PHP code example of globus-studio / readsight
1. Go to this page and download the library: Download globus-studio/readsight library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
globus-studio / readsight example snippets
$plain = 'We made an app that reads your text. It tells you how easy it is to read. You get a score in one second.';
$legal = 'The parties acknowledge that any unauthorized disclosure of confidential information may cause irreparable harm. In such an event, the affected party shall be entitled to seek injunctive relief.';
use GlobusStudio\ReadSight\Engine;
$rs = new Engine('en-us');
foreach ($rs->getSupportedFormulas() as $formula) {
$result = $rs->score($formula, $legal);
// $result->score, $result->gradeLevel, $result->interpretation
// ...
}
use GlobusStudio\ReadSight\Engine;
$engine = new Engine('en-us');
// Syllable counting
$engine->syllableCount('banana'); // 3
$engine->splitSyllables('hyphenation'); // ['hyp', 'hen', 'ati', 'on'] (4 syllables, heuristic split)
$engine->splitWord('hyphenation'); // ['hy', 'phen', 'ation'] (TeX hyphenation points)
// Text analysis
$stats = $engine->analyze('The quick brown fox jumps over the lazy dog.');
echo "Words: {$stats->wordCount}, Syllables: {$stats->syllableCount}\n";
// Readability formulas
$fre = $engine->fleschReadingEase($text);
echo "Flesch Reading Ease: {$fre->score} - {$fre->interpretation}\n";
$fog = $engine->gunningFog($text);
echo "Gunning Fog: {$fog->score} (grade {$fog->gradeLevel})\n";
$lix = $engine->lix($text);
echo "LIX: {$lix->score} - {$lix->interpretation}\n";
$engine = new Engine('en-us'); // composite mode - heuristic wins
$engine->syllableCount('hyphenation'); // 4 ✓ (in problemWords list)
$engine->splitSyllables('hyphenation'); // ['hyp', 'hen', 'ati', 'on'] - heuristic: equal-width split, ≈ approximate
$engine->splitWord('hyphenation'); // ['hy', 'phen', 'ation'] - TeX hyphenator: exact points
$engine = new Engine('de-1996'); // tex mode
$engine->syllableCount('hyphenation'); // 4 ✓ (TeX patterns)
$engine->splitSyllables('hyphenation'); // ['hy', 'phena', 'ti', 'on'] - TeX: exact
$engine->splitWord('hyphenation'); // ['hy', 'phena', 'ti', 'on'] - same, both use TeX
$engine = new Engine('ru'); // Russian
$engine = new Engine('de-1996'); // German (1996 reform)
$engine = new Engine('es'); // Spanish
$engine = new Engine('th'); // Thai
// List all supported languages
$langs = Engine::getSupportedLanguages();
# ['af', 'ar', 'as', 'be', 'bg', 'bn', 'ca', 'cop', 'cs', 'cu', 'cy', 'da',
# 'de-1901', 'de-1996', 'de-ch-1901', 'el-monoton', 'el-polyton', 'en-gb',
# 'en-us', 'eo', 'es', 'et', 'eu', 'fa', 'fi', 'fi-x-school', 'fr', 'fur',
# 'ga', 'gl', 'grc', 'gu', 'he', 'hi', 'hr', 'hsb', 'hu', 'hy', 'ia', 'id',
# 'is', 'it', 'ka', 'kk', 'kmr', 'kn', 'la', 'la-x-classic', 'la-x-liturgic',
# 'lt', 'lv', 'mk', 'ml', 'mn-cyrl', 'mn-cyrl-x-lmc', 'mr', 'mul-ethi', 'nb',
# 'nl', 'nn', 'oc', 'or', 'pa', 'pi', 'pl', 'pms', 'pt', 'rm', 'ro', 'ru',
# 'sa', 'sh-cyrl', 'sh-latn', 'sk', 'sl', 'sq', 'sr-cyrl', 'sv', 'ta', 'te',
# 'th', 'tk', 'tr', 'uk', 'vi', 'zh-latn-pinyin']
$result = $engine->score('gunning_fog', $text);
$result = $engine->score('wiener_sachtextformel', $text);
$result->score; // float - raw formula score
$result->gradeLevel; // ?float - normalized grade level (FKGL, GF, SMOG, CL, ARI)
$result->interpretation; // string - qualitative interpretation ("Easy", "Hard")
$result->formulaName; // string - formula key
$result->languageCode; // string - language code used
$result->inputs; // array<string, float|int> - intermediate values for debugging
$engine->syllableCount(string $word): int
$engine->splitWord(string $word): list<string>
$engine->splitSyllables(string $word): list<string>
$engine->wordCount(string $text): int
$engine->sentenceCount(string $text): int
$engine->letterCount(string $text): int
$engine->totalSyllables(string $text): int
$engine->averageSyllablesPerWord(string $text): float
$engine->averageWordsPerSentence(string $text): float
$engine->polysyllableCount(string $text, bool $countProperNouns = true): int
$engine->wordsWithMoreThanNSyllables(string $text, int $n, bool $countProperNouns = true): int
$engine->histogramSyllables(string $text): array<int, int>
$engine->analyze(string $text): TextStatistics
$engine->fleschReadingEase(string $text): FormulaResult
$engine->fleschKincaidGradeLevel(string $text): FormulaResult
$engine->gunningFog(string $text): FormulaResult
$engine->smogIndex(string $text): FormulaResult
$engine->colemanLiau(string $text): FormulaResult
$engine->automatedReadabilityIndex(string $text): FormulaResult
$engine->lix(string $text): FormulaResult
$engine->wienerSachtextformel(string $text, int $variant = 1): FormulaResult
$engine->gulpease(string $text): FormulaResult
$engine->fernandezHuerta(string $text): FormulaResult
$engine->szigrisztPazos(string $text): FormulaResult
$engine->gutierrezPolini(string $text): FormulaResult
$engine->crawford(string $text): FormulaResult
$engine->fogPL(string $text): FormulaResult
$engine->daleChall(string $text): FormulaResult
$engine->spache(string $text): FormulaResult
$engine->osman(string $text): FormulaResult
use GlobusStudio\ReadSight\Engine;
// Set default paths (before creating engines)
Engine::setDefaultCacheDir('/var/cache/readsight');
Engine::setDefaultPatternsDir('/usr/share/readsight/patterns');
Engine::setDefaultLanguagesDir('/usr/share/readsight/languages');
// Or per-instance
$engine = new Engine(
language: 'en-us',
patternsDir: '/custom/patterns',
cacheDir: '/custom/cache',
);
// Add custom hyphenation rules (affects splitWord, not splitSyllables in composite/heuristic modes)
$engine->addHyphenations([
'customword' => 'cus-tom-word',
]);
$engine->splitWord('customword'); // ['cus', 'tom', 'word']
bash
php examples/dashboard.php
php examples/dashboard.php --lang=de-1996 --file=essay.txt
bash
php examples/demo.php
bash
php examples/demo.php --compare
bash
php examples/demo.php --file=essay.txt
php examples/demo.php --file=essay.txt --lang=de-1996