Exemple #1
0
        static void ParseFromConsole(HiddenMarkovModel hmm, ParseTarget target)
        {
            ConsoleColor defaultColor = Console.ForegroundColor;
            ITagger      tagger;

            char[] splitChars = null;
            if (target == ParseTarget.Address)
            {
                tagger     = new AddressTagger();
                splitChars = new char[1] {
                    '-'
                };
            }
            else
            {
                tagger = new NameTagger();
            }
            while (true)
            {
                Console.WriteLine($"Enter the {target}:");
                Console.ForegroundColor = ConsoleColor.Green;
                string input = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(input))
                {
                    continue;
                }
                string[] words  = Preprocessing.GetFormattedWords(input, splitChars);
                int[]    tags   = tagger.TagInput(words);
                int[]    result = hmm.Decide(tags);
                DisplayParseResults(words, tags, result, target);
                Console.ForegroundColor = defaultColor;
            }
        }
Exemple #2
0
        public HMMTestResult Test(Tuple <int[][], int[][]> xAndY)
        {
            int[][]       predicted = HMM.Decide(xAndY.Item1);
            HMMTestResult result    = predicted
                                      .Zip(xAndY.Item2, (pred, actual) => new HMMTestResult
            {
                TotalAccuracy   = pred.SequenceEqual(actual) ? 1 : 0,
                AverageAccuracy = pred.Zip(actual, (p, a) => p == a ? 1 : 0).Sum() / (float)pred.Count()
            }).Aggregate((curr, accum) =>
            {
                accum.TotalAccuracy   += curr.TotalAccuracy;
                accum.AverageAccuracy += curr.AverageAccuracy;
                return(accum);
            });

            result.TotalAccuracy   /= predicted.Count();
            result.AverageAccuracy /= predicted.Count();
            return(result);
        }
Exemple #3
0
 public int[] Decide(int[] input)
 {
     return(Model.Decide(input));
 }