<commit_before>// Copyright 2015 <NAME>.  All rights reserved.
// Use of this source code is governed by the MIT
// license, which can be found in the LICENSE file.

// File scripts.go contains code related to lua scripts,
// including parsing the scripts in the scripts folder and
// wrapper functions which offer type safety for using them.

package zoom

import (
	"github.com/garyburd/redigo/redis"
	"io/ioutil"
	"os"
	"path/filepath"
)

var (
	deleteModelsBySetIdsScript      *redis.Script
	deleteStringIndexScript         *redis.Script
	extractIdsFromFieldIndexScript  *redis.Script
	extractIdsFromStringIndexScript *redis.Script
)

var (
	scriptsPath = filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "albrow", "zoom", "scripts")
)

// initScripts will parse all the lua script files in scriptsPath and assign them
// to the variables above. It must be run before any scripts are executed.
func initScripts() error {
	scriptsToParse := []struct {
		script   **redis.Script
		filename string
		keyCount int
	}{
		{
			script:   &deleteModelsBySetIdsScript,
			filename: "delete_models_by_set_ids.lua",
			keyCount: 1,
		},
		{<commit_msg>Attempt to fix script path problems.<commit_after>// Copyright 2015 <NAME>.  All rights reserved.
// Use of this source code is governed by the MIT
// license, which can be found in the LICENSE file.

// File scripts.go contains code related to lua scripts,
// including parsing the scripts in the scripts folder and
// wrapper functions which offer type safety for using them.

package zoom

import (
	"github.com/garyburd/redigo/redis"
	"go/build"
	"io/ioutil"
	"path/filepath"
)

var (
	deleteModelsBySetIdsScript      *redis.Script
	deleteStringIndexScript         *redis.Script
	extractIdsFromFieldIndexScript  *redis.Script
	extractIdsFromStringIndexScript *redis.Script
)

var (
	scriptsPath string
)

// initScripts will parse all the lua script files in scriptsPath and assign them
// to the variables above. It must be run before any scripts are executed.
func initScripts() error {
	pkg, err := build.Import("github.com/albrow/zoom", "", build.FindOnly)
	if err != nil {
		return err
	}
	scriptsPath = filepath.Join(pkg.Dir, "scripts")
	scriptsToParse := []struct {
		script   **redis.Script
		filename string
		keyCount int
	}{
		{
			script:   &deleteModelsBySetIdsScript,
			filename: "delete_models_by_set_ids.lua",
			keyCount: 1,
		},
		{
{'fraction_non_alphanumeric': 0.09347735770668883, 'fraction_numerical': 0.004154549231408392, 'mean_word_length': 3.8353413654618476, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3888771', 'n_tokens_mistral': 782, 'n_tokens_neox': 733, 'n_words': 250}