<commit_before>package types

import (
	"flag"
	"fmt"
	"github.com/pkg/errors"
	"io/ioutil"
	"os"
	"path/filepath"
)

var (
	testDataPathFlag = flag.String("path", "./testdata", "Directory of test data")
	testDataPath     string
)

// testData stores io.Readers for each of the files found in the directory
var testData = make(map[string][]*os.File, len(typesList))

// this is the list of potential types
// must be lower case
var typesList = []string{
	"journey",
	"section",
	"region",
	"place",
}

func init() {
	flag.Parse()
	// If the given path is absolute, then use it as-is
	if filepath.IsAbs(*testDataPathFlag) {
		testDataPath = *testDataPathFlag
	} else {
		wd, err := os.Getwd()
		if err != nil {
			panic(err)
		}
		testDataPath = filepath.Join(wd, *testDataPathFlag)
	}

	err := load()
	if err != nil {
		panic(err)
	}

	fmt.Printf("Loaded: %#v\n", testData)
}

func load() error {
	subdirs, err := ioutil.ReadDir(testDataPath)
	if err != nil {
		return errors.Wrapf(err, "Error while reading %s's files", testDataPath)
	}

	// Iterate through the subdirs
	for _, dinfo := range subdirs {
		if dinfo.IsDir() {
			dpath := filepath.Join(testDataPath, dinfo.Name())
			files, err := ioutil.ReadDir(dpath)
			if err != nil {
				return errors.Wrapf(err, "error while reading %s's files", dpath)
			}

			// Now we'll iterate through the files, checking if their name include a type, and if so adding them to testData
			for _, finfo := range files {
				// Get the name
				fileName := finfo.Name()<commit_msg>types: remove superfluous load print<commit_after>package types

import (
	"flag"
	"github.com/pkg/errors"
	"io/ioutil"
	"os"
	"path/filepath"
)

var (
	testDataPathFlag = flag.String("path", "./testdata", "Directory of test data")
	testDataPath     string
)

// testData stores io.Readers for each of the files found in the directory
var testData = make(map[string][]*os.File, len(typesList))

// this is the list of potential types
// must be lower case
var typesList = []string{
	"journey",
	"section",
	"region",
	"place",
}

func init() {
	flag.Parse()
	// If the given path is absolute, then use it as-is
	if filepath.IsAbs(*testDataPathFlag) {
		testDataPath = *testDataPathFlag
	} else {
		wd, err := os.Getwd()
		if err != nil {
			panic(err)
		}
		testDataPath = filepath.Join(wd, *testDataPathFlag)
	}

	err := load()
	if err != nil {
		panic(err)
	}
}

func load() error {
	subdirs, err := ioutil.ReadDir(testDataPath)
	if err != nil {
		return errors.Wrapf(err, "Error while reading %s's files", testDataPath)
	}

	// Iterate through the subdirs
	for _, dinfo := range subdirs {
		if dinfo.IsDir() {
			dpath := filepath.Join(testDataPath, dinfo.Name())
			files, err := ioutil.ReadDir(dpath)
			if err != nil {
				return errors.Wrapf(err, "error while reading %s's files", dpath)
			}

			// Now we'll iterate through the files, checking if their name include a type, and if so adding them to testData
			for _, finfo := range files {
				// Get the name
				fileName := finfo.Name()
{'fraction_non_alphanumeric': 0.1347682119205298, 'fraction_numerical': 0.0, 'mean_word_length': 3.4821958456973294, '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': '1314653', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1072, 'n_words': 325}