Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PHP spell check library

License

NotificationsYou must be signed in to change notification settings

mekras/php-speller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

139 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP spell check library.

Latest Stable VersionLicenseBuild Pipeline

Currently supported backends:

Installation

WithComposer:

$ composer require mekras/php-speller

Usage

  1. Create a text source object from string, file or something else using one of theMekras\Speller\Source\Source implementations (seeSources below).
  2. Create some speller instance (Hunspell, Ispell or any other implementation of theMekras\Speller\Speller).
  3. ExecuteSpeller::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.

Source encoding

For aspell, hunspell and ispell source text encoding should be equal to dictionary encoding. You canuseIconvSource to convert source.

Aspell

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');

Custom Dictionary

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'));

Important

  • aspell allow to specify only one language at once, so only first item taken from$languages argument inIspell::checkText().

Hunspell

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']);

Ispell

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');

Important

  • ispell allow to use only one dictionary at once, so only first item taken from$languages argument inIspell::checkText().

Sources

Sources — is an abstraction layer allowing spellers receive text from different sources like stringsor files.

FileSource

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');

StringSource

Use string as text source.

useMekras\Speller\Source\StringSource;$source =newStringSource('foo','koi8-r');

Meta sources

Additionally there is a set of meta sources, which wraps other sources to perform extra tasks.

HtmlSource

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.

IconvSource

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');

XliffSource

Loads text fromXLIFFfiles.

useMekras\Speller\Source\XliffSource;$source =newXliffSource(__DIR__ .'/fixtures/test.xliff');

Source filters

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:

About

PHP spell check library

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors12


[8]ページ先頭

©2009-2026 Movatter.jp