private static void SimpleMovementTest() { var voc = Vocabulary.GetVocabularyFromFile(@"Vocabulary.json"); var grammar = new Grammar(voc); Program.AddTypesToGrammar(grammar); grammar.AddProjectionTypeToTypeDictionary("CP", "V"); // no overt POS here, head of IP is V. grammar.AddProjectionTypeToTypeDictionary("IP", "V"); // no overt POS here, head of IP is V. grammar.AddRule(new Rule(1, "START", new[] {"CP"}, 0, 0)); grammar.AddRule(new Rule(1, "CP", new[] {"IP"}, 0, 0)); grammar.AddRule(new Rule(1, "IP", new[] {"NP", "VP"}, 1, 1)); grammar.AddRule(new Rule(1, "VP", new[] {"V1", "NP"}, 0, 1)); grammar.AddRule(new Rule(1, "VP", new[] {"V2", "PP"}, 0, 1)); grammar.AddRule(new Rule(1, "PP", new[] {"P", "NP"}, 0, 1)); grammar.AddRule(new Rule(1, "NP", new[] {"D", "N"}, 1, 0)); grammar.AddNonTerminalToLandingSites("CP"); grammar.AddMoveable("NP"); grammar.AddMoveable("PP"); grammar.GenerateDerivedRulesFromSchema(); var parser = new Parser(grammar); var n = parser.ParseSentence("Who the bells toll for"); n.Print(); n = parser.ParseSentence("Who a man arrived from"); n.Print(); n = parser.ParseSentence("from Who a man arrived"); n.Print(); n = parser.ParseSentence("John David kissed"); n.Print(); }
private static void TestAmbiguityGrammar() { var voc = Vocabulary.GetVocabularyFromFile(@"Vocabulary.json"); var grammar = new Grammar(voc); Program.AddTypesToGrammar(grammar); grammar.AddRule(new Rule(0, "START", new[] {"VP"}, 0, 0)); grammar.AddRule(new Rule(1, "VP", new[] {"V1", "NP"}, 0, 1)); grammar.AddRule(new Rule(1, "VP", new[] {"VP", "NP"}, 0, 0)); grammar.AddRule(new Rule(0, "NP", new[] {"NP", "NP"}, 0, 0)); var parser = new Parser(grammar, true); var n = parser.ParseSentence("kissed John David"); n.Print(); }
private Tuple<Node, int>[] ParseAllSentences(Grammar currentHypothesis) { var allParses = new Tuple<Node, int>[sentencesWithCounts.Count]; try { Parallel.ForEach(sentencesWithCounts, (sentenceItem, state, i) => { var parser = new Parser(currentHypothesis); var n = parser.ParseSentence(sentenceItem.Key); allParses[i] = Tuple.Create(n, sentenceItem.Value); }); return allParses; } catch (Exception) { return null; //parsing failed. } }
private static void TestMovement2() { var voc = Vocabulary.GetVocabularyFromFile(@"Vocabulary.json"); var grammar = new Grammar(voc); Program.AddTypesToGrammar(grammar); grammar.AddProjectionTypeToTypeDictionary("CP", "V"); // no overt POS here, head of IP is V. grammar.AddProjectionTypeToTypeDictionary("IP", "V"); // no overt POS here, head of IP is V. grammar.AddRule(new Rule(1, "START", new[] {"VP", "VP"}, 1, 1)); grammar.AddRule(new Rule(1, "VP", new[] {"VP", "PP"}, 0, 1)); grammar.AddRule(new Rule(1, "VP", new[] {"NP", "V1"}, 1, 0)); grammar.AddRule(new Rule(1, "PP", new[] {"V2", "P"}, 1, 0)); grammar.AddRule(new Rule(1, "NP", new[] {"D", "N"}, 1, 0)); var parser = new Parser(grammar, true); var n = parser.ParseSentence("the man arrived to Mary"); //supposed to fail in parsing!! n.Print(); }