Documentation
¶
Overview ¶
Package readability provides text readability analysis using standard formulas.
It is a Go rewrite of the Python textstat library, targeting English text.
Index ¶
- func FormulaNames() []string
- type Analysis
- func (a *Analysis) AutomatedReadabilityIndex() float64
- func (a *Analysis) ColemanLiauIndex() float64
- func (a *Analysis) DaleChallReadabilityScore() float64
- func (a *Analysis) DaleChallReadabilityScoreV2() float64
- func (a *Analysis) FleschKincaidGrade() float64
- func (a *Analysis) FleschReadingEase() float64
- func (a *Analysis) GunningFog() float64
- func (a *Analysis) LinsearWriteFormula() float64
- func (a *Analysis) LinsearWriteFormulaOpts(strictLower, strictUpper bool) float64
- func (a *Analysis) Lix() float64
- func (a *Analysis) McalpineEFLAW() float64
- func (a *Analysis) ReadingTime() float64
- func (a *Analysis) ReadingTimeWithRate(msPerChar float64) float64
- func (a *Analysis) Rix() float64
- func (a *Analysis) Score(formula Formula) (float64, error)
- func (a *Analysis) ScoreAll() map[Formula]float64
- func (a *Analysis) SmogIndex() float64
- func (a *Analysis) SpacheReadability() float64
- func (a *Analysis) SpacheReadabilityInt() int
- func (a *Analysis) Stats() Stats
- func (a *Analysis) TextStandard() float64
- func (a *Analysis) TextStandardString() string
- type Analyzerdeprecated
- func (az *Analyzer) Analyze(text string) Stats
- func (az *Analyzer) LinsearWrite(text string, strictLower, strictUpper bool) float64
- func (az *Analyzer) ReadingTime(text string, msPerChar float64) float64
- func (az *Analyzer) Score(text string, formula Formula) (float64, error)
- func (az *Analyzer) ScoreAll(text string) map[Formula]float64
- func (az *Analyzer) SpacheReadabilityInt(text string) int
- func (az *Analyzer) TextStandardString(text string) string
- type Formula
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormulaNames ¶
func FormulaNames() []string
FormulaNames returns all formula names as strings, sorted.
Types ¶
type Analysis ¶
type Analysis struct {
// contains filtered or unexported fields
}
Analysis holds all pre-computed values any formula needs, computed once per text. An Analysis is immutable after construction via NewAnalysis.
func NewAnalysis ¶
NewAnalysis pre-computes all text statistics needed by readability formulas.
func (*Analysis) AutomatedReadabilityIndex ¶
AutomatedReadabilityIndex calculates the Automated Readability Index.
func (*Analysis) ColemanLiauIndex ¶
ColemanLiauIndex calculates the Coleman-Liau Index.
func (*Analysis) DaleChallReadabilityScore ¶
DaleChallReadabilityScore calculates the Dale-Chall Readability Score.
func (*Analysis) DaleChallReadabilityScoreV2 ¶
DaleChallReadabilityScoreV2 calculates the New Dale-Chall Readability Score. Unlike v1, uses syllable_threshold=2 and checks raw_score > 0.05 for adjustment.
func (*Analysis) FleschKincaidGrade ¶
FleschKincaidGrade calculates the Flesch-Kincaid Grade Level.
func (*Analysis) FleschReadingEase ¶
FleschReadingEase calculates the Flesch Reading Ease score.
func (*Analysis) GunningFog ¶
GunningFog calculates the Gunning Fog Index.
func (*Analysis) LinsearWriteFormula ¶
LinsearWriteFormula calculates the Linsear Write Formula with default options.
func (*Analysis) LinsearWriteFormulaOpts ¶
LinsearWriteFormulaOpts calculates the Linsear Write Formula with configurable bounds. strictLower: return 0 if text has fewer than 100 words. strictUpper: use only the first 100 words.
func (*Analysis) McalpineEFLAW ¶
McalpineEFLAW calculates the McAlpine EFLAW readability score.
func (*Analysis) ReadingTime ¶
ReadingTime returns estimated reading time in seconds using the default 14.69 ms per character.
func (*Analysis) ReadingTimeWithRate ¶
ReadingTimeWithRate returns estimated reading time in seconds using the given ms per character.
func (*Analysis) Rix ¶
Rix calculates the RIX readability index. Uses the same long word count as LIX (> 6 letters, apostrophes removed).
func (*Analysis) SpacheReadability ¶
SpacheReadability calculates the Spache Readability Formula.
func (*Analysis) SpacheReadabilityInt ¶
SpacheReadabilityInt returns the Spache score truncated to an integer.
func (*Analysis) TextStandard ¶
TextStandard estimates grade level as the mode of grade estimates from multiple formulas.
func (*Analysis) TextStandardString ¶
TextStandardString returns the text standard grade level as a string like "6th and 7th grade".
type Analyzer
deprecated
type Analyzer struct{}
Analyzer is a convenience type whose methods accept text and internally construct an Analysis for each call.
Deprecated: prefer NewAnalysis(text) for direct access to methods and to reuse a single Analysis across multiple formula calls.
func (*Analyzer) LinsearWrite ¶
LinsearWrite calculates the Linsear Write Formula with configurable bounds. strictLower: return 0 if text has fewer than 100 words. strictUpper: use only the first 100 words (default behavior).
func (*Analyzer) ReadingTime ¶
ReadingTime returns estimated reading time in seconds using the given ms per character.
func (*Analyzer) ScoreAll ¶
ScoreAll calculates all formulas for text and returns a map of formula → score.
func (*Analyzer) SpacheReadabilityInt ¶
SpacheReadabilityInt returns the Spache score truncated to an integer.
func (*Analyzer) TextStandardString ¶
TextStandardString returns grade level as a string like "6th and 7th grade".
type Formula ¶
type Formula string
Formula identifies a readability formula by name.
const ( FleschReadingEase Formula = "flesch_reading_ease" FleschKincaidGrade Formula = "flesch_kincaid_grade" GunningFog Formula = "gunning_fog" SmogIndex Formula = "smog_index" ColemanLiauIndex Formula = "coleman_liau_index" AutomatedReadabilityIndex Formula = "automated_readability_index" DaleChallReadabilityScore Formula = "dale_chall_readability_score" DaleChallReadabilityScoreV2 Formula = "dale_chall_readability_score_v2" LinsearWriteFormula Formula = "linsear_write_formula" SpacheReadability Formula = "spache_readability" Lix Formula = "lix" McalpineEFLAW Formula = "mcalpine_eflaw" Rix Formula = "rix" TextStandard Formula = "text_standard" ReadingTime Formula = "reading_time" )
func AllFormulas ¶
func AllFormulas() []Formula
AllFormulas returns a sorted list of all available formula names.