public static InferenceInput ParseInferenceInput(string filePath) { var inferenceInput = new InferenceInput(); var fileLines = File.ReadAllLines(filePath); int tellIndex = 0; int askIndex = 0; for (int i = 0; i < fileLines.Length; ++i) { if (fileLines[i] == "TELL") { tellIndex = i; } else if (fileLines[i] == "ASK") { askIndex = i; } } string[] tellLines = new string[askIndex - tellIndex - 1]; for (int i = 0; i < tellLines.Length; ++i) { tellLines[i] = fileLines[tellIndex + 1 + i]; } var clauseStrings = new List <string>(); foreach (var line in tellLines) { var formattedLines = new List <string>(); foreach (var formattedLine in line.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { formattedLines.Add(formattedLine.Replace(" ", "")); } clauseStrings.AddRange(formattedLines); } inferenceInput.knowledgeClauses = clauseStrings; inferenceInput.queryClause = fileLines[askIndex + 1]; return(inferenceInput); }
static void Main(string[] args) { string methodName = args[0]; string filename = args[1]; InferenceInput input = Parser.ParseInferenceInput(filename); var kb = new KnowledgeBase(); foreach (var clause in input.knowledgeClauses) { kb.Tell(clause); } kb.Ask(input.queryClause, methodName); Console.ReadLine(); }