WordDictionary

WordDictionary generic description

Namespace: Nlp4Net.NlpLib Assembly: NlpLib.dll

[Serializable]
public class WordDictionary<TValue> : IUserData, IDictionary<string,TValue>, IXmlSerializable


Unique features.

WordDictionary allows you to create large dictionaries.

Serialization.

You can serialize WordDictionary into binary or XML-Stream. Load() and Save() methods are shortcuts to serialize directly into a file.

Thread safety and performance.

WordDictionary is designed for multithreaded applications.

Application can get the best performance if it loads or fills in WordDictionary first and then performs only read operaions. Do not put any lock on read operations for better performance.

You have to take care about synchrnonization if you do write operations like Add(), Remove(), Clear()
WordDictionary is neither thread safe for writing, nor it implements any locks internally.




Constructors Description
Nlp4Net method WordDictionary() creates an empty WordDictionary
Nlp4Net method WordDictionary(INormalizer normalizer) creates WordDictionary with a specified normalizer

Before WordDictionary processes a string in methods like Add(), AddRange(), Remove(), ContainsKey() it converts it into a normalized form by calling INormalizer.Normalize()
By providing normalizer you can control normalization behavior. For example converting string into upper case will make dictionary case insensitive.
If you pass null normalizer, strings are processed as is without modification.

You can use StringNormalizer.ToLowerInvariant, StringNormalizer.ToLowerInvariantTrim or your own implementation.
StringNormalizer.ToLowerInvariant converts string to lower case.
StringNormalizer.ToLowerInvariantTrim converts string to lower case and trims spaces.



Methods Description
Nlp4Net method void Add(KeyValuePair<string, TValue> item) Adds an item to the WordDictionary in a form of KeyValuePair
Nlp4Net method void Add(string key, TValue value) Adds an item to the WordDictionary in a form of Key and Value
Nlp4Net method void Clear() Removes all words from WordDictionary
Nlp4Net method bool Contains(KeyValuePair<string, TValue> item) Returns true if both word and value are found in dictionary.
word is normalized first and then searched in dictionary.
Nlp4Net method bool ContainsKey(string word) Returns true if word is in dictionary.
word is normalized first and then searched in dictionary.
Nlp4Net method void CopyTo(KeyValuePair<string, TValue>[] array, int arrayIndex) Copies whole dictionary into an array.
Nlp4Net method Nlp4Net method static WordDictionary Create(string fileName) Reads WordDictionary from a file.
If fileName has .xml extension, uses XML format, otherwise uses binary format.
Nlp4Net method char[] GetChars() Returns sorted array of ordinary chars used in dictionary.
It may be cosidered as an alphabet with the note that surrogates are not honored and are broken into ordinary chars.
Nlp4Net method IEnumerator<KeyValuePair<string, TValue>> GetEnumerator() You can enumerate dictionary using foreach statement.
Nlp4Net method XmlSchema GetSchema() Always returns null.
Nlp4Net method void ReadXml(XmlReader reader) Loads WordDictionary from XML stream.
Nlp4Net method bool Remove(KeyValuePair<string, TValue> item) Returns true if KeyValuePair is removed from WordDictionary.
KeyValuePair.Key is normalized first and then the normalized form is searched.
Nlp4Net method bool Remove(string word) Returns true if word is found and removed from WordDictionary.
word is normalized first and then the normalized form is searched.
Nlp4Net method void Save(string fileName) Saves WordDictionary into a file.
If fileName has .xml extension, uses XML format, otherwise uses binary format.
Nlp4Net method bool TryGetValue(string key, out TValue value) Returns true if key is found, otherwise false.
key is normalized first and then the normalized form is searched.
Nlp4Net method void WriteXml(XmlWriter writer) Serializes WordDictionary into XML-Stream.



Properties Description
Nlp4Net property int Count Number of words in a WordDictionary
Nlp4Net property bool IsReadOnly Always returns false.
Nlp4Net property TValue this[string key] Returns value associated with key
key is normalized first and then the normalized form is searched.
Nlp4Net property ICollection<string> Keys All words in dictionary in normalized form.
Nlp4Net property int LCID Allows you to set language.
Nlp4Net propertyINormalizer Normalizer Performs word normalization before it is processed.
Proprety can be null.
You cannot change Normalizer if WordDictionary is not empty.
Nlp4Net propertyobject IUserData.UserData Your arbitrary object
Nlp4Net property ICollection<TValue> Values All values in dictionary.