5 | 5 |
"github.com/jdkato/prose/internal/util"
|
6 | 6 |
)
|
7 | 7 |
|
8 | |
// FleschKincaid computes the Flesch–Kincaid grade level of the Document d.
|
9 | |
// https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests
|
|
8 |
// FleschKincaid computes the Flesch–Kincaid grade level
|
|
9 |
// (https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests).
|
10 | 10 |
func (d *Document) FleschKincaid() float64 {
|
11 | 11 |
x := 0.39 * d.NumWords / d.NumSentences
|
12 | 12 |
y := 11.8 * d.NumSyllables / d.NumWords
|
13 | 13 |
return x + y - 15.59
|
14 | 14 |
}
|
15 | 15 |
|
16 | |
// FleschReadingEase computes the Flesch reading-ease score of the Document d.
|
17 | |
// https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests
|
|
16 |
// FleschReadingEase computes the Flesch reading-ease score
|
|
17 |
// (https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests).
|
18 | 18 |
func (d *Document) FleschReadingEase() float64 {
|
19 | 19 |
x := 1.015 * d.NumWords / d.NumSentences
|
20 | 20 |
y := 84.6 * d.NumSyllables / d.NumWords
|
21 | 21 |
return 206.835 - x - y
|
22 | 22 |
}
|
23 | 23 |
|
24 | |
// GunningFog computes the Gunning Fog index score of the Document d.
|
25 | |
// https://en.wikipedia.org/wiki/Gunning_fog_index
|
|
24 |
// GunningFog computes the Gunning Fog index score
|
|
25 |
// (https://en.wikipedia.org/wiki/Gunning_fog_index.
|
26 | 26 |
func (d *Document) GunningFog() float64 {
|
27 | 27 |
x := d.NumWords / d.NumSentences
|
28 | 28 |
y := d.NumComplexWords / d.NumWords
|
29 | 29 |
return 0.4 * (x + 100.0*y)
|
30 | 30 |
}
|
31 | 31 |
|
32 | |
// SMOG computes the SMOG grade of the Document d.
|
33 | |
// https://en.wikipedia.org/wiki/SMOG
|
|
32 |
// SMOG computes the SMOG grade (https://en.wikipedia.org/wiki/SMOG).
|
34 | 33 |
func (d *Document) SMOG() float64 {
|
35 | 34 |
return 1.0430*math.Sqrt(d.NumPolysylWords*30.0/d.NumSentences) + 3.1291
|
36 | 35 |
}
|
37 | 36 |
|
38 | |
// AutomatedReadability computes the automated readability index score of the
|
39 | |
// Document d.
|
40 | |
// https://en.wikipedia.org/wiki/Automated_readability_index
|
|
37 |
// AutomatedReadability computes the automated readability index score
|
|
38 |
// (https://en.wikipedia.org/wiki/Automated_readability_index).
|
41 | 39 |
func (d *Document) AutomatedReadability() float64 {
|
42 | 40 |
x := 4.71 * (d.NumCharacters / d.NumWords)
|
43 | 41 |
y := 0.5 * (d.NumWords / d.NumSentences)
|
44 | 42 |
return x + y - 21.43
|
45 | 43 |
}
|
46 | 44 |
|
47 | |
// ColemanLiau computes the Coleman–Liau index score of the Document d.
|
48 | |
// https://en.wikipedia.org/wiki/Coleman%E2%80%93Liau_index
|
|
45 |
// ColemanLiau computes the Coleman–Liau index score
|
|
46 |
// (https://en.wikipedia.org/wiki/Coleman%E2%80%93Liau_index).
|
49 | 47 |
func (d *Document) ColemanLiau() float64 {
|
50 | 48 |
x := 0.0588 * (d.NumCharacters / d.NumWords) * 100
|
51 | 49 |
y := 0.296 * (d.NumSentences / d.NumWords) * 100
|
52 | 50 |
return x - y - 15.8
|
53 | 51 |
}
|
54 | 52 |
|
55 | |
// DaleChall computes the Dale–Chall score of the Document d.
|
56 | |
// https://en.wikipedia.org/wiki/Dale%E2%80%93Chall_readability_formula
|
|
53 |
// DaleChall computes the Dale–Chall score
|
|
54 |
// (https://en.wikipedia.org/wiki/Dale%E2%80%93Chall_readability_formula).
|
57 | 55 |
func (d *Document) DaleChall() float64 {
|
58 | 56 |
easy := 0.0
|
59 | 57 |
for word := range d.WordFrequency {
|