r34117y / kwg-parser
Extract word lists from Kurnia Word Graph (KWG) files.
Requires
- php: ^8.4.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.84
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^13.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
KWG Parser extracts word lists from Kurnia Word Graph (KWG) files used by computer Scrabble tools.
Installation
composer require r34117y/kwg-parser
Usage
use Agrzelec\KwgParser\KwgWordExtractor; use Agrzelec\KwgParser\KwgWordListWriter; $extractor = new KwgWordExtractor(); $words = $extractor->extract('/path/to/NWL23.kwg'); $writer = new KwgWordListWriter(); $writer->write('/path/to/words.txt', $words);
Extraction returns a deterministic alphabetically sorted list<string>. Saving writes exactly one
word per line using UTF-8-compatible plain text.
Supported Alphabets
The extractor recognizes common real-world lexicon filename prefixes and applies the matching alphabet automatically. Supported alphabets are English, Catalan, Dutch, French, German, Norwegian, Polish, Slovene, and Spanish.
This allows national alphabet KWGs with tile values beyond Z, such as NSF25.kwg, OSPS52.kwg,
RD29.kwg, and SLV26.kwg, to produce stable UTF-8 word lists. Unknown lexicon filename prefixes
use the English alphabet by default and fail clearly if the KWG contains tile values that cannot be
resolved.
Errors
Agrzelec\KwgParser\Exception\InvalidKwgFileException is thrown when a KWG path is missing, unreadable,
empty, truncated, malformed, uses unresolvable tile labels, or is not a supported KWG file.
Agrzelec\KwgParser\Exception\WordListWriteException is thrown when the destination text file cannot be
created or written.
Quality
composer test
composer analyse
composer cs-check
composer check
Versioning
This package follows Semantic Versioning. Public API compatibility is maintained across patch and minor releases within the same major version; breaking public API changes are reserved for major releases.