All Projects β†’ tigitz β†’ Php Spellchecker

tigitz / Php Spellchecker

Licence: mit
πŸ˜πŸŽ“πŸ“ PHP Library providing an easy way to spellcheck multiple sources of text by many spellcheckers

Projects that are alternatives of or similar to Php Spellchecker

Kts linguistics
Spellcheck, phonetics, text processing and more
Stars: ✭ 18 (-91.55%)
Mutual labels:  spellcheck
Spelling
Tools for Spell Checking in R
Stars: ✭ 82 (-61.5%)
Mutual labels:  spellcheck
Comment Spell Checker
Xcode extension for spell checking and auto-correcting code comments.
Stars: ✭ 155 (-27.23%)
Mutual labels:  spellcheck
Symspellcompound
SymSpellCompound: compound aware automatic spelling correction
Stars: ✭ 61 (-71.36%)
Mutual labels:  spellcheck
Vim Litecorrect
Lightweight auto-correction for Vim
Stars: ✭ 77 (-63.85%)
Mutual labels:  spellcheck
Symspell
SymSpell: 1 million times faster spelling correction & fuzzy search through Symmetric Delete spelling correction algorithm
Stars: ✭ 1,976 (+827.7%)
Mutual labels:  spellcheck
Yaspeller
πŸ” Search tool typos in the text, files and websites
Stars: ✭ 554 (+160.09%)
Mutual labels:  spellcheck
Hunspell Dict Ko
Korean spellchecking dictionary for Hunspell
Stars: ✭ 187 (-12.21%)
Mutual labels:  spellcheck
Guess Language.el
Emacs minor mode that detects the language you're typing in. Automatically switches spell checker. Supports multiple languages per document.
Stars: ✭ 78 (-63.38%)
Mutual labels:  spellcheck
Vim Ditto
πŸ™Š Stop repeating yourself
Stars: ✭ 148 (-30.52%)
Mutual labels:  spellcheck
Wecantspell.hunspell
A port of Hunspell v1 for .NET and .NET Standard
Stars: ✭ 61 (-71.36%)
Mutual labels:  spellcheck
Hunspell
The most popular spellchecking library.
Stars: ✭ 1,196 (+461.5%)
Mutual labels:  spellcheck
Did you mean
The gem that has been saving people from typos since 2014
Stars: ✭ 1,786 (+738.5%)
Mutual labels:  spellcheck
Grazi
Grammar checking and more for IntelliJ IDEA
Stars: ✭ 32 (-84.98%)
Mutual labels:  spellcheck
Misspell Fixer
Simple tool for fixing common misspellings, typos in source code
Stars: ✭ 154 (-27.7%)
Mutual labels:  spellcheck
Dictionaries
Hunspell dictionaries in UTF-8
Stars: ✭ 591 (+177.46%)
Mutual labels:  spellcheck
Nuspell
πŸ–‹οΈ Fast and safe spellchecking C++ library
Stars: ✭ 108 (-49.3%)
Mutual labels:  spellcheck
Nspell
πŸ“ Hunspell compatible spell-checker
Stars: ✭ 195 (-8.45%)
Mutual labels:  spellcheck
Spylls
Pure Python spell-checker, (almost) full port of Hunspell
Stars: ✭ 185 (-13.15%)
Mutual labels:  spellcheck
Dspellcheck
Notepad++ Spell-checking Plug-in
Stars: ✭ 144 (-32.39%)
Mutual labels:  spellcheck

PHP-Spellchecker

PHP-Spellchecker

Build Status Code coverage Code coverage PHP-Spellchecker chat room License

Check misspellings from any text source with the most popular PHP spellchecker.


About

PHP-Spellchecker is a spellchecker abstraction library for PHP. By providing a unified interface for many different spellcheckers, you’re able to swap out spellcheckers without extensive rewrites.

Using PHP-Spellchecker can eliminate vendor lock-in, reduce technical debt, and improve the testability of your code.

Features

PHP-Spellchecker is a welcoming project for new contributors.

Want to make your first open source contribution? Check the roadmap, pick one task, open an issue and we'll help you go through it πŸ€“πŸš€

Install

Via Composer

$ composer require tigitz/php-spellchecker

Usage

Check out the documentation and examples

Using the spellchecker directly

You can check misspellings directly from a PhpSpellCheck\SpellChecker class and process them on your own.

<?php
// if you made the default aspell installation on you local machine
$aspell = Aspell::create();

// or if you want to use binaries from Docker
$aspell = new Aspell(new CommandLine(['docker','run','--rm', '-i', 'starefossen/aspell']));

$misspellings = $aspell->check('mispell', ['en_US'], ['from_example']);
foreach ($misspellings as $misspelling) {
    $misspelling->getWord(); // 'mispell'
    $misspelling->getLineNumber(); // '1'
    $misspelling->getOffset(); // '0'
    $misspelling->getSuggestions(); // ['misspell', ...]
    $misspelling->getContext(); // ['from_example']
}

Using the MisspellingFinder orchestrator

You can also use an opinionated MisspellingFinder class to orchestrate your spellchecking flow:

PHP-Spellchecker-misspellingfinder-flow

Following the well-known Unix philosophy:

Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.

