WeCantSpell.Hunspell 4.0.0

.NET 6.0 .NET Standard 2.0
NuGet\Install-Package WeCantSpell.Hunspell -Version 4.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package WeCantSpell.Hunspell --version 4.0.0
<PackageReference Include="WeCantSpell.Hunspell" Version="4.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WeCantSpell.Hunspell --version 4.0.0
#r "nuget: WeCantSpell.Hunspell, 4.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install WeCantSpell.Hunspell as a Cake Addin
#addin nuget:?package=WeCantSpell.Hunspell&version=4.0.0

// Install WeCantSpell.Hunspell as a Cake Tool
#tool nuget:?package=WeCantSpell.Hunspell&version=4.0.0

WeCantSpell: Hunspell

A port of Hunspell for .NET.

bee

Download and install with NuGet: WeCantSpell.Hunspell

NuGet version CI

Features

  • Reads Hunspell DIC and AFF file formats
  • Supports checking and suggesting words
  • Ported to fully managed C#
  • Can be queried concurrently
  • Confusing LGPL, GPL, MPL tri-license
  • Compatible with .NET Core and .NET Standard
  • Compatible with multiple .NET framework versions
  • Uses .NET to handle cultures and encodings

License

"It's complicated"

Read the license: LICENSE

This library was ported from the original Hunspell source and as a result is licensed under an MPL, LGPL, and GPL tri-license. Read the LICENSE file to be sure you can use this library.

Quick Start Example

using WeCantSpell.Hunspell;

var dictionary = WordList.CreateFromFiles(@"English (British).dic");
bool notOk = dictionary.Check("Color");
var suggestions = dictionary.Suggest("Color");
bool ok = dictionary.Check("Colour");

Upstream

To know how up to date this port is, check the hunspell-origin submodule.

Performance

"Good enough I guess"

The performance of this port while not fantastic relative to the original binaries and NHunspell is definitely acceptable. If you need better performance you should check out NHunspell.

Benchmark WeCantSpell.Hunspell net6 WeCantSpell.Hunspell net48 NHunspell
Dictionary Loads /s 🥌 4 🐌 3 🐇 14
Words Checked /s 🐇 1,244,387 🐢 670,525 🐇 1,319,847
Suggest Queries / s 🐇 167 🥌 93 🐢 38

Note: Measurements taken on an AMD 5800H.

To reproduce:

dotnet run -c Release --project .\WeCantSpell.Hunspell.Benchmarking.LongRunning\WeCantSpell.Hunspell.Benchmarking.LongRunning.csproj --output ./perf-reports/
dotnet run -c Release --project .\WeCantSpell.Hunspell.Benchmarking.NHunspell\WeCantSpell.Hunspell.Benchmarking.NHunspell.csproj --output ./perf-reports/

Specialized Examples

Construct from a list:

var words = "The quick brown fox jumps over the lazy dog".Split(' ');
var dictionary = WordList.CreateFromWords(words);
bool notOk = dictionary.Check("teh");

Construct from streams:

using var dictionaryStream = File.OpenRead(@"English (British).dic");
using var affixStream = File.OpenRead(@"English (British).aff");
var dictionary = WordList.CreateFromStreams(dictionaryStream, affixStream);
bool notOk = dictionary.Check("teh");

Encoding Issues

The .NET Framework contains many encodings that can be handy when opening some dictionary or affix files that do not use a UTF8 encoding or were incorrectly given a UTF BOM. On a full framework platform this works out great but when using .NET Core or .NET Standard those encodings may be missing. If you suspect that there is an issue when loading dictionary and affix files you can check the dictionary.Affix.Warnings collection to see if there was a failure when parsing the encoding specified in the file, such as "Failed to get encoding: ISO-8859-15" or "Failed to parse line: SET ISO-8859-15". To enable these encodings, reference the System.Text.Encoding.CodePages package and then use Encoding.RegisterProvider(CodePagesEncodingProvider.Instance) to register them before loading files.

using System.Text;
using WeCantSpell.Hunspell;

class Program
{
    static Program() => Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

    static void Main(string[] args)
    {
        var dictionary = WordList.CreateFromFiles(@"encoding.dic");
        bool notOk = dictionary.Check("teh");
        var warnings = dictionary.Affix.Warnings;
    }
}
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on WeCantSpell.Hunspell:

