Пример #1
0
func ErrMain() error {
	if len(os.Args) != 3 {
		return errors.New("Usage: diphones <dictionary.txt> <common.txt>")
	}

	// Read input files
	fmt.Println("Reading input files...")
	dict, err := gospeech.LoadDictionary(os.Args[1])
	if err != nil {
		return err
	}
	common, err := ReadLines(os.Args[2])
	if err != nil {
		return err
	}

	// Sort the dictionary
	fmt.Println("Sorting dictionary...")
	dictKeys := SortDictionary(dict, common)

	// Generate diphones
	fmt.Println("Generating diphones...")
	diphones := map[string][]string{}
	for _, word := range dictKeys {
		phones := dict.Get(word)
		if phones == nil {
			continue
		}
		// Find all the diphones and check them
		for i := 0; i < len(phones)-1; i++ {
			// I admit, even I cannot read this code.
			diphone := phones[i].Name() + "-" + phones[i+1].Name()
			if list, ok := diphones[diphone]; ok && len(list) > 10 {
				continue
			} else if !ok {
				diphones[diphone] = []string{}
			}
			example := strings.ToLower(word) + " (" + dict.GetRaw(word) + ")"
			diphones[diphone] = append(diphones[diphone], example)
		}
	}

	PrintDiphones(diphones)
	return nil
}
Пример #2
0
func ErrMain() error {
	if len(os.Args) != 3 {
		return errors.New("Usage: edgephones <dictionary.txt> <common.txt>")
	}

	// Read input files
	fmt.Println("Reading input files...")
	dict, err := gospeech.LoadDictionary(os.Args[1])
	if err != nil {
		return err
	}
	common, err := ReadLines(os.Args[2])
	if err != nil {
		return err
	}

	// Sort the dictionary
	fmt.Println("Sorting dictionary...")
	dictKeys := SortDictionary(dict, common)

	// Generate keys and values
	fmt.Println("Generating edge phones...")
	result := map[string][]string{}
	for _, word := range dictKeys {
		phones := dict.Get(word)
		if phones == nil {
			continue
		}

		prefixPhone := "-" + phones[0].Name()
		suffixPhone := phones[len(phones)-1].Name() + "-"

		for _, key := range []string{prefixPhone, suffixPhone} {
			if list, ok := result[key]; !ok {
				result[key] = []string{word}
			} else if len(list) < 10 {
				result[key] = append(result[key], word)
			}
		}
	}

	PrintKeyValues(result)
	return nil
}