WoofWare.LiangHyphenation 0.1.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package WoofWare.LiangHyphenation --version 0.1.3
                    
NuGet\Install-Package WoofWare.LiangHyphenation -Version 0.1.3
                    
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.
<PackageReference Include="WoofWare.LiangHyphenation" Version="0.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WoofWare.LiangHyphenation" Version="0.1.3" />
                    
Directory.Packages.props
<PackageReference Include="WoofWare.LiangHyphenation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WoofWare.LiangHyphenation --version 0.1.3
                    
#r "nuget: WoofWare.LiangHyphenation, 0.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WoofWare.LiangHyphenation@0.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WoofWare.LiangHyphenation&version=0.1.3
                    
Install as a Cake Addin
#tool nuget:?package=WoofWare.LiangHyphenation&version=0.1.3
                    
Install as a Cake Tool

WoofWare.LiangHyphenation

NuGet version GitHub Actions status License file

<picture> <source media="(prefers-color-scheme: dark)" srcset="logos/dark.svg"> <source media="(prefers-color-scheme: light)" srcset="logos/light.svg"> <img alt="Project logo: minimalistic black-and-white face of a cartoon Shiba Inu, composed almost entirely of horizontal lines." src="logos/light.svg" width="300"> </picture>

The Liang hyphenation algorithm.

Structure

The library provides two namespaces: WoofWare.LiangHyphenation, which contains functions for performing hyphenation, and WoofWare.LiangHyphenation.Construction, which contains functions for manipulating and creating the efficient data structures holding hyphenation data.

As a consumer, using hyphenation out of the box, you should simply call methods from WoofWare.LiangHyphenation's Hyphenation module.

Usage

open WoofWare.LiangHyphenation

// Load the hyphenation data for your language (cache this yourself if desired).
let trie : PackedTrie = LanguageData.load KnownLanguage.EnGb

// Get the priority array for a word.
let priorities : byte[] = Hyphenation.hyphenate trie "hyphenation"
// priorities = [| 2; 3; 0; 4; 4; 1; 1; 2; 4; 2 |]

// Or get just the indices where hyphenation is allowed.
let points : int[] = Hyphenation.getHyphenationPoints trie "hyphenation"
// points = [| 1; 5; 6 |]
// This corresponds to: hy-phen-a-tion

Algorithm overview

The Liang algorithm works by overlaying a dictionary of patterns over each word, each pattern identifying candidate word breaks. A pattern defines some collection of candidate breaks within a string, and a priority for each candidate (the priority can also specify "do not break here" with some strength). Most of the patterns in the dictionary won't match any given word, but it's a big dictionary, so most words are covered by multiple patterns.

The convention is that odd-valued priorities indicate "break here", and even-valued priorities indicate "don't break here". Higher-magnitude priorities win over lower-magnitude ones.

Example patterns:

  • ain5ders: consider breaking ain-ders
  • a4ju: consider not breaking a-ju

In the en-gb dictionary, for example, two of the patterns are aleg4 and leg1a. (That is, "don't break after aleg, priority 4", and "do break leg-a, priority 1".) Imagine we had only those two rules in the dictionary; then the dictionary would choose not to break paralegal, because the priority 4 on "don't break after aleg" beats the priority 1 on "do break leg-a".

The hyphenate function returns an array of priority values, one for each inter-letter position in the word (so it returns an array of length string.Length - 1).

For example, in "hyphenation":

Position Letters Priority Hyphenate?
0 h-y 2 No (even)
1 y-p 3 Yes (odd)
2 p-h 0 No (even)
3 h-e 4 No (even)
4 e-n 4 No (even)
5 n-a 1 Yes (odd)
6 a-t 1 Yes (odd)
7 t-i 2 No (even)
8 i-o 4 No (even)
9 o-n 2 No (even)

The odd positions (1, 5, 6) give: hy-phen-a-tion.

Licence

The patterns defining hyphenation patterns are derived from the hyph-utf8 package, and are in WoofWare.LiangHyphenation.Test/Patterns. The text files which we consume are a bit unclear about the licenses which apply to them; I've taken them to be MIT licensed just as are the .tex files defining the same patterns. Copies can be found in the LICENSES folder.

WoofWare.LiangHyphenation is licenced to you under the MIT licence; see LICENSE.md.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.9 134 10/25/2026
0.1.8 1,037 8/25/2026
0.1.7 154 6/21/2026
0.1.6 135 6/21/2026
0.1.5 137 6/20/2026
0.1.4 232 12/24/2025
0.1.3 456 12/19/2025