public string ProcessParseTree(ParserTree tree) { Console.WriteLine(tree); // only continue if the tree is a valid sentence if (!tree.IsValid()) { return NeutralResponse; } string response = string.Empty; bool foundAResponse = false; for (int i = 0; i < _processors.Count && !foundAResponse; i++) { if (_processors[i].TryProcess(tree, out response)) { foundAResponse = true; } } if (!foundAResponse) { response = NeutralResponse; } return response; ////var t = tree.HeadNode.ToString(); ////Console.WriteLine(t); //return "Yay a good one"; }
public bool TryProcess(ParserTree tree, out string response) { response = string.Empty; if ((tree.HeadNode as VariableNode).Children.First().Type == "LIKESTATEMENT") { string previousNonTerminal = string.Empty; StringBuilder sb = new StringBuilder(); sb.Append("Do "); foreach (var f in tree.HeadNode) { if (f.Type == "TERMINAL") { if (previousNonTerminal == "PRONOUN") { sb.Append($"{ResponseUtils.PronounReverse(f.ToString())} "); } else { sb.Append($"{f} "); } } else { previousNonTerminal = f.Type; } //Debug.WriteLine($"f: {f.Type} {f.ToString()}"); } sb.Append("often?"); response = sb.ToString(); return true; //string a = $"Do {tree.ToString()} often?"; //a = a.Replace("I ", "you "); //a = a.Replace("i ", "you "); //Console.WriteLine(a); } return false; }
public string ConvertLikeTree(ParserTree tree) { return ""; }
public bool TryProcess(ParserTree tree, out string response) { response = string.Empty; if ((tree.HeadNode as VariableNode).Children.First().Type == "DISTANCESTATEMENT") { string distance = null; ParserNode city1 = null; ParserNode city2 = null; foreach (var f in tree.HeadNode) { if (f.Type == "NUMBER") { if (distance == null) { distance = f.ToString(); } else { response = "Distance was already set once. I dont know what to do."; return true; } } if (f.Type == "CITY") { if (city1 == null) { city1 = f; } else { if (city2 == null) { city2 = f; } else { response = "Sorry i dont know what to do with 3 cities."; return true; } } } //Debug.WriteLine($"f: {f.Type} {f.ToString()}"); } var node1 = GetCityNode(city1.ToString()); var node2 = GetCityNode(city2.ToString()); node1.AddConnection(node2, double.Parse(distance)); _roadCount++; response = $"Thanks for the information, I know about {_roadCount} roads. Tell me about yourself."; return true; } if ((tree.HeadNode as VariableNode).Children.First().Type == "DISTANCEQUESTION") { ParserNode city1 = null; ParserNode city2 = null; foreach (var f in tree.HeadNode) { if (f.Type == "CITY") { if (city1 == null) { city1 = f; } else { if (city2 == null) { city2 = f; } else { response = "Sorry i dont know what to do with 3 cities."; return true; } } } //Debug.WriteLine($"f: {f.Type} {f.ToString()}"); } response = $"The best route between {city1} and {city2} is TBD"; return true; } return false; }