-
Notifications
You must be signed in to change notification settings - Fork 4
/
textstats.go
105 lines (88 loc) · 3.44 KB
/
textstats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package textstats
import "strings"
// AverageLettersPerWord returns the average number of letters per word in the
// text
func AverageLettersPerWord(text string) float64 {
res, _ := Analyse(strings.NewReader(text))
return res.AverageLettersPerWord()
}
// AverageSyllablesPerWord returns the average number of syllables per word in
// the text
func AverageSyllablesPerWord(text string) float64 {
res, _ := Analyse(strings.NewReader(text))
return res.AverageSyllablesPerWord()
}
// AverageWordsPerSentence returns the avergae number of words per sentence in
// the text
func AverageWordsPerSentence(text string) float64 {
res, _ := Analyse(strings.NewReader(text))
return res.AverageWordsPerSentence()
}
// WordsWithAtLeastNSyllables returns the number of words with at least N
// syllables, including or excluding proper nouns, in the text
func WordsWithAtLeastNSyllables(text string, n int, incProperNouns bool) int {
res, _ := Analyse(strings.NewReader(text))
return res.WordsWithAtLeastNSyllables(n, incProperNouns)
}
// PercentageWordsWithAtLeastNSyllables returns the percentage of words with at
// least N syllables, including or excluding proper nouns, in the text
func PercentageWordsWithAtLeastNSyllables(text string, n int, incProperNouns bool) float64 {
res, _ := Analyse(strings.NewReader(text))
return res.PercentageWordsWithAtLeastNSyllables(n, incProperNouns)
}
// WordCount returns the number of words in a given string
func WordCount(text string) int {
res, _ := Analyse(strings.NewReader(text))
return res.Words
}
// SentenceCount returns the number of sentences in a given string
func SentenceCount(text string) int {
res, _ := Analyse(strings.NewReader(text))
return res.Sentences
}
// LetterCount returns the number of letters in a given string
func LetterCount(text string) int {
res, _ := Analyse(strings.NewReader(text))
return res.Letters
}
// SyllableCount returns the number of syllables in a given string
func SyllableCount(text string) int {
res, _ := Analyse(strings.NewReader(text))
return res.Syllables
}
// FleschKincaidReadingEase returns the Flesch-Kincaid reading ease score for
// given text
func FleschKincaidReadingEase(text string) float64 {
res, _ := Analyse(strings.NewReader(text))
return res.FleschKincaidReadingEase()
}
// FleschKincaidGradeLevel returns the Flesch-Kincaid grade level for the given text
func FleschKincaidGradeLevel(text string) float64 {
res, _ := Analyse(strings.NewReader(text))
return res.FleschKincaidGradeLevel()
}
// GunningFogScore returns the Gunning-Fog score for the given text
func GunningFogScore(text string) float64 {
res, _ := Analyse(strings.NewReader(text))
return res.GunningFogScore()
}
// ColemanLiauIndex returns the Coleman-Liau index for the given text
func ColemanLiauIndex(text string) float64 {
res, _ := Analyse(strings.NewReader(text))
return res.ColemanLiauIndex()
}
// SMOGIndex returns the SMOG index for the given text
func SMOGIndex(text string) float64 {
res, _ := Analyse(strings.NewReader(text))
return res.SMOGIndex()
}
// AutomatedReadabilityIndex returns the Automated Readability index for the given text
func AutomatedReadabilityIndex(text string) float64 {
res, _ := Analyse(strings.NewReader(text))
return res.AutomatedReadabilityIndex()
}
// DaleChallReadabilityScore returns the Dale-Chall readability score for the given text
func DaleChallReadabilityScore(text string) float64 {
res, _ := Analyse(strings.NewReader(text))
return res.DaleChallReadabilityScore()
}