private static void ExecuteTest(Grammar g, string input) { var earley1 = new EarleyParser(g); var earley2 = new EarleyParser2(g); var sentence = Sentence.FromWords(input); var p1 = earley1.ParseGetProbability(sentence); var p2 = earley2.ParseGetProbability(sentence); Helpers.AssertNear(p1, p2); }
private static void BnfParse(Sentence sentence) { var g = Bnf.Grammar(); //var h = g.ToCNF(); // too much memory var earley = new EarleyParser(g); // var cyk = new CykParser(h); var earley2 = new EarleyParser2(g); // var p1 = cyk.ParseGetProbability(sentence); var p2 = earley.ParseGetProbability(sentence); var p3 = earley2.ParseGetProbability(sentence); // Helpers.AssertNear(p1, p2); Helpers.AssertNear(p2, p3); Assert.IsTrue(p2 > 0.0); }
private static void ExecuteTest(Grammar g, List <Sentence> sentences) { CNFGrammar h = g.ToCNF(); var earley = new EarleyParser(g); var cyk = new CykParser(h); var earley2 = new EarleyParser2(g); foreach (var sentence in sentences) { var p1 = cyk.ParseGetProbability(sentence); var p2 = earley.ParseGetProbability(sentence); var p3 = earley2.ParseGetProbability(sentence); Helpers.AssertNear(p1, p2); Helpers.AssertNear(p2, p3); } }
private static void DebugGrammar() { BaseGrammar g = new Grammar(new List <Production> { CFGParser.Production("<S> → ε"), }, Nonterminal.Of("S")); var sentence = Sentence.FromWords("1 + 1 + 1"); var grammar = AdditionGrammar(argList => string.Format("({0} + {1})", argList[0].Payload, argList[2].Payload)); g = grammar; var earley = new EarleyParser(g); var earley2 = new EarleyParser2(g); //DotRunner.Run(earley.ParseGetForest(sentence).GetRawDot(), "testEarleyOld"); //DotRunner.Run(earley2.ParseGetForest(sentence).GetRawDot(), "testEarleyNew"); DotRunner.Run(DotBuilder.GetRawDot(earley.ParseGetForest(sentence)), "testEarleyOld"); DotRunner.Run(DotBuilder.GetRawDot(earley2.ParseGetForest(sentence)), "testEarleyNew"); // DotRunner.Run(DotBuilder.GetFlattenedDot(earley2.ParseGetForest(sentence)), "testEarleyFlat"); // var prob0 = earley.ParseGetProbability(sentence); var prob = earley2.ParseGetProbability(sentence); }