예제 #1
0
func NumSyllables(text string) (int, error) {
	text = whitespaceRe.ReplaceAllLiteralString(text, " ")
	text = strings.TrimSpace(text)
	words := strings.Split(text, " ")

	var syllables int

	corpus, err := cmu.CMUCorpus()
	if err != nil {
		return 0, err
	}
	for _, word := range words {
		// TODO check for words in which the lookup failed
		s := corpus.Syllables(word)
		syllables += s
	}
	return syllables, nil
}
예제 #2
0
func polysyllableCount(text string) (int, error) {
	text = whitespaceRe.ReplaceAllLiteralString(text, " ")
	text = strings.TrimSpace(text)
	words := strings.Split(text, " ")

	var polysyllablicWords int

	corpus, err := cmu.CMUCorpus()
	if err != nil {
		return 0, err
	}
	for _, word := range words {
		// TODO check for words in which the lookup failed
		if corpus.Syllables(word) > 2 {
			polysyllablicWords++
		}
	}
	return polysyllablicWords, nil
}
예제 #3
0
func NumComplexWords(text string) (int, error) {
	text = whitespaceRe.ReplaceAllLiteralString(text, " ")
	text = strings.TrimSpace(text)
	words := strings.Split(text, " ")

	var complexWords int

	corpus, err := cmu.CMUCorpus()
	if err != nil {
		return 0, err
	}
	for _, word := range words {
		// TODO check for words in which the lookup failed
		if isComplex(word, corpus) {
			complexWords++
		}
	}
	return complexWords, nil
}