Esempio n. 1
0
            public bool FindWord(string word)
            {
                int dist = Levenshtein.Compute(word, this.nodeWord);

                // The word's already in the dictionary!
                if (dist == 0)
                {
                    return(true);
                }

                BKNode child;

                if (children.TryGetValue(dist, out child))
                {
                    // We already have another node of equal distance, so add this word to that node's subtree
                    return(child.FindWord(word));
                }

                return(false);
            }
Esempio n. 2
0
            public IEnumerable <string> FindSuggestions(string word, int tolerance)
            {
                var suggestions = new List <string>();

                int dist = Levenshtein.Compute(word, nodeWord);

                if (dist < tolerance)
                {
                    suggestions.Add(nodeWord);
                }

                foreach (int key in children.Keys)
                {
                    if (key >= dist - tolerance && key <= dist + tolerance)
                    {
                        suggestions.AddRange(children[key].FindSuggestions(word, tolerance));
                    }
                }

                return(suggestions);
            }
Esempio n. 3
0
            public void AddNode(string word)
            {
                var dist = Levenshtein.Compute(word, nodeWord);

                // The word is already in dictionary
                if (dist == 0)
                {
                    return;
                }

                BKNode child;

                if (children.TryGetValue(dist, out child))
                {
                    // We already have another node of equal distance, so add this word to that node's subtree
                    child.AddNode(word);
                }
                else
                {
                    // We don't have a child of that distance, so a new child is added
                    children.Add(dist, new BKNode(word));
                }
            }