0xDEADBEEF

RSS odkazy english edition

readability.php

17. 5. 2022
while (($line = fgets(STDIN)) !== false) {
  $line = trim($line);
  if (strlen($line) < 200) continue;

  $line = preg_replace('~\d+\.\d+~', '', $line);
  $line = preg_replace('~\b&\b~', 'a', $line);
  $line = preg_replace('~[^\w.?! ]~u', '', $line);
  $line = preg_replace('~\s+~', ' ', $line);

  $words = count(preg_split('~\s~', $line));
  $sentences = preg_match_all('~[.?!]+~', $line);

  $syllables = preg_match_all('~(au|ou|eu|a|á|e|é|ě|i|í|o|ó|u|ú|ů|y|ý|\b(k|v|z)\b)~iu', $line);

  if ($sentences === 0 || $words === 0) continue;

  // https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests
  //$score = 206.835 - 1.015 * ($words / $sentences) - 84.6 * ($syllables / $words);

  // https://ufal.mff.cuni.cz/biblio/attachments/2021-bendova-p179299898553114557.pdf
  $score = 206.935 - 1.672 * ($words / $sentences) - 62.18 * ($syllables / $words);

  echo $score, " ", $line, "\n";
}
píše k47 (@kaja47, k47)