コード例 #1
0
ファイル: Checker.cs プロジェクト: lepeap/TxTraktor
        internal static void CheckGrammar(string text, Grammar etalonGrammar)
        {
            var rezGrammar = _parser.Parse("Test", text);

            Assert.AreEqual(etalonGrammar.Language,
                            rezGrammar.Language,
                            "Wrong grammar lang"
                            );

            Assert.AreEqual(etalonGrammar.Name,
                            rezGrammar.Name,
                            "Wrong grammar name"
                            );

            Assert.AreEqual(etalonGrammar.Key,
                            rezGrammar.Key,
                            "Wrong grammar key"
                            );

            _checkRules(rezGrammar.Rules.ToArray(), etalonGrammar.Rules.ToArray());

            Assert.AreEqual(etalonGrammar.HasGrammarImports,
                            rezGrammar.HasGrammarImports,
                            "Wrong grammars imports count"
                            );
            if (etalonGrammar.HasGrammarImports)
            {
                _checkGrammarImports(etalonGrammar.Imports.ToArray(), rezGrammar.Imports.ToArray());
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            GrammarContainer grammarContainer = new GrammarContainer("EnglishGrammar.json");

            IWordDataReader reader = new English1WordDataReader("english.txt", grammarContainer.ReplaceIdentifiers);

            IDictionary dict = new DefaultDictionary();

            int i = 0;
            English1GrammarFactory factory = new English1GrammarFactory(grammarContainer, new WordIdCounter(1));

            IGrammarParser grammar = factory.CreateGrammar();

            foreach (IWordData wordCorpus in reader)
            {
                IList <IWord> words = grammar.Parse(wordCorpus);

                foreach (IWord word in words)
                {
                    dict.AddWord(word);
                }
                //PrintWordData (words);

                if (i++ == 100)
                {
                    IList <IWord> postProcessed = grammar.PostProcess();

                    //PrintWordData (postProcessed);

                    dict.Print();
                    Environment.Exit(0);
                }
            }

            Console.WriteLine("done: " + i);
        }