コード例 #1
0
ファイル: TestCases.cs プロジェクト: JosephPotashnik/LIG
        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;
        }
コード例 #2
0
ファイル: Learner.cs プロジェクト: JosephPotashnik/LIG
        internal Grammar GetNeighbor(Grammar currentHypothesis)
        {
            while (true)
            {
                var m = GrammarPermutations.GetWeightedRandomMutation();
                var newGrammar = new Grammar(currentHypothesis);

                var res = m(newGrammar);
                if (res)
                {
                    //Console.WriteLine("mutation accepted: {0}", m);
                    //Console.WriteLine("New grammar {0}",newGrammar.ToString());
                }
                else
                {
                    //if there is no mutation to accept, don't bother re-parsing the current grammar.
                    //Console.WriteLine("mutation rejected");
                    return null;
                }
                var infinite = newGrammar.DoesGrammarAllowInfiniteMovement();
                if (!infinite) return newGrammar;
            }
        }
コード例 #3
0
ファイル: TestCases.cs プロジェクト: JosephPotashnik/LIG
 private static Grammar InfiniteMovementGrammar1()
 {
     var voc = Vocabulary.GetVocabularyFromFile(@"..\..\..\Input\Vocabulary.json");
     var grammar = new Grammar(voc);
     Program.AddTypesToGrammar(grammar);
     grammar.AddRule(new Rule(1, "START", new[] {"NP"}, 0, 0));
     grammar.AddRule(new Rule(1, "NP", new[] {"PP", "NP"}, 1, 0));
     grammar.AddRule(new Rule(1, "PP", new[] {"NP", "PP"}, 1, 0));
     grammar.AddRule(new Rule(1, "PP", new[] {"V2", "P"}, 1, 0));
     var does = grammar.DoesGrammarAllowInfiniteMovement();
     return grammar;
 }