IcuDictionaryBreakEngine Class

A dictionary break engine of ICU: it finds the words of a run of characters of a script that is written without spaces between words, with a word list of ICU (IcuWordDictionary).

public abstract class IcuDictionaryBreakEngine

Remarks

The engines are ports of the ones of ICU (icu4c/source/common/dictbe.cpp), which the word break iterator and the line break iterator of ICU use, and so the browsers and Intl.Segmenter of JavaScript:

  • IcuDictionaryBreakEngine.ChineseJapanese (CjkBreakEngine, without the phrase breaking): the segmentation of the run whose words have the smallest total cost. The run is normalized to NFKC; a character that does not start a word of one character is a word of the highest cost, and a run of katakana is a candidate word with a cost that depends on its length.
  • IcuDictionaryBreakEngine.Thai, IcuDictionaryBreakEngine.Lao, IcuDictionaryBreakEngine.Khmer and IcuDictionaryBreakEngine.Burmese (ThaiBreakEngine, LaoBreakEngine, KhmerBreakEngine and BurmeseBreakEngine): the longest words of the list that are followed by other words of the list, with up to three words of lookahead. The characters that start no word are attached to the word before them, up to a plausible word start; a break is never before a combining mark, and Thai attaches the elision and repetition characters to the word before them.

The engines do not find the runs: a caller applies the rules of its segmentation (the word or line breaking rules of Unicode, of ICU, or of CSS) and gives each run of the characters an engine handles (IcuDictionaryBreakEngine.Handles) to that engine. The text is read by code point, an unpaired surrogate being a code point, as ICU reads it. The engines are stateless and can be used by several threads at the same time; the word list of an engine is loaded on its first use.

Properties

NameDescription
BurmeseGets the engine of Burmese: the characters of the Myanmar script whose line breaking class is Complex_Context (SA).
ChineseJapaneseGets the engine of Chinese and Japanese: the characters of the Han, Hiragana and Katakana scripts, and U+30FC, U+FF70, U+FF9E and U+FF9F.
DictionaryKindGets the word list the engine uses.
KhmerGets the engine of Khmer: the characters of the Khmer script whose line breaking class is Complex_Context (SA).
LaoGets the engine of Lao: the characters of the Lao script whose line breaking class is Complex_Context (SA).
ThaiGets the engine of Thai: the characters of the Thai script whose line breaking class is Complex_Context (SA).

Gets the engine of Burmese: the characters of the Myanmar script whose line breaking class is Complex_Context (SA).

public static IcuDictionaryBreakEngine Burmese { get; }

Gets the engine of Chinese and Japanese: the characters of the Han, Hiragana and Katakana scripts, and U+30FC, U+FF70, U+FF9E and U+FF9F.

public static IcuDictionaryBreakEngine ChineseJapanese { get; }

Gets the word list the engine uses.

public IcuWordDictionaryKind DictionaryKind { get; }

Property value

IcuWordDictionaryKind

Gets the engine of Khmer: the characters of the Khmer script whose line breaking class is Complex_Context (SA).

public static IcuDictionaryBreakEngine Khmer { get; }

Gets the engine of Lao: the characters of the Lao script whose line breaking class is Complex_Context (SA).

public static IcuDictionaryBreakEngine Lao { get; }

Gets the engine of Thai: the characters of the Thai script whose line breaking class is Complex_Context (SA).

public static IcuDictionaryBreakEngine Thai { get; }

Methods

NameDescription
FindBreaks(ReadOnlySpan<char>, Span<int>)Finds the boundaries between the words of a run of characters the engine handles.
GetEngine(int)Gets the engine that handles a code point.
Handles(int)Determines whether the engine handles a code point (the set of characters of the engine in ICU).

FindBreaks(ReadOnlySpan<char>, Span<int>)

IcuDictionaryBreakEngine.cs

Finds the boundaries between the words of a run of characters the engine handles.

public int FindBreaks(ReadOnlySpan<char> text, Span<int> breakPositions)

Parameters

text ReadOnlySpan<char>
The run: characters the engine handles (IcuDictionaryBreakEngine.Handles). It is segmented as a whole: the result for a text that has other characters is not specified.
breakPositions Span<int>
The buffer that receives the positions, in increasing order. A position is the index of the UTF-16 code unit of text where a word starts, other than the start of the text. As many elements as the length of the text are always enough.

Returns

int The number of positions written; 0 when the run is one word (or too short to have two words).

Exceptions

ArgumentException
breakPositions is too small.

Remarks

The start and the end of the run are boundaries, and are never written. The engines of ICU are given the whole text and the range of the run; the engines of this package are given the run.

Gets the engine that handles a code point.

public static IcuDictionaryBreakEngine? GetEngine(int codePoint)

Parameters

codePoint int
The code point.

Returns

IcuDictionaryBreakEngine? The engine whose IcuDictionaryBreakEngine.Handles method returns true for the code point, or null when no engine handles it (the sets of characters of the engines do not overlap).

Handles(int)

Determines whether the engine handles a code point (the set of characters of the engine in ICU).

public abstract bool Handles(int codePoint)

Parameters

codePoint int
The code point. An unpaired surrogate is a code point.

Returns

bool true when the code point is one of the characters of the engine; false for a value that is not a code point.