<commit_before>package anagrams

import (
	"fmt"
	"io/ioutil"
	"math/rand"
	"sort"
	"strings"
	"time"
	"unicode/utf8"
)

//RuneSlice type attaches functions to allow sorting of runes
type RuneSlice []rune

func (rs RuneSlice) Len() int {
	return utf8.RuneCountInString(string(rs))
}

func (rs RuneSlice) Less(i, j int) bool {
	return rs[i] < rs[j]
}

func (rs RuneSlice) Swap(i, j int) {
	rs[i], rs[j] = rs[j], rs[i]
}

//LenCheck returns true if strings are of equal length, else false
func LenCheck(x string, y string) bool {
	if len(x) == len(y) {
		return true
	}
	return false
}

//SortWord takes a string and returns its characters sorted as a string
func SortWord(word string) string {
	w := []rune(word)
	rs := RuneSlice(w)
	sort.Sort(rs)
	return string(rs)
}

//Anagram1 sorts the characters of two given strings and returns true if they match
func Anagram1(x string, y string) bool {
	if LenCheck(x, y) {
		//Continue anagram check
		//TODO: map characters
		amapX := SortWord(x)
		amapY := SortWord(y)
		if amapX == amapY {
			return true
		}
	}
	return false
}

//ReadSystemWords parses the system word list(/usr/share/dict/words) and returns
//an array of strings.
func ReadSystemWords() ([]string, error) {
	path := "/usr/share/dict/words"
	contents, err := ioutil.ReadFile(path)
	if err != nil {
		panic(err)
		return nil, err
	}
	return strings.Split(string(contents), "\n"), nil
}

//AnagramMap holds construct of sorted characters of anagrams to all the
//possible words in the 'Mapping' field.  Mapping field holds a 'set' map to
//allow fast lookup of unique words possible.
type AnagramMap struct {
	Mapping map[string]map[string]bool
}

//AnagramOfWord takes a word and returns a separate anagram of it
func (a *AnagramMap) AnagramOfWord(word string) string {
	word = strings.ToLower(word)<commit_msg>Added custom wordlist functionality<commit_after>package anagrams

import (
	"fmt"
	"io/ioutil"
	"math/rand"
	"sort"
	"strings"
	"time"
	"unicode/utf8"
)

//RuneSlice type attaches functions to allow sorting of runes
type RuneSlice []rune

func (rs RuneSlice) Len() int {
	return utf8.RuneCountInString(string(rs))
}

func (rs RuneSlice) Less(i, j int) bool {
	return rs[i] < rs[j]
}

func (rs RuneSlice) Swap(i, j int) {
	rs[i], rs[j] = rs[j], rs[i]
}

//LenCheck returns true if strings are of equal length, else false
func LenCheck(x string, y string) bool {
	if len(x) == len(y) {
		return true
	}
	return false
}

//SortWord takes a string and returns its characters sorted as a string
func SortWord(word string) string {
	w := []rune(word)
	rs := RuneSlice(w)
	sort.Sort(rs)
	return string(rs)
}

//Anagram1 sorts the characters of two given strings and returns true if they match
func Anagram1(x string, y string) bool {
	if LenCheck(x, y) {
		//Continue anagram check
		//TODO: map characters
		amapX := SortWord(x)
		amapY := SortWord(y)
		if amapX == amapY {
			return true
		}
	}
	return false
}

//ReadSystemWords parses the system word list(/usr/share/dict/words) and returns
//an array of strings.
func ReadSystemWords() ([]string, error) {
	path := "/usr/share/dict/words"
	contents, err := ioutil.ReadFile(path)
	if err != nil {
		panic(err)
		return nil, err
	}
	return strings.Split(string(contents), "\n"), nil
}

//ReadCustomWords parses list of words from a file given in the 'path' parameter.
//Panics if the custom path fails to load a file
func ReadCustomWords(path string) ([]string, error) {
	contents, err := ioutil.ReadFile(path)
	if err != nil {
		panic(err)
		return nil, err
	}
	return strings.Split(string(contents), "\n"), nil
}

//AnagramMap holds construct of sorted characters of anagrams to all the
//possible words in the 'Mapping' field.  Mapping field holds a 'set' map to
//allow fast lookup of unique words possible.
type AnagramMap struct {
	Mapping map[string]map[string]bool
}

//AnagramOfWord takes a word and returns a separate anagram of it
func (a *AnagramMap) AnagramOfWord(word string) string {
	word = strings.ToLower(word)
{'fraction_non_alphanumeric': 0.11680840420210105, 'fraction_numerical': 0.002001000500250125, 'mean_word_length': 4.005006257822278, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5641852', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1392, 'n_words': 490}