Ejemplo n.º 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;
            }
        }
Ejemplo n.º 2
0
 private int[] LabelSample(SampleType sample, char[] splitChars)
 {
     return(TrainingSampleProps
            .Select((prop, i) =>
                    Preprocessing.GetFormattedWords(prop.GetValue(sample)?.ToString() ?? "", splitChars)
                    .Select(x => (int)typeof(LabelEnum).GetEnumValues().GetValue(i)))
            .SelectMany(x => x)
            .ToArray());
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses <paramref name="address"/> into its component parts and returns <see cref="Address"/>.
        /// </summary>
        /// <param name="address">address <see cref="string"/> to parse</param>
        /// <returns>parsed and formatted <see cref="Address"/></returns>
        public Address Parse(string address)
        {
            string[] words = Preprocessing.GetFormattedWords(
                address?.Trim() ?? "",
                new char[1] {
                '-'
            });
            int[]   tags          = Tagger.TagInput(words);
            int[]   labels        = HMM.Decide(tags);
            Address parsedAddress = AssignToAddressFromLabels(labels, words);

            return(Formatter.Format(parsedAddress));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parses <paramref name="name"/> into its component parts and returns <see cref="Name"/>.
        /// </summary>
        /// <param name="name">name <see cref="string"/> to parse</param>
        /// <returns>parsed and formatted <see cref="Name"/></returns>
        public Name Parse(string name)
        {
            string[] words  = Preprocessing.GetFormattedWords(name?.Trim() ?? "");
            int[]    labels = new int[0];
            if (IndividualChecker.IsIndividual(words))
            {
                int[] tags = Tagger.TagInput(words);
                labels = HMM.Decide(tags);
            }
            else
            {
                // if non-individual, just assign everything to LastName
                labels = words.Select(w => (int)NameLabel.LastName).ToArray();
            }
            Name parsedName = AssignToNameFromLabels(labels, words);

            return(Formatter.Format(parsedName));
        }
Ejemplo n.º 5
0
 private int[] TagSample(SampleType sample, char[] splitChars)
 {
     return(Tagger.TagInput(Preprocessing.GetFormattedWords(sample.Input, splitChars)));
 }