public GrammarContainer(string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new IOException("Grammar file not found: " + fileName);
            }

            GrammarContainer gram = JsonConvert.DeserializeObject <GrammarContainer> (File.ReadAllText(fileName));

            m_grammar     = gram.Grammar;
            m_ignore      = gram.IgnoreIdentifiers;
            m_replace     = gram.ReplaceIdentifiers;
            m_ignoreWords = gram.IgnoreWords;
        }
Example #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);

		}
Example #3
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);
        }
 public English1GrammarFactory(GrammarContainer grammar, IWordIdCounter counter)
 {
     m_grammar = grammar;
     m_counter = counter;
 }
		public English1GrammarFactory (GrammarContainer grammar, IWordIdCounter counter)
		{
			m_grammar = grammar; 
			m_counter = counter;
		}