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[]); } }
// 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(); }
public Link(Node parent, Node target, int score = 0) { this.Parent = parent; this.Target = target; this.Score = score; }
public int GetHashCode(Node key) { return key.Value.GetHashCode(); }
public bool Equals(Node n) { return this.Value.SequenceEqual(n.Value); }