<?php
// My custom text processor that replaces "_" by " "
$customTextProcessor = new class implements TextProcessorInterface
{
    public function process(TextInterface $text): TextInterface
    {
        $contentProcessed = str_replace('_', ' ', $text->getContent());

        return $text->replaceContent($contentProcessed);
    }
};

$misspellingFinder = new MisspellingFinder(
    Aspell::create(), // Creates aspell spellchecker pointing to "aspell" as it's binary path
    new EchoHandler(), // Handles all the misspellings found by echoing their information
    $customTextProcessor
);

// using a string
$misspellingFinder->find('It\'s_a_mispelling', ['en_US']);
// word: mispelling | line: 1 | offset: 7 | suggestions: mi spelling,mi-spelling,misspelling | context: []

// using a TextSource
$inMemoryTextProvider = new class implements SourceInterface
{
    public function toTexts(array $context): iterable
    {
        yield new Text('my_mispell', ['from_source_interface']);
        // t() is a shortcut for new Text()
        yield t('my_other_mispell', ['from_named_constructor']);
    }
};

$misspellingFinder->find($inMemoryTextProvider, ['en_US']);
//word: mispell | line: 1 | offset: 3 | suggestions: mi spell,mi-spell,misspell,... | context: ["from_source_interface"]
//word: mispell | line: 1 | offset: 9 | suggestions: mi spell,mi-spell,misspell,... | context: ["from_named_constructor"]

Roadmap

The project is still in its initial phase, requiring more real life usage to stabilize its final 1.0.0 API.

Global

  • [ ] Add a CLI that could do something like vendor/bin/php-spellchecker "misspell" Languagetools EchoHandler --lang=en_US
  • [ ] Add asynchronous mechanism to spellcheckers.
  • [ ] Make some computed misspelling properties optional to improve performance for certain use cases (e.g., lines and offset in LanguageTools).
  • [ ] Add a language mapper to manage different representations across spellcheckers.
  • [ ] Evaluate strtok instead of explode to parse lines of text, for performance.
  • [ ] Evaluate MutableMisspelling for performance comparison.
  • [ ] Wrap Webmozart/Assert library exceptions to throw PHP-Spellchecker custom exceptions instead.
  • [ ] Improve the Makefile.

Sources

  • [ ] Make a SourceInterface class that's able to have an effect on the used spellchecker configuration.
  • [ ] League/Flysystem source.
  • [ ] Symfony/Finder source.

Text processors

  • [ ] Markdown - Find a way to keep original offset and line of words after stripping.
  • [ ] Add PHPDoc processor.
  • [ ] Add HTML Processor (inspiration).
  • [ ] Add XLIFF Processor (inspiration).

Spell checkers

  • [ ] Cache suggestions of already spellchecked words (PSR-6/PSR-16?).
  • [ ] Pspell - Find way to compute word offset.
  • [ ] LanguageTools - Evaluate HTTPlug library to make API requests.
  • [x] Pspell - find way to list available dictionaries.
  • [x] Add JamSpell spellchecker.
  • [ ] Add NuSpell spellchecker.
  • [ ] Add SymSpell spellchecker.
  • [ ] Add Yandex.Speller API spellchecker.
  • [ ] Add Bing Spell Check API spellchecker.

Handlers

  • [ ] MonologHandler
  • [ ] ChainedHandler
  • [ ] HTMLReportHandler
  • [ ] XmlReportHandler
  • [ ] JSONReportHandler
  • [ ] ConsoleTableHandler

Tests

  • [ ] Add or improve tests with different text encoding.
  • [ ] Refactor duplicate Dockerfile content between PHP images.

Versioning

We follow SemVer v2.0.0.

There still are many design decisions that should be confronted with real-world usage before thinking about a v1.0.0 stable release:

  • Are TextInterface and MisspellingInterface really useful?
  • Is using generators the right way to go?
  • Should all the contributed spellcheckers be maintained by the package itself?
  • How to design an intuitive CLI given the needed flexibility of usage?
  • Is the "context" array passed through all the layers the right design to handle data sharing?

Testing

Spell checkers come in many different forms, from HTTP API to command line tools. PHP-Spellchecker wants to ensure real-world usage is OK, so it contains integration tests. To run these, spellcheckers need to all be available during tests execution.

The most convenient way to do it is by using Docker and avoid polluting your local machine.

Docker

Requires docker and docker-compose to be installed (tested on Linux).

$ make build # build container images
$ make setup # start spellcheckers container
$ make tests-dox

You can also specify PHP version, dependency version target and if you want coverage. Coverage is only supported by PHP 7.2 for now.

$ PHP_VERSION=7.2 DEPS=LOWEST WITH_COVERAGE="true" make tests-dox

Run make help to list all available tasks.

Locally

Todo

Environment variables

If spellcheckers execution paths are different than their default values (e.g., docker exec -ti myispell instead of ispell) you can override the path used in tests by redefining environment variables in the PHPUnit config file.

Contributing

Please see CONTRIBUTING.

Credits

License

The MIT License (MIT). Please see license file for more information.

Logo: Elements taken for the final rendering are Designed by rawpixel.com / Freepik.

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].