WeCantSpell.Hunspell
5.0.0
See the version list below for details.
dotnet add package WeCantSpell.Hunspell --version 5.0.0
NuGet\Install-Package WeCantSpell.Hunspell -Version 5.0.0
<PackageReference Include="WeCantSpell.Hunspell" Version="5.0.0" />
paket add WeCantSpell.Hunspell --version 5.0.0
#r "nuget: WeCantSpell.Hunspell, 5.0.0"
// Install WeCantSpell.Hunspell as a Cake Addin #addin nuget:?package=WeCantSpell.Hunspell&version=5.0.0 // Install WeCantSpell.Hunspell as a Cake Tool #tool nuget:?package=WeCantSpell.Hunspell&version=5.0.0
WeCantSpell: Hunspell
A port of Hunspell for .NET.
Download and install with NuGet: WeCantSpell.Hunspell
Features
- Reads Hunspell DIC and AFF file formats
- Supports checking and suggesting words
- No unmanaged dependencies and mostly "safe" code
- Can be queried concurrently
- Confusing LGPL, GPL, MPL tri-license
- Compatible with .NET, .NET Core, and .NET Framework
- Uses .NET to handle most culture, encoding, and text concerns.
License
"It's complicated"
Read the license: LICENSE
This library was ported from the original Hunspell source and as a result is licensed under their 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");
Performance
"Good enough"
This port will likely perform slower relative to the original binaries and NHunspell but it should be acceptable. It is worth considering that while NHunspell is faster, it hasn't been updated in a long while and may be missing important fixes and changes.
Benchmark | .NET 8 | .NET 4.8 | NHunspell |
---|---|---|---|
Check | ðĒ 7,376 Ξs | ð 19,496 Ξs | ð 6,324 Ξs |
Suggest | ð 367 ms | ðĒ 758 ms | ð 1,904 ms |
Note: Measurements taken on an AMD 5800H.
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;
}
}
Development
This port wouldn't be feasible for me to produce or maintain without the live testing functionality in NCrunch. Being able to get actual near instant feedback from tests saved me from so many typos, bugs due to porting, and even bugs from upstream. I was very relieved to see that NCrunch was survived the release of "Live Unit Testing" in Visual Studio. If you want to try live testing but have been dissatisfied with the native implementation in Visual Studio, please give NCrunch a try. Without NCrunch I will likely stop maintaining this port, it really is that critical to my workflow here.
I initially started this port so I could revive my old C# spell check tool but I ended up so distracted and burnt out from this port I never got around to writing the Roslyn analyzer. Eventually, Visual Studio got it's own spell checker and vscode has a plethora of them too, so I doubt I will be developing such an analyzer in the future. Some others have taken up that task, so give them a look:
- https://github.com/rpsft/WeCantSpell.Roslyn
- https://github.com/BrightLight/YouShouldSpellcheck.Analyzer
For details on contributing, see the contributing document. Check the hunspell-origin submodule to see how up to date this library is compared with source .
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Collections.Immutable (>= 6.0.0)
- System.Memory (>= 4.5.4)
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (12)
Showing the top 5 NuGet packages that depend on WeCantSpell.Hunspell:
Package | Downloads |
---|---|
Dynamicweb.WeightedSearch
Weighted Search |
|
HIC.RDMP.Plugin.UI
UI package for plugin development |
|
VPKSoft.ScintillaSpellCheck
A spell checking library for the ScintillaNET. |
|
LisaCore
CSharp dynamic runtime code execution |
|
Skybrud.TextAnalysis
Hunspell text analysis package for .NET. |
GitHub repositories (2)
Showing the top 2 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.
|
|
nightroman/FarNet
Far Manager framework for .NET modules and scripts in PowerShell, F#, JavaScript.
|
Version | Downloads | Last updated |
---|---|---|
5.2.1 | 436 | 11/13/2024 |
5.2.0 | 117 | 11/12/2024 |
5.1.0 | 4,177 | 10/23/2024 |
5.0.1 | 150 | 10/23/2024 |
5.0.0 | 246,860 | 12/3/2023 |
4.1.0 | 8,233 | 11/20/2023 |
4.0.0 | 270,162 | 5/15/2022 |
3.1.2 | 128,235 | 3/24/2022 |
3.1.1 | 6,222 | 2/21/2022 |
3.1.0 | 1,950 | 2/21/2022 |
3.0.1 | 847,550 | 9/6/2018 |
2.1.0 | 3,884 | 8/23/2018 |
2.0.1 | 5,156 | 7/23/2018 |
2.0.0 | 10,594 | 7/1/2017 |
1.1.0 | 1,723 | 6/20/2017 |
1.0.0 | 5,852 | 5/30/2017 |
# WeCantSpell.Hunspell Changelog
All notable changes to this project will be documented in this file.
## 5.0.0 - 2023-12
- Removes usages of `Environment.TickCount`: [PR #83](https://github.com/aarondandy/WeCantSpell.Hunspell/pull/83)
- Adds `net8.0` as a new target
- (breaking) Improves many collection types
- (breaking) Adds more exceptions for exceptional situations
- (breaking) Moves ArrayBuilder to internal
- Updates to match unreleased changes and fixes from Hunspell
- Assorted performance related changes
- Restricts unsafe code to netstandard2.0 builds
## 4.1.0 - 2023-11
- Updates the library to match changes in [Hunspell 1.7.2](https://github.com/hunspell/hunspell/releases/tag/v1.7.2)
## 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/).