public void AddWordTagPair(string word, string tag) { Utils.ThrowException(word == null ? new ArgumentNullException("word") : null); Utils.ThrowException(tag == null ? new ArgumentNullException("tag") : null); word = "#" + word; SuffixTrieNode current = mRoot; int i = word.Length - 1; while (i >= 0 && current.mChildren.ContainsKey(word[i])) { current = current.mChildren[word[i]]; i--; } while (i >= 0) { current.mChildren.Add(word[i], current = new SuffixTrieNode(word[i])); i--; } if (current.mTags == null) { current.mTags = new Set <string>(new string[] { tag }); } else { current.mTags.Add(tag); } }
public Set <string> .ReadOnly GetTags(string word) { Utils.ThrowException(word == null ? new ArgumentNullException("word") : null); word = "#" + word; SuffixTrieNode current = mRoot; int i = word.Length - 1; while (i >= 0 && current.mChildren.ContainsKey(word[i])) { current = current.mChildren[word[i]]; i--; } return(current.mTags); }
private static void ToString(SuffixTrieNode node, StringBuilder strBuilder, string offset) { strBuilder.Append(offset); strBuilder.Append(node.mLetter.ToString()); if (node.mTags != null) { strBuilder.Append(string.Format(" {0}", node.mTags)); } strBuilder.AppendLine(); foreach (SuffixTrieNode childNode in node.mChildren.Values) { ToString(childNode, strBuilder, offset + " "); } }
private void PropagateTags(SuffixTrieNode node) { if (node.mChildren.Count == 1) { foreach (SuffixTrieNode child in node.mChildren.Values) { PropagateTags(child); node.mTags = child.mTags; } } else if (node.mChildren.Count > 1) { Set <string> tags = new Set <string>(); foreach (SuffixTrieNode child in node.mChildren.Values) { PropagateTags(child); tags.AddRange(child.mTags); } node.mTags = tags; } }
public void Load(BinarySerializer reader) { mRoot = new SuffixTrieNode(reader); // throws ArgumentNullException, serialization-related exceptions }