IcuWordDictionary Class

A word list of ICU (icu4c/source/data/brkitr/dictionaries/*dict.txt), embedded in this package: the words of Chinese and Japanese, Thai, Lao, Khmer or Burmese, which IcuDictionaryBreakEngine uses to find the words of a text.

public sealed class IcuWordDictionary

Remarks

A list is decompressed and loaded on the first call of IcuWordDictionary.Get for it, so an application only pays for the lists of the scripts of its texts. In memory, a list takes from about 0.5 MB (Thai) to 3 MB (Chinese and Japanese). An instance is immutable and can be used by several threads at the same time.

The lists are the ones of the release of ICU given by IcuWordDictionary.IcuVersion. They are distributed under the Unicode License v3, and the lists of Chinese and Japanese, Lao and Burmese have additional notices: see the THIRD-PARTY-NOTICES.md file of the package.

Properties

NameDescription
IcuVersionGets the version of ICU whose word lists are embedded in this package.
KindGets the word list.
WordCountGets the number of words.

Gets the version of ICU whose word lists are embedded in this package.

public static string IcuVersion { get; }

Property value

string

Gets the word list.

public IcuWordDictionaryKind Kind { get; }

Property value

IcuWordDictionaryKind

Gets the number of words.

public int WordCount { get; }

Property value

int

Methods

NameDescription
Contains(ReadOnlySpan<char>)Determines whether a word is in the list.
CreateLineBreakDictionary()Creates a LineBreakDictionary with the words of the lists of Thai, Lao, Khmer and Burmese, the scripts whose characters have the line breaking class Complex_Context (SA).
Get(IcuWordDictionaryKind)Gets a word list, loading it on first use.
TryGetValue(ReadOnlySpan<char>, int)Gets whether a word is in the list, and its value.

Contains(ReadOnlySpan<char>)

IcuWordDictionary.cs

Determines whether a word is in the list.

public bool Contains(ReadOnlySpan<char> word)

Parameters

word ReadOnlySpan<char>
The word. The comparison is ordinal.

Returns

bool true when the word is in the list.

CreateLineBreakDictionary()

IcuWordDictionary.cs

Creates a LineBreakDictionary with the words of the lists of Thai, Lao, Khmer and Burmese, the scripts whose characters have the line breaking class Complex_Context (SA).

public static LineBreakDictionary CreateLineBreakDictionary()

Returns

LineBreakDictionary A new dictionary. Creating it takes a few hundred milliseconds: keep it and share it.

Remarks

LineBreakDictionary segments a text with its own rule (the fewest characters outside of the words of the list, then the fewest words), which is not the heuristic of the break engines of ICU (IcuDictionaryBreakEngine): the breaks are close to the ones of ICU, but not always the same.

Get(IcuWordDictionaryKind)

IcuWordDictionary.cs

Gets a word list, loading it on first use.

Parameters

kind IcuWordDictionaryKind
The word list.

Returns

IcuWordDictionary The word list. The same instance is returned for each call.

Exceptions

ArgumentOutOfRangeException
kind is not a value of IcuWordDictionaryKind.

TryGetValue(ReadOnlySpan<char>, int)

IcuWordDictionary.cs

Gets whether a word is in the list, and its value.

public bool TryGetValue(ReadOnlySpan<char> word, out int value)

Parameters

word ReadOnlySpan<char>
The word. The comparison is ordinal.
value int
The value of the word: its cost for the list of Chinese and Japanese (the lower, the more frequent), 0 for the other lists.

Returns

bool true when the word is in the list.