All Projects → mekras → php-speller

mekras / php-speller

Licence: MIT license
PHP spell check library

Programming Languages

PHP
23972 projects - #3 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to php-speller

ispell-lt
Lithuanian spellchecking dictionary
Stars: ✭ 26 (-60.61%)
Mutual labels:  spelling, aspell, hunspell, ispell
spacy hunspell
✏️ Hunspell extension for spaCy 2.0.
Stars: ✭ 94 (+42.42%)
Mutual labels:  spelling, hunspell
ka GE.spell
ქართული ორთოგრაფიული ლექსიკონი - Georgian Spell Checking Dictionary
Stars: ✭ 24 (-63.64%)
Mutual labels:  spelling, hunspell
cyberdic
An auxiliary spellcheck dictionary that corresponds with the Bishop Fox Cybersecurity Style Guide
Stars: ✭ 63 (-4.55%)
Mutual labels:  spelling, hunspell
spellr
Spell check your source code
Stars: ✭ 31 (-53.03%)
Mutual labels:  spelling
yaspeller-ci
Fast spelling check for Travis CI
Stars: ✭ 60 (-9.09%)
Mutual labels:  spelling
convert-british-to-american-spellings
Convert text so that British spellings are swapped with their Americanized form or vice versa.
Stars: ✭ 26 (-60.61%)
Mutual labels:  spelling
spellchecker-wasm
SpellcheckerWasm is an extrememly fast spellchecker for WebAssembly based on SymSpell
Stars: ✭ 46 (-30.3%)
Mutual labels:  spelling
spell
Spelling correction and string segmentation written in Go
Stars: ✭ 24 (-63.64%)
Mutual labels:  spelling
Did you mean
The gem that has been saving people from typos since 2014
Stars: ✭ 1,786 (+2606.06%)
Mutual labels:  spelling
SymSpellCppPy
Fast SymSpell written in c++ and exposes to python via pybind11
Stars: ✭ 28 (-57.58%)
Mutual labels:  spelling
lingose-notation
The best mnemonics and notational system of English words.
Stars: ✭ 17 (-74.24%)
Mutual labels:  spelling
Symspell
SymSpell: 1 million times faster spelling correction & fuzzy search through Symmetric Delete spelling correction algorithm
Stars: ✭ 1,976 (+2893.94%)
Mutual labels:  spelling
Spell-IT
Flutter Game for improving your english vocabulary skills
Stars: ✭ 16 (-75.76%)
Mutual labels:  spelling
check-spelling
Spelling checker action
Stars: ✭ 139 (+110.61%)
Mutual labels:  spelling
Chinese Programmer Wrong Pronunciation
中国程序员容易发音错误的单词
Stars: ✭ 14,766 (+22272.73%)
Mutual labels:  spelling
LinSpell
Fast approximate strings search & spelling correction
Stars: ✭ 52 (-21.21%)
Mutual labels:  spelling
GreynirCorrect
Spelling and grammar correction for Icelandic
Stars: ✭ 12 (-81.82%)
Mutual labels:  spelling
Buzz
🐝 Spelling Bee game for Android
Stars: ✭ 62 (-6.06%)
Mutual labels:  spelling
jetbrains-polish-dictionary
Polish dictionary for JetBrains' IDEs
Stars: ✭ 63 (-4.55%)
Mutual labels:  spelling

php-speller

PHP spell check library.

Latest Stable Version License Build Pipeline

Currently supported backends:

Installation

With Composer:

$ composer require mekras/php-speller

Usage

  1. Create a text source object from string, file or something else using one of the Mekras\Speller\Source\Source implementations (see Sources below).
  2. Create some speller instance (Hunspell, Ispell or any other implementation of the Mekras\Speller\Speller).
  3. Execute Speller::checkText() method.
use Mekras\Speller\Hunspell\Hunspell;
use Mekras\Speller\Source\StringSource;

$source = new StringSource('Tiger, tigr, burning bright');
$speller = new Hunspell();
$issues = $speller->checkText($source, ['en_GB', 'en']);

echo $issues[0]->word; // -> "tigr"
echo $issues[0]->line; // -> 1
echo $issues[0]->offset; // -> 7
echo implode(',', $issues[0]->suggestions); // -> tiger, trig, tier, tigris, tigress

You can list languages supported by backend:

/** @var Mekras\Speller\Speller $speller */
print_r($speller->getSupportedLanguages());

See examples for more info.

Source encoding

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

Aspell

This backend uses aspell program, so it should be installed in the system.

use Mekras\Speller\Aspell\Aspell;

$speller = new Aspell();

Path to binary can be set in constructor:

use Mekras\Speller\Aspell\Aspell;

$speller = new Aspell('/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 count of words inside the dictionary. Beware that there should no spaces at the end of words. Each word should be listed in a new line.

$aspell = new Aspell();
$aspell->setPersonalDictionary(new Dictionary('/path/to/custom.pws'));

Important

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

Hunspell

This backend uses hunspell program, so it should be installed in the system.

use Mekras\Speller\Hunspell\Hunspell;

$speller = new Hunspell();

Path to binary can be set in constructor:

use Mekras\Speller\Hunspell\Hunspell;

$speller = new Hunspell('/usr/local/bin/hunspell');

You can set additional dictionary path:

use Mekras\Speller\Hunspell\Hunspell;

$speller = new Hunspell();
$speller->setDictionaryPath('/var/spelling/custom');

You can specify custom dictionaries to use:

use Mekras\Speller\Hunspell\Hunspell;

$speller = new Hunspell();
$speller->setDictionaryPath('/my_app/spelling');
$speller->setCustomDictionaries(['tech', 'titles']);

Ispell

This backend uses ispell program, so it should be installed in the system.

use Mekras\Speller\Ispell\Ispell;

$speller = new Ispell();

Path to binary can be set in constructor:

use Mekras\Speller\Ispell\Ispell;

$speller = new Ispell('/usr/local/bin/ispell');

Important

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

Sources

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

FileSource

Reads text from file.

use Mekras\Speller\Source\FileSource;

$source = new FileSource('/path/to/file.txt');

You can specify file encoding:

use Mekras\Speller\Source\FileSource;

$source = new FileSource('/path/to/file.txt', 'windows-1251');

StringSource

Use string as text source.

use Mekras\Speller\Source\StringSource;

$source = new StringSource('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.

use Mekras\Speller\Source\HtmlSource;

$source = new HtmlSource(
    new StringSource('<a  title="Foo">Bar</a> Baz')
);
echo $source->getAsString(); // Foo Bar Baz

Encoding detected via DOMDocument::$encoding.

IconvSource

This is a meta-source which converts encoding of other given source:

use Mekras\Speller\Source\IconvSource;
use Mekras\Speller\Source\StringSource;

// Convert file contents from windows-1251 to koi8-r.
$source = new IconvSource(
    new FileSource('/path/to/file.txt', 'windows-1251'),
    'koi8-r'
);

XliffSource

Loads text from XLIFF files.

use Mekras\Speller\Source\XliffSource;

$source = new XliffSource(__DIR__ . '/fixtures/test.xliff');

Source filters

Filters used internally to filter out all non text contents received from source. In order to save original word location (line and column numbers) all filters replaces non text content with spaces.

Available filters:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].