Exemplo n.º 1
0
func populateAlphsDefs(filename string, combinations func(string) uint64,
	dist lexicon.LetterDistribution) (
	map[string]string, map[string]Alphagram) {
	definitions := make(map[string]string)
	alphagrams := make(map[string]Alphagram)
	file, _ := os.Open(filename)
	// XXX: Check error
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		fields := strings.Fields(scanner.Text())
		if len(fields) > 0 {
			word := lexicon.Word{Word: strings.ToUpper(fields[0]), Dist: dist}
			definition := ""
			if len(fields) > 1 {
				definition = strings.Join(fields[1:], " ")
			}
			definitions[word.Word] = definition
			alphagram := word.MakeAlphagram()
			alph, ok := alphagrams[alphagram]
			if !ok {
				alphagrams[alphagram] = Alphagram{
					[]string{word.Word},
					combinations(alphagram),
					alphagram}
			} else {
				alph.words = append(alph.words, word.Word)
				alphagrams[alphagram] = alph
			}
		}
	}
	file.Close()
	return definitions, alphagrams
}
Exemplo n.º 2
0
func sortedHooks(hooks []rune, dist lexicon.LetterDistribution) string {
	w := lexicon.Word{Word: string(hooks), Dist: dist}
	return w.MakeAlphagram()
}