Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/Formula/Crawford.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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',
};
}
Expand Down