Skip to content

Commit 4a30f7e

Browse files
committed
Add readme
1 parent fd3b00c commit 4a30f7e

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ReadSight is a PHP library for measuring text readability across **86 languages*
1414

1515
- [Installation](#installation)
1616
- [Quick Start](#quick-start)
17+
- [Syllable Counting Modes](#syllable-counting-modes)
1718
- [Demo](#demo)
1819
- [Supported Languages](#supported-languages)
1920
- [Readability Formulas](#readability-formulas)
@@ -47,7 +48,8 @@ $engine = new Engine('en-us');
4748

4849
// Syllable counting
4950
$engine->syllableCount('banana'); // 3
50-
$engine->splitWord('hyphenation'); // ['hy', 'phen', 'ation']
51+
$engine->splitSyllables('hyphenation'); // ['hyp', 'hen', 'ati', 'on'] (4 syllables, heuristic split)
52+
$engine->splitWord('hyphenation'); // ['hy', 'phen', 'ation'] (TeX hyphenation points)
5153

5254
// Text analysis
5355
$stats = $engine->analyze('The quick brown fox jumps over the lazy dog.');
@@ -64,6 +66,36 @@ $lix = $engine->lix($text);
6466
echo "LIX: {$lix->score} - {$lix->interpretation}\n";
6567
```
6668

69+
## Syllable Counting Modes
70+
71+
ReadSight has three syllable counting modes, configured per language via `syllableMode` in `data/languages/*.json`:
72+
73+
| Mode | How it works | `count` accuracy | `split` accuracy |
74+
|---|---|---|---|
75+
| **`heuristic`** | Vowel patterns + word list + prefix/suffix rules || ≈ approximate |
76+
| **`tex`** | Frank M. Liang hyphenation algorithm (TeX `.tex` patterns) || ✓ exact |
77+
| **`composite`** | Heuristic first, TeX as fallback || ≈ approximate (uses heuristic split) |
78+
79+
The default mode is **`tex`**. **84 languages use `tex`**; **2 use `composite`** (`en-us`, `en-gb`).
80+
81+
### Example: "hyphenation" in each mode
82+
83+
```php
84+
$engine = new Engine('en-us'); // composite mode - heuristic wins
85+
$engine->syllableCount('hyphenation'); // 4 ✓ (in problemWords list)
86+
$engine->splitSyllables('hyphenation'); // ['hyp', 'hen', 'ati', 'on'] - heuristic: equal-width split, ≈ approximate
87+
$engine->splitWord('hyphenation'); // ['hy', 'phen', 'ation'] - TeX hyphenator: exact points
88+
89+
$engine = new Engine('de-1996'); // tex mode
90+
$engine->syllableCount('hyphenation'); // 4 ✓ (TeX patterns)
91+
$engine->splitSyllables('hyphenation'); // ['hy', 'phena', 'ti', 'on'] - TeX: exact
92+
$engine->splitWord('hyphenation'); // ['hy', 'phena', 'ti', 'on'] - same, both use TeX
93+
```
94+
95+
> **Tip:** `splitWord()` always uses the TeX hyphenator (exact). `splitSyllables()` may use the heuristic split (approximate) in `composite`/`heuristic` modes. For syllable *counts* both are correct.
96+
97+
> **Note:** `addHyphenations()` adds overrides to the TeX hyphenator. These affect `splitWord()` but NOT `splitSyllables()` in `composite`/`heuristic` modes (the heuristic counter doesn't see them).
98+
6799
## Demo
68100

69101
Run the interactive demo to see ReadSight in action:
@@ -168,6 +200,7 @@ $result->inputs; // array<string, float|int> - intermediate values for
168200
```php
169201
$engine->syllableCount(string $word): int
170202
$engine->splitWord(string $word): list<string>
203+
$engine->splitSyllables(string $word): list<string>
171204
$engine->wordCount(string $text): int
172205
$engine->sentenceCount(string $text): int
173206
$engine->letterCount(string $text): int
@@ -180,6 +213,8 @@ $engine->histogramSyllables(string $text): array<int, int>
180213
$engine->analyze(string $text): TextStatistics
181214
```
182215

216+
> **`splitSyllables` vs `splitWord`:** `splitSyllables` may use the heuristic ≈approximate split (depends on the language's `syllableMode`). `splitWord` always uses the TeX hyphenator for exact hyphenation points. Syllable *counts* are accurate in all modes. See [Syllable Counting Modes](#syllable-counting-modes).
217+
183218
#### Formula Methods
184219

185220
```php
@@ -232,10 +267,11 @@ $engine = new Engine(
232267
cacheDir: '/custom/cache',
233268
);
234269

235-
// Add custom hyphenation rules
270+
// Add custom hyphenation rules (affects splitWord, not splitSyllables in composite/heuristic modes)
236271
$engine->addHyphenations([
237272
'customword' => 'cus-tom-word',
238273
]);
274+
$engine->splitWord('customword'); // ['cus', 'tom', 'word']
239275
```
240276

241277
## Architecture

0 commit comments

Comments
 (0)