From 18938c9ce324ace65206336e47d67e469324eb5a Mon Sep 17 00:00:00 2001 From: Bas van Dinther Date: Fri, 11 Aug 2023 15:38:55 +0200 Subject: [PATCH] wip --- src/Checks/Content/FleschReadingEaseCheck.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Checks/Content/FleschReadingEaseCheck.php b/src/Checks/Content/FleschReadingEaseCheck.php index 7a30fe41..0e46fa16 100644 --- a/src/Checks/Content/FleschReadingEaseCheck.php +++ b/src/Checks/Content/FleschReadingEaseCheck.php @@ -48,11 +48,23 @@ public function validateContent(Crawler $crawler): bool // Average syllable count per word $averageSyllableCount = $this->getAverageSyllableCountPerWord($sentences); - dd($averageSyllableCount, $averageWordCount); + $fleschReadingEase = $this->fleschReadingEaseScoreFromAverages($averageSyllableCount, $averageWordCount); + + // TODO: + // Average word count is too low and the average syllable count is too high. That's why the calculation is not accurate. + // Probably because we still get sentences like: cls-11{stroke:#fe8185} + // We need to find a better way to get all sentences from a web page. + dd($averageSyllableCount, $averageWordCount, $fleschReadingEase); // return true; } + private function fleschReadingEaseScoreFromAverages(float $averageSyllableCount, float $averageWordCount): float + { + $fleschReadingEase = 206.835 - (1.015 * $averageWordCount) - (84.6 * $averageSyllableCount); + return $fleschReadingEase; + } + private function getAverageWordCountPerSentence(array $sentences): int { $totalWordCount = 0;