Package Downloads
Dynamicweb.WeightedSearch

Weighted Search

VPKSoft.ScintillaSpellCheck

A spell checking library for the ScintillaNET.

fortune-lib

A .net implementation of a library to read unix BSD fortune-style files. This library will create and read dat files (it uses JSON rather than binary DAT format), discover and assign probabilities for the files with an associated DAT, Rotate the text of offensive fortune files (if preferred), and find random fortunes.

VPKSoft.ScintillaSpellCheck.SUO

A spell checking library for the ScintillaNET.

VPKSoft.SpellCheckUtility

A class library to allow to perform a spell check via whatever interface using the WeCantSpell.Hunspell library.

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on WeCantSpell.Hunspell:

Repository Stars
LayTec-AG/Plotly.Blazor
This library packages the well-known charting library plotly.js into a razor component that can be used in a Blazor project.
ONLYOFFICE/DocSpace
Platform for creating your own online office.
nightroman/FarNet
Far Manager framework for .NET modules and scripts in PowerShell, F#, JavaScript.
Version Downloads Last updated
4.0.0 13,352 5/15/2022
3.1.2 3,473 3/24/2022
3.1.1 2,498 2/21/2022
3.1.0 314 2/21/2022
3.0.1 450,648 9/6/2018
2.1.0 1,586 8/23/2018
2.0.1 2,750 7/23/2018
2.0.0 7,247 7/1/2017
1.1.0 919 6/20/2017
1.0.0 3,486 5/30/2017

# WeCantSpell.Hunspell Changelog
All notable changes to this project will be documented in this file.
## 4.0.0 - 2022-05
- Changes library target to net6.0 and netstandard2.0
- [Fixes suggest affix performance problems](https://github.com/aarondandy/WeCantSpell.Hunspell/issues/40)
- Adds `ReadOnlySpan<char>` overloads for Check and Suggest.
- General improvements to check and suggest performance
- CancellationToken support added to Check and Suggest calls
- Allows customization of timeouts and other options for Check and Suggest calls
## 3.1.2 - 2022-03-23
- [Fixes an index out of range bug](https://github.com/aarondandy/WeCantSpell.Hunspell/issues/71)
## 3.1.1 - 2022-02-21
- [Fixes a character classification bug](https://github.com/aarondandy/WeCantSpell.Hunspell/pull/54)
- Code simplification
## 3.1.0 - 2022-02-21
- Adds a target for net461
- Applies new changes and fixes to match origin
- Project and build has been modernized for newer .NET versions.
## 3.0.1 - 2018-09-05
- Adds a target for netstandard2.0
- References System.Memory
- Removes the net35 target
- A bunch of performance improvements
- Uses System.Memory instead of older custom solution
## 2.1.0 - 2018-08-22
- Allowed more usage of comments in ICONV and OCONV
- Performs BREAK check on 2nd word break
- Now uses SubStandard affix flag
- Adds phonetic entries to the replacement list
- Restricts compound replacement to using "middle" entries
- General suggesion improvements
- Reduce number of strange ngram suggestions
- Prefer suggestions for word pairs listed in dictionary
- Reduce compound word overgeneration
## 2.0.1 - 2018-07-22
- Applied upstream fixes for dotted `I` and Turkish
- Applied upstream fixes for forbidden words
- Applied upstream changes for Hungarian
## 2.0.0 - 2017-06-30
- Replaced .NET Framework 4.6.1 and 4.5.1 with a single 4.5 build (net45).
- Reduced nuget package size.
- Improved performance.
- Removed build for PCL Profile 259 (portable-net45+win8+wpa81+wp8).
- Removed build for .NET Standard 1.1 (netstandard1.1).
- Removed or made inaccessible members and types, including `WordEntrySet` and `WordEntry`.
## 1.1.0 - 2017-06-19
- New `WordEntryDetail` type to simplify storage.
- Reduced memory usage.
- Improved performance.
- Included fixes from source up to commit 77492a4.
- Project beautification 🐝.
- Able to read affix files with a flag mode of NUMBER.
## 1.0.0 - 2017-05-30
- Initial release of the project
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project tries its best to adhere to [Semantic Versioning](http://semver.org/).