| @@ 132-159 (lines=28) @@ | ||
| 129 | * @param boolean|string $strText Text to be checked |
|
| 130 | * @return int|float |
|
| 131 | */ |
|
| 132 | public function fleschKincaidReadingEase($strText = false) |
|
| 133 | { |
|
| 134 | $strText = $this->setText($strText); |
|
| 135 | ||
| 136 | $score = Maths::bcCalc( |
|
| 137 | Maths::bcCalc( |
|
| 138 | 206.835, |
|
| 139 | '-', |
|
| 140 | Maths::bcCalc( |
|
| 141 | 1.015, |
|
| 142 | '*', |
|
| 143 | Text::averageWordsPerSentence($strText, $this->strEncoding) |
|
| 144 | ) |
|
| 145 | ), |
|
| 146 | '-', |
|
| 147 | Maths::bcCalc( |
|
| 148 | 84.6, |
|
| 149 | '*', |
|
| 150 | Syllables::averageSyllablesPerWord($strText, $this->strEncoding) |
|
| 151 | ) |
|
| 152 | ); |
|
| 153 | ||
| 154 | if ($this->normalise) { |
|
| 155 | return Maths::normaliseScore($score, 0, 100, $this->dps); |
|
| 156 | } else { |
|
| 157 | return Maths::bcCalc($score, '+', 0, true, $this->dps); |
|
| 158 | } |
|
| 159 | } |
|
| 160 | ||
| 161 | /** |
|
| 162 | * Gives the Flesch-Kincaid Grade level of text entered rounded to one digit |
|
| @@ 166-193 (lines=28) @@ | ||
| 163 | * @param boolean|string $strText Text to be checked |
|
| 164 | * @return int|float |
|
| 165 | */ |
|
| 166 | public function fleschKincaidGradeLevel($strText = false) |
|
| 167 | { |
|
| 168 | $strText = $this->setText($strText); |
|
| 169 | ||
| 170 | $score = Maths::bcCalc( |
|
| 171 | Maths::bcCalc( |
|
| 172 | 0.39, |
|
| 173 | '*', |
|
| 174 | Text::averageWordsPerSentence($strText, $this->strEncoding) |
|
| 175 | ), |
|
| 176 | '+', |
|
| 177 | Maths::bcCalc( |
|
| 178 | Maths::bcCalc( |
|
| 179 | 11.8, |
|
| 180 | '*', |
|
| 181 | Syllables::averageSyllablesPerWord($strText, $this->strEncoding) |
|
| 182 | ), |
|
| 183 | '-', |
|
| 184 | 15.59 |
|
| 185 | ) |
|
| 186 | ); |
|
| 187 | ||
| 188 | if ($this->normalise) { |
|
| 189 | return Maths::normaliseScore($score, 0, $this->maxGradeLevel, $this->dps); |
|
| 190 | } else { |
|
| 191 | return Maths::bcCalc($score, '+', 0, true, $this->dps); |
|
| 192 | } |
|
| 193 | } |
|
| 194 | ||
| 195 | /** |
|
| 196 | * Gives the Gunning-Fog score of text entered rounded to one digit |
|
| @@ 268-299 (lines=32) @@ | ||
| 265 | * @param boolean|string $strText Text to be checked |
|
| 266 | * @return int|float |
|
| 267 | */ |
|
| 268 | public function smogIndex($strText = false) |
|
| 269 | { |
|
| 270 | $strText = $this->setText($strText); |
|
| 271 | ||
| 272 | $score = Maths::bcCalc( |
|
| 273 | 1.043, |
|
| 274 | '*', |
|
| 275 | Maths::bcCalc( |
|
| 276 | Maths::bcCalc( |
|
| 277 | Maths::bcCalc( |
|
| 278 | Syllables::wordsWithThreeSyllables($strText, true, $this->strEncoding), |
|
| 279 | '*', |
|
| 280 | Maths::bcCalc( |
|
| 281 | 30, |
|
| 282 | '/', |
|
| 283 | Text::sentenceCount($strText, $this->strEncoding) |
|
| 284 | ) |
|
| 285 | ), |
|
| 286 | 'sqrt', |
|
| 287 | 0 |
|
| 288 | ), |
|
| 289 | '+', |
|
| 290 | 3.1291 |
|
| 291 | ) |
|
| 292 | ); |
|
| 293 | ||
| 294 | if ($this->normalise) { |
|
| 295 | return Maths::normaliseScore($score, 0, $this->maxGradeLevel, $this->dps); |
|
| 296 | } else { |
|
| 297 | return Maths::bcCalc($score, '+', 0, true, $this->dps); |
|
| 298 | } |
|
| 299 | } |
|
| 300 | ||
| 301 | /** |
|
| 302 | * Gives the Automated Readability Index of text entered rounded to one digit |
|
| @@ 390-421 (lines=32) @@ | ||
| 387 | * @param boolean|string $strText Text to be checked |
|
| 388 | * @return int|float |
|
| 389 | */ |
|
| 390 | public function spacheReadabilityScore($strText = false) |
|
| 391 | { |
|
| 392 | $strText = $this->setText($strText); |
|
| 393 | ||
| 394 | $score = Maths::bcCalc( |
|
| 395 | Maths::bcCalc( |
|
| 396 | Maths::bcCalc( |
|
| 397 | 0.121, |
|
| 398 | '*', |
|
| 399 | Maths::bcCalc( |
|
| 400 | Text::wordCount($strText, $this->strEncoding), |
|
| 401 | '/', |
|
| 402 | Text::sentenceCount($strText, $this->strEncoding) |
|
| 403 | ) |
|
| 404 | ), |
|
| 405 | '+', |
|
| 406 | Maths::bcCalc( |
|
| 407 | 0.082, |
|
| 408 | '*', |
|
| 409 | $this->spacheDifficultWordCount($strText) |
|
| 410 | ) |
|
| 411 | ), |
|
| 412 | '+', |
|
| 413 | 0.659 |
|
| 414 | ); |
|
| 415 | ||
| 416 | if ($this->normalise) { |
|
| 417 | return Maths::normaliseScore($score, 0, 5, $this->dps); // Not really suitable for measuring readability above grade 4 |
|
| 418 | } else { |
|
| 419 | return Maths::bcCalc($score, '+', 0, true, $this->dps); |
|
| 420 | } |
|
| 421 | } |
|
| 422 | ||
| 423 | /** |
|
| 424 | * Returns the number of words NOT on the Dale-Chall easy word list |
|