Example #1
0
        public void AddText(String s)
        {
            messages.Add(s);

            List<String> tokens = new List<String>(s.Split(' '));

            if (StringOrDefault(tokens.ElementAt(0)) == "")
                return; // abort if it doesn't have anything

            Node lastNode = null;
            String[] currentWord = new String[ORDER];
            for(int i = 0; i < tokens.Count - (ORDER - 1); i++)
            {
                for (int j = 0; j < ORDER; j++)
                    currentWord[j] = StringOrDefault(tokens.ElementAt(i + j));

                var currentNode = nodes.ContainsKey(currentWord) ? nodes[currentWord] : null;
                if (currentNode == null)
                {
                    currentNode = new Node(currentWord);
                    nodes.Add(currentWord, currentNode);
                }

                if (lastNode == null)
                    starts.Add(currentNode);
                else
                    AddPair(lastNode, currentNode);

                lastNode = new Node(currentNode.Value.Clone() as String[]);
            }
        }
Example #2
0
 // point foo to bar
 public void AddPair(Node fooNode, Node barNode, int score = 0)
 {
     Link link = fooNode.Links.ContainsKey(barNode.Value) ? fooNode.Links[barNode.Value] : null;
     if (link == null)
     {
         link = new Link(fooNode, barNode);
         fooNode.Links.Add(barNode.Value, link);
     }
     link.Hit();
 }
Example #3
0
 public Link(Node parent, Node target, int score = 0)
 {
     this.Parent = parent;
     this.Target = target;
     this.Score = score;
 }
Example #4
0
 public int GetHashCode(Node key)
 {
     return key.Value.GetHashCode();
 }
Example #5
0
 public bool Equals(Node n)
 {
     return this.Value.SequenceEqual(n.Value);
 }