<commit_before>/*
Package flect is a new inflection engine to replace [https://github.com/markbates/inflect](https://github.com/markbates/inflect) designed to be more modular, more readable, and easier to fix issues on than the original.
*/
package flect

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"unicode"
)

func init() {
	pwd, _ := os.Getwd()
	cfg := filepath.Join(pwd, "inflections.json")
	if p := os.Getenv("INFLECT_PATH"); p != "" {
		cfg = p
	}
	if _, err := os.Stat(cfg); err == nil {
		b, err := ioutil.ReadFile(cfg)
		if err != nil {
			fmt.Printf("could not read inflection file %s (%s)\n", cfg, err)
			return
		}
		if err = LoadReader(bytes.NewReader(b)); err != nil {
			fmt.Println(err)
		}
	}
}

//LoadReader loads rules from io.Reader param
func LoadReader(r io.Reader) error {
	m := map[string]interface{}{}

	err := json.NewDecoder(r).Decode(&m)
	if err != nil {
		return fmt.Errorf("could not decode inflection JSON from reader: %s", err)
	}
	pluralMoot.Lock()
	defer pluralMoot.Unlock()
	singularMoot.Lock()
	defer singularMoot.Unlock()

	for s, p := range m {
		if ps, ok := p.(string); ok {
			singleToPlural[s] = ps
			pluralToSingle[ps] = s
		}

		if pa, ok := p.([]interface{}); ok && s == "_acronyms" {
			for _, acronym := range pa {
				key := (acronym).(string)
				baseAcronyms[key] = true
			}
		}

	}

	return nil
}

var spaces = []rune{'_', ' ', ':', '-', '/'}

func isSpace(c rune) bool {
	for _, r := range spaces {
		if r == c {
			return true
		}<commit_msg>moving acronyms key to a constant<commit_after>/*
Package flect is a new inflection engine to replace [https://github.com/markbates/inflect](https://github.com/markbates/inflect) designed to be more modular, more readable, and easier to fix issues on than the original.
*/
package flect

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"unicode"
)

const (
	//acronymsKey is the key we use to get acronyms from the inflections file
	//p.e:
	// #inflections.json
	// {
	// 	"house":"houses",
	// 	"_acronyms": ["TSA", "LSA"]
	// }
	acronymsKey = "_acronyms"
)

func init() {
	pwd, _ := os.Getwd()
	cfg := filepath.Join(pwd, "inflections.json")
	if p := os.Getenv("INFLECT_PATH"); p != "" {
		cfg = p
	}
	if _, err := os.Stat(cfg); err == nil {
		b, err := ioutil.ReadFile(cfg)
		if err != nil {
			fmt.Printf("could not read inflection file %s (%s)\n", cfg, err)
			return
		}
		if err = LoadReader(bytes.NewReader(b)); err != nil {
			fmt.Println(err)
		}
	}
}

//LoadReader loads rules from io.Reader param
func LoadReader(r io.Reader) error {
	m := map[string]interface{}{}

	err := json.NewDecoder(r).Decode(&m)
	if err != nil {
		return fmt.Errorf("could not decode inflection JSON from reader: %s", err)
	}
	pluralMoot.Lock()
	defer pluralMoot.Unlock()
	singularMoot.Lock()
	defer singularMoot.Unlock()

	for s, p := range m {
		if ps, ok := p.(string); ok {
			singleToPlural[s] = ps
			pluralToSingle[ps] = s
		}

		if pa, ok := p.([]interface{}); ok && s == acronymsKey {
			for _, acronym := range pa {
				key := (acronym).(string)
				baseAcronyms[key] = true
			}
		}

	}

	return nil
}

var spaces = []rune{'_', ' ', ':', '-', '/'}

func isSpace(c rune) bool {
	for _, r := range spaces {
		if r == c {
			return true
		}
{'fraction_non_alphanumeric': 0.1713171317131713, 'fraction_numerical': 0.0, 'mean_word_length': 3.236340533672173, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '6447895', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1286, 'n_words': 345}