Example #1
0
            private void LookupTolerantImpl(DictNode cur, MatchCandidate mc)
            {
                if (cur.Children == null)
                {
                    return;
                }

                //System.Diagnostics.Trace.WriteLine("--------------------------");
                //System.Diagnostics.Trace.WriteLine(string.Format("Processing children for word {0}", mc.Word));
                for (byte childPos = 0; childPos < cur.Children.Length; childPos++)
                {
                    DictNode child = cur.Children[childPos];
                    DoKeyMatching(child, 0, mc);
                }
                //System.Diagnostics.Trace.WriteLine(string.Format("Completed processing node children for word {0}", mc.Word));
                //System.Diagnostics.Trace.WriteLine("--------------------------");
            }
Example #2
0
            private void DoKeyMatching(DictNode node, byte nodeKeyPos, MatchCandidate mc)
            {
                byte currentKeyPos = mc.keyPos, startingNodeKeyPos = nodeKeyPos;

                while (nodeKeyPos < node.Key.Length && currentKeyPos < key.Length)
                {
                    // toleration
                    foreach (ToleranceFuncDelegate tf in toleranceFunctions)
                    {
                        byte  tmpKeyPos = mc.keyPos;
                        float tmpScore  = mc.Score;
                        byte? tret      = tf(key, ref tmpKeyPos, mc.Word, ref tmpScore, node.Key[nodeKeyPos]);
                        if (tret != null)
                        {
                            //System.Diagnostics.Trace.WriteLine(string.Format("{0} tolerated a char, attempting word {1}", tf.Method.Name, mc.Word + node._Key[nodeKeyPos]));

                            string consumedLetters = string.Empty;
                            if (((byte)tret > 0) && ((byte)tret <= node.Key.Length))
                            {
                                consumedLetters = new string(node.Key, nodeKeyPos, (byte)tret);
                            }
                            MatchCandidate nmc = new MatchCandidate(tmpKeyPos, mc.Word + consumedLetters, tmpScore);
                            if ((nodeKeyPos + (byte)tret) == node.Key.Length)
                            {
                                LookupTolerantImpl(node, nmc);
                            }
                            else
                            {
                                DoKeyMatching(node, (byte)(nodeKeyPos + (byte)tret), nmc);
                            }
                        }
                    }

                    // standard key matching
                    if (node.Key[nodeKeyPos] != key[currentKeyPos])
                    {
                        break;
                    }

                    //System.Diagnostics.Trace.WriteLine(string.Format("Matched char: {0}", key[currentKeyPos]));
                    currentKeyPos++;
                    nodeKeyPos++;
                }

                if (nodeKeyPos == node.Key.Length)
                {
                    if (currentKeyPos == key.Length)
                    {
                        //System.Diagnostics.Trace.WriteLine(string.Format("Consumed the whole key"));
                        if (node.Value != null)
                        {
                            resultSet.Add(
                                new LookupResult(mc.Word + new string(node.Key, startingNodeKeyPos, nodeKeyPos - startingNodeKeyPos),
                                                 node.Value, mc.Score)
                                );
                        }
                    }
                    else
                    {
                        MatchCandidate nmc = new MatchCandidate(currentKeyPos,
                                                                mc.Word + new string(node.Key, startingNodeKeyPos, nodeKeyPos - startingNodeKeyPos),
                                                                mc.Score);
                        LookupTolerantImpl(node, nmc);
                    }
                }
            }