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(); }
public static void CreateMovementGrammar(Grammar grammar) { AddTypesToGrammar(grammar); grammar.AddProjectionTypeToTypeDictionary("IP", "V"); // no overt POS here, head of IP is V. grammar.AddRule(new Rule(1, "START", new[] {"IP"}, 0, 0)); grammar.AddRule(new Rule(1, "START", new[] {"CP"}, 0, 0)); grammar.AddRule(new Rule(0, "CP", new[] {"C", "IP"}, 0, 1)); grammar.AddRule(new Rule(0, "IP", new[] {"NP", "VP"}, 1, 1)); grammar.AddRule(new Rule(0, "VP", new[] {"V1", "NP"}, 0, 1)); grammar.AddRule(new Rule(0, "VP", new[] {"V2", "PP"}, 0, 1)); grammar.AddRule(new Rule(2, "VP", new[] {"V3", "CP"}, 0, 1)); grammar.AddRule(new Rule(0, "NP", new[] {"D", "N"}, 1, 0)); grammar.AddRule(new Rule(0, "PP", new[] {"P", "NP"}, 0, 1)); grammar.AddNonTerminalToLandingSites("CP"); grammar.AddMoveable("NP"); grammar.AddMoveable("PP"); }
public bool AddMoveable(Grammar grammar) { for (var i = 0; i < NumberOfRetries; i++) { var rule = grammar.GetRandomRule(); //if movement symbol is LHS for some rule.. if (!grammar.Moveables.Contains(rule.Name.NonTerminal)) { grammar.AddMoveable(rule.Name.NonTerminal); return true; } } return false; }