Beispiel #1
0
        private static void ComplexMovementTest()
        {
            var voc = Vocabulary.GetVocabularyFromFile(@"Vocabulary.json");
            var grammar = new Grammar(voc);
            Program.AddTypesToGrammar(grammar);

            grammar.AddProjectionTypeToTypeDictionary("CP", "N"); // no overt POS here, head of IP is V.
            grammar.AddProjectionTypeToTypeDictionary("IP", "N"); // no overt POS here, head of IP is V.
            grammar.AddRule(new Rule(1, "START", new[] {"CP"}, 0, 0));
            grammar.AddRule(new Rule(1, "START", new[] {"IP"}, 0, 0));

            //grammar.AddRule(new Rule(1, "CP", new[] { "IP" }, 0, 0));
            //grammar.AddRule(new Rule(1, "IP", new[] { "NP" }, 0, 0));
            //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.AddNonTerminalToLandingSites("IP");
            grammar.AddMoveable("NP");
            grammar.AddMoveable("PP");
            grammar.GenerateDerivedRulesFromSchema();

            var parser = new Parser(grammar, true);
            var n = parser.ParseSentence("Who Who Who");
            n.Print();
        }
Beispiel #2
0
        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");
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        private static Grammar InfiniteMovementGrammar3()
        {
            var voc = Vocabulary.GetVocabularyFromFile(@"..\..\..\Input\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, "NP", new[] {"V0P", "NP"}, 1, 0));

            grammar.AddRule(new Rule(1, "V0P", new[] {"V2"}, 0, 0));
            grammar.AddRule(new Rule(1, "START", new[] {"NP", "V0"}, 1, 1));
            grammar.AddRule(new Rule(1, "START", new[] {"V0", "NP"}, 0, 1));
            grammar.AddRule(new Rule(1, "START", new[] {"PP", "NP"}, 0, 1));
            grammar.AddRule(new Rule(1, "START", new[] {"NP", "NP"}, 1, 1));
            grammar.AddRule(new Rule(1, "V0P", new[] {"V1"}, 0, 0));
            grammar.AddRule(new Rule(1, "PP", new[] {"V0P", "P"}, 1, 1));

            grammar.AddRule(new Rule(1, "V0P", new[] {"NP", "V0P"}, 1, 1));
            grammar.AddRule(new Rule(1, "NP", new[] {"D", "N"}, 1, 1));
            var does = grammar.DoesGrammarAllowInfiniteMovement();
            return grammar;
        }
        public bool InsertRuleWithANewSymbol(Grammar grammar)
        {
            for (var i = 0; i < NumberOfRetries; i++)
            {
                var existingLHSNonTerminal = grammar.GetRandomRule().Name.NonTerminal;
                if (existingLHSNonTerminal == grammar.StartSymbol) continue;

                var newLHSNonTerminal = grammar.GetNextAvailableProjectionName();

                var typeOfExistingLHS = grammar.NonTerminalsTypeDictionary[existingLHSNonTerminal];

                grammar.AddProjectionTypeToTypeDictionary(newLHSNonTerminal, typeOfExistingLHS);

                //grammar.AddRule(new Rule(0, grammar.StartSymbol, new[] { newLHSNonTerminal, grammar.StartSymbol }, 0, 1));
                // grammar.AddRule(new Rule(0, grammar.StartSymbol, new[] { newLHSNonTerminal }, 0, 0));

                grammar.AddRule(new Rule(0, newLHSNonTerminal, new[] {existingLHSNonTerminal}, 0, 0));


                return true;
            }
            return false;
        }