Codebase list golang-github-jdkato-prose / 9f70ad2
Remove links from Assessment code block Since they're already provided with the individual method descriptions (where they correctly render as hyperlinks), I think we can remove these. Joseph Kato 7 years ago
2 changed file(s) with 20 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
55 "github.com/jdkato/prose/internal/util"
66 )
77
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).
1010 func (d *Document) FleschKincaid() float64 {
1111 x := 0.39 * d.NumWords / d.NumSentences
1212 y := 11.8 * d.NumSyllables / d.NumWords
1313 return x + y - 15.59
1414 }
1515
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).
1818 func (d *Document) FleschReadingEase() float64 {
1919 x := 1.015 * d.NumWords / d.NumSentences
2020 y := 84.6 * d.NumSyllables / d.NumWords
2121 return 206.835 - x - y
2222 }
2323
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.
2626 func (d *Document) GunningFog() float64 {
2727 x := d.NumWords / d.NumSentences
2828 y := d.NumComplexWords / d.NumWords
2929 return 0.4 * (x + 100.0*y)
3030 }
3131
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).
3433 func (d *Document) SMOG() float64 {
3534 return 1.0430*math.Sqrt(d.NumPolysylWords*30.0/d.NumSentences) + 3.1291
3635 }
3736
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).
4139 func (d *Document) AutomatedReadability() float64 {
4240 x := 4.71 * (d.NumCharacters / d.NumWords)
4341 y := 0.5 * (d.NumWords / d.NumSentences)
4442 return x + y - 21.43
4543 }
4644
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).
4947 func (d *Document) ColemanLiau() float64 {
5048 x := 0.0588 * (d.NumCharacters / d.NumWords) * 100
5149 y := 0.296 * (d.NumSentences / d.NumWords) * 100
5250 return x - y - 15.8
5351 }
5452
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).
5755 func (d *Document) DaleChall() float64 {
5856 easy := 0.0
5957 for word := range d.WordFrequency {
5353
5454 // An Assessment provides comprehensive access to a Document's metrics.
5555 type Assessment struct {
56
5756 // assessments returning an estimated grade level
58
59 AutomatedReadability float64 // https://en.wikipedia.org/wiki/Automated_readability_index
60 ColemanLiau float64 // https://en.wikipedia.org/wiki/Coleman%E2%80%93Liau_index
61 FleschKincaid float64 // https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests
62 GunningFog float64 // https://en.wikipedia.org/wiki/Gunning_fog_index
63 SMOG float64 // https://en.wikipedia.org/wiki/SMOG
57 AutomatedReadability float64
58 ColemanLiau float64
59 FleschKincaid float64
60 GunningFog float64
61 SMOG float64
6462
6563 // mean & standard deviation of the above estimated grade levels
66
6764 MeanGradeLevel float64
6865 StdDevGradeLevel float64
6966
7067 // assessments Not returning an estimated grade level
71
72 DaleChall float64 // https://en.wikipedia.org/wiki/Dale%E2%80%93Chall_readability_formula
73 ReadingEase float64 // https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests
68 DaleChall float64
69 ReadingEase float64
7470 }
7571
7672 // NewDocument is a Document constructor that takes a string as an argument. It