LexiDiff.Snowball
0.4.0
dotnet add package LexiDiff.Snowball --version 0.4.0
NuGet\Install-Package LexiDiff.Snowball -Version 0.4.0
<PackageReference Include="LexiDiff.Snowball" Version="0.4.0" />
<PackageVersion Include="LexiDiff.Snowball" Version="0.4.0" />
<PackageReference Include="LexiDiff.Snowball" />
paket add LexiDiff.Snowball --version 0.4.0
#r "nuget: LexiDiff.Snowball, 0.4.0"
#:package LexiDiff.Snowball@0.4.0
#addin nuget:?package=LexiDiff.Snowball&version=0.4.0
#tool nuget:?package=LexiDiff.Snowball&version=0.4.0
LexiDiff
Token-aware text diffs that favour readability over compactness.
Deletions are shown with strikethrough; additions are shown in bold.
| Pure Levenshtein | LexiDiff |
|---|---|
| Alice was |
Alice was |
LexiDiff compares words and their stems, with optional sentence or paragraph granularity.
- Language-aware word segmentation with ICU4N and stemming with Snowball
- Edits aligned to whole words, stems, and suffixes
- Sentence and paragraph comparison
- Equal, insert, and delete spans, with unified diff and inline HTML output
Install
Compatibility: Targets .NET Standard 2.0; consumable by .NET Framework 4.8 and .NET 8, 9, and 10.
dotnet add package LexiDiff
Quick Start
using LexiDiff;
LexiDiffResult result = Lexi.Compare(
"Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do.",
"Alice was getting very tired to sit by her sister on the bank, with nothing to do.");
Console.WriteLine(result.ToInlineHtml());
LexiDiffResult.Spans contains equal, insert, and delete spans. ApplyTo(original) applies the changes to the original text. ToInlineHtml() HTML-encodes the text and wraps changes in <del> and <ins> tags.
The example highlights these changes:
Alice was
beginning togetting very tiredofto sittingby her sister on the bank,and of havingwith nothing to do.
The shared stem in getting stays unchanged. Replacing of with to produces ofto, keeping both words intact.
Granularity Promotion (Sentence / Paragraph)
Use sentence or paragraph granularity to show each changed sentence or paragraph as a whole replacement.
using System.Globalization;
using LexiDiff;
var a = "A sentence. Next entry stays.";
var b = "A new sentence. Next entry stays.";
// Compare whole sentences using English sentence boundaries
var sentenceDiff = Lexi.Compare(
a, b,
new LexiOptions {
PromoteTo = LexGranularity.Sentence,
SentenceCulture = CultureInfo.GetCultureInfo("en-US")
});
Console.WriteLine(sentenceDiff.ToUnifiedDiff("a.txt", "b.txt"));
// Paragraph-level promotion
var paraDiff = Lexi.CompareParagraphs(a, b);
Sentence boundaries use ICU4N with the specified culture. Paragraphs split at each newline; a blank line forms a separate paragraph.
Word segmentation and stemming default to English (en-US). To use another language, supply a culture-selection callback through LexiOptions.DetectLang. Set SentenceCulture for sentence boundaries; it defaults to the invariant culture.
Why token-aware?
LexiDiff uses ICU4N to identify words and Snowball to find stems. A word such as cats can split into cat + s, allowing suffix changes to appear independently. Edits preserve these token boundaries.
Original spelling, punctuation, and whitespace are preserved. Use ReconstructA() and ReconstructB() to recover the input texts.
Known Limitations
- Unified diffs show changes by line. Use
ToInlineHtml()for word and suffix highlighting. - Snowball’s stemming is heuristic. Words without a usable stem split remain whole.
- Sentence boundaries around abbreviations (
Me.,Dr.,art.) may require additional tailoring for specialized text.
License
LexiDiff is licensed under Apache-2.0.
Dependency licenses:
- Snowball: BSD-3-Clause
- ICU4N: license and third-party notices
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on LexiDiff.Snowball:
| Package | Downloads |
|---|---|
|
LexiDiff
Token-aware diff engine with Snowball stemming, ICU tokenization, and unified diff rendering. |
GitHub repositories
This package is not used by any popular GitHub repositories.