Exemple #1
0
        static void Phase1()
        {
            List <Word> words2 = ParsingTools.GetListOfWords(ParsingTools.ProjectDirectory + "training_dataset.txt");

            words2.AddRange(ParsingTools.GetListOfWords(ParsingTools.ProjectDirectory + "testing_dataset.txt"));


            loadTests(words2);

            // while (true)
            // {
            Console.WriteLine("Enter a seed word:");
            string searchNext = Console.ReadLine();

            Console.WriteLine("Enter how many words to generate:");
            int genNum = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine();
            for (int n = 0; n < genNum; n++)
            {
                WordAndPercentage answer = predictNextWord(searchNext);
                searchNext = answer.word;
                Console.Write(searchNext + " ");
            }
        }
Exemple #2
0
 public Word(string underscored_encoding)
 {
     string[] split = underscored_encoding.Split('_');
     if (split.Length != 2)
     {
         throw new Exception("Expected exactly 1 underscore");
     }
     Content      = split[0].ToLower();
     PartOfSpeech = ParsingTools.GetWordType(split[1]);
 }
Exemple #3
0
        static void Phase2()
        {
            List <Word> words2 = ParsingTools.GetListOfWords(ParsingTools.ProjectDirectory + "training_dataset.txt");

            words2.AddRange(ParsingTools.GetListOfWords(ParsingTools.ProjectDirectory + "testing_dataset.txt"));



            Console.WriteLine("Enter your sentence. Please separate every symbol with a space (that includes periods, exclamation marks, etc.)");
            string        sentenceWhole = Console.ReadLine();
            List <string> sentence      = sentenceWhole.Split(' ').ToList();

            for (int n = sentence.Count - 1; n >= 0; n--)
            {
                sentence[n] = sentence[n].Trim();
                if (sentence[n] == "")
                {
                    sentence.RemoveAt(n);
                }
                else
                {
                    sentence[n] = sentence[n].ToLower();
                }
            }

            Console.WriteLine();

            Console.Write("You entered: ");
            Console.Write("[" + sentence[0] + "]");
            for (int n = 1; n < sentence.Count; n++)
            {
                Console.Write(", " + "[" + sentence[n] + "]");
            }
            Console.WriteLine();
            Console.WriteLine("Please wait...");


            Dictionary <StateTransition, double> transitionModel = createTransitionModel(words2);
            //printTransitionMatrix(transitionModel); Environment.Exit(0);

            Dictionary <ObservationFromState, double> observationModel = createObservationModel(words2);
            //  loadTests(words2);
            //  Printing.printObservationMatrix(observationModel, myDictionary);
            Dictionary <WordType, double> sentenceStarters = beginSentenceProb(words2);


            //  foreach (var s in sentenceStarters)
            //  {
            //      Console.WriteLine(s.Key.ToString() + ", " + s.Value.ToString());
            //  }


            var res = Viterbi.DoViterbi(sentence, transitionModel, observationModel, sentenceStarters);

            Console.Write("Our results: ");
            Console.Write(res[1]);
            for (int n = 2; n < res.Length; n++)
            {
                Console.Write(", " + res[n]);
            }


            Console.WriteLine();
        }