- Notifications
You must be signed in to change notification settings - Fork24
mekras/php-speller
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
PHP spell check library.
Currently supported backends:
WithComposer:
$ composer require mekras/php-speller- Create a text source object from string, file or something else using one of the
Mekras\Speller\Source\Sourceimplementations (seeSources below). - Create some speller instance (Hunspell, Ispell or any other implementation of the
Mekras\Speller\Speller). - Execute
Speller::checkText()method.
useMekras\Speller\Hunspell\Hunspell;useMekras\Speller\Source\StringSource;$source =newStringSource('Tiger, tigr, burning bright');$speller =newHunspell();$issues =$speller->checkText($source, ['en_GB','en']);echo$issues[0]->word;// -> "tigr"echo$issues[0]->line;// -> 1echo$issues[0]->offset;// -> 7echoimplode(',',$issues[0]->suggestions);// -> tiger, trig, tier, tigris, tigress
You can list languages supported by backend:
/** @var Mekras\Speller\Speller $speller */print_r($speller->getSupportedLanguages());
Seeexamples for more info.
For aspell, hunspell and ispell source text encoding should be equal to dictionary encoding. You canuseIconvSource to convert source.
This backend uses aspell program, so it should be installed in the system.
useMekras\Speller\Aspell\Aspell;$speller =newAspell();
Path to binary can be set in constructor:
useMekras\Speller\Aspell\Aspell;$speller =newAspell('/usr/local/bin/aspell');
You can use a custom dictionary for aspell. The dictionary needs to be in the following format:
personal_ws-1.1 [lang] [words]Where[lang] shout be the shorthand for the language you are using (e.g.en) and[words] is the countof words inside the dictionary.Beware that there should no spaces at the end of words. Each word should be listedin a new line.
$aspell =newAspell();$aspell->setPersonalDictionary(newDictionary('/path/to/custom.pws'));
- aspell allow to specify only one language at once, so only first item taken from$languages argument in
Ispell::checkText().
This backend uses hunspell program, so it should be installed in the system.
useMekras\Speller\Hunspell\Hunspell;$speller =newHunspell();
Path to binary can be set in constructor:
useMekras\Speller\Hunspell\Hunspell;$speller =newHunspell('/usr/local/bin/hunspell');
You can set additional dictionary path:
useMekras\Speller\Hunspell\Hunspell;$speller =newHunspell();$speller->setDictionaryPath('/var/spelling/custom');
You can specify custom dictionaries to use:
useMekras\Speller\Hunspell\Hunspell;$speller =newHunspell();$speller->setDictionaryPath('/my_app/spelling');$speller->setCustomDictionaries(['tech','titles']);
This backend uses ispell program, so it should be installed in the system.
useMekras\Speller\Ispell\Ispell;$speller =newIspell();
Path to binary can be set in constructor:
useMekras\Speller\Ispell\Ispell;$speller =newIspell('/usr/local/bin/ispell');
- ispell allow to use only one dictionary at once, so only first item taken from$languages argument in
Ispell::checkText().
Sources — is an abstraction layer allowing spellers receive text from different sources like stringsor files.
Reads text from file.
useMekras\Speller\Source\FileSource;$source =newFileSource('/path/to/file.txt');
You can specify file encoding:
useMekras\Speller\Source\FileSource;$source =newFileSource('/path/to/file.txt','windows-1251');
Use string as text source.
useMekras\Speller\Source\StringSource;$source =newStringSource('foo','koi8-r');
Additionally there is a set of meta sources, which wraps other sources to perform extra tasks.
Return user visible text from HTML.
useMekras\Speller\Source\HtmlSource;$source =newHtmlSource(newStringSource('<a href="#" title="Foo">Bar</a> Baz'));echo$source->getAsString();// Foo Bar Baz
Encoding detected viaDOMDocument::$encoding.
This is a meta-source which converts encoding of other given source:
useMekras\Speller\Source\IconvSource;useMekras\Speller\Source\StringSource;// Convert file contents from windows-1251 to koi8-r.$source =newIconvSource(newFileSource('/path/to/file.txt','windows-1251'),'koi8-r');
Loads text fromXLIFFfiles.
useMekras\Speller\Source\XliffSource;$source =newXliffSource(__DIR__ .'/fixtures/test.xliff');
Filters used internally to filter out all non text contents received from source. In order to saveoriginal word location (line and column numbers) all filters replaces non text content with spaces.
Available filters:
- StripAllFilter — strips all input text;
- HtmlFilter — strips HTML tags.
About
PHP spell check library
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors12
Uh oh!
There was an error while loading.Please reload this page.

