diff --git a/src/Formula/Crawford.php b/src/Formula/Crawford.php index 3223910..fcd6464 100644 --- a/src/Formula/Crawford.php +++ b/src/Formula/Crawford.php @@ -30,10 +30,12 @@ public function calculate(TextStatistics $stats, Language $language): FormulaRes $wordCount = $stats->wordCount > 0 ? $stats->wordCount : 1; $sentenceCount = $stats->sentenceCount > 0 ? $stats->sentenceCount : 1; - $averageLetters = $stats->letterCount / $wordCount; + // Crawford (1989) is a Fry-type procedure: its two inputs are sentences + // per 100 words (OP) and syllables per 100 words (SP). $sentencesPer100 = ($sentenceCount / $wordCount) * 100.0; + $syllablesPer100 = ($stats->syllableCount / $wordCount) * 100.0; - $score = -0.205 * $averageLetters + 0.049 * $sentencesPer100 - 3.407; + $score = -0.205 * $sentencesPer100 + 0.049 * $syllablesPer100 - 3.407; return new FormulaResult( formulaName: $this->name(), @@ -42,19 +44,20 @@ public function calculate(TextStatistics $stats, Language $language): FormulaRes gradeLevel: null, interpretation: $this->interpret($score), inputs: [ - 'avgLettersPerWord' => \round($averageLetters, 2), 'sentencesPer100Words' => \round($sentencesPer100, 2), + 'syllablesPer100Words' => \round($syllablesPer100, 2), ], ); } private function interpret(float $score): string { + // Years of schooling: the more years a text needs, the harder it is. return match (true) { - $score >= 9.0 => 'Very Easy', - $score >= 7.0 => 'Easy', - $score >= 5.0 => 'Standard', - $score >= 3.0 => 'Difficult', + $score <= 3.0 => 'Very Easy', + $score <= 5.0 => 'Easy', + $score <= 7.0 => 'Standard', + $score <= 9.0 => 'Difficult', default => 'Very Difficult', }; }