<commit_before>package process

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"

	"kego.io/json"
	"kego.io/system"
)

func Scan(dir string, packageName string, packagePath string, imports map[string]string, types map[string]*system.Type) error {

	walker := func(path string, file os.FileInfo, err error) error {
		if strings.HasSuffix(path, ".json") {

			file, err := ioutil.ReadFile(path)
			if err != nil {
				return fmt.Errorf("Error reading file %v in %v:\n%v\n", path, packageName, err)
			}

			var i interface{}
			if err := json.UnmarshalTyped(file, &i, packagePath, imports); err != nil {
				return fmt.Errorf("Error when processing %v:\n%v\n", path, err)
			}

			t, ok := i.(*system.Type)
			if ok {
				fullname := fmt.Sprintf("%s:%s", packagePath, t.Id.Value)
				types[fullname] = t
				system.RegisterType(fullname, t)
				if t.Rule != nil {
					rulename := fmt.Sprintf("%s:%s", packagePath, t.Rule.Id.Value)
					types[rulename] = t.Rule
					system.RegisterType(rulename, t.Rule)
				}
			}

			return nil

		}
		return nil
	}

	if err := filepath.Walk(dir, walker); err != nil {
		return fmt.Errorf("Error while scanning for types:\n%v\n", err)
	}
	return nil
}<commit_msg>Added kego package, renamed UnmarshalTyped to Unmarshal<commit_after>package process

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"

	"kego.io/json"
	"kego.io/system"
)

func Scan(dir string, packageName string, packagePath string, imports map[string]string, types map[string]*system.Type) error {

	walker := func(path string, file os.FileInfo, err error) error {
		if strings.HasSuffix(path, ".json") {

			file, err := ioutil.ReadFile(path)
			if err != nil {
				return fmt.Errorf("Error reading file %v in %v:\n%v\n", path, packageName, err)
			}

			var i interface{}
			if err := json.Unmarshal(file, &i, packagePath, imports); err != nil {
				return fmt.Errorf("Error when processing %v:\n%v\n", path, err)
			}

			t, ok := i.(*system.Type)
			if ok {
				fullname := fmt.Sprintf("%s:%s", packagePath, t.Id.Value)
				types[fullname] = t
				system.RegisterType(fullname, t)
				if t.Rule != nil {
					rulename := fmt.Sprintf("%s:%s", packagePath, t.Rule.Id.Value)
					types[rulename] = t.Rule
					system.RegisterType(rulename, t.Rule)
				}
			}

			return nil

		}
		return nil
	}

	if err := filepath.Walk(dir, walker); err != nil {
		return fmt.Errorf("Error while scanning for types:\n%v\n", err)
	}
	return nil
}
{'fraction_non_alphanumeric': 0.1549410329402196, 'fraction_numerical': 0.0, 'mean_word_length': 3.353982300884956, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7437907', 'n_tokens_mistral': 1027, 'n_tokens_neox': 887, 'n_words': 226}