public static Recognizer Create(System.Globalization.CultureInfo culture, int priority)
        {
            try
            {
                // TODO support non-blank languages for unit separation

                MeasureRegexRecognizer result = new MeasureRegexRecognizer(100, "DEFAULT_MEASURE_RECOGNIZER", culture);

                Core.CharacterSet first = null;
                // augmentation doesn't change FIRST()
                List <string> patterns = NumberRegexRecognizer.ComputeRXPatterns(culture, NumberSeparatorMode.CultureDefault, out first);
                AugmentPatterns(patterns, culture);

                foreach (string p in patterns)
                {
                    // use the same first for all patterns (the number regex pattern computer returns just one pattern anyway)
                    result.Add(p, first, 2);
                }

                SeparatorCombination defaultSc = new SeparatorCombination(culture, false);
                if (defaultSc.IsSwappable())
                {
                    patterns = NumberRegexRecognizer.ComputeRXPatterns(culture, NumberSeparatorMode.Swapped, out first);
                    AugmentPatterns(patterns, culture);

                    foreach (string p in patterns)
                    {
                        result.Add(p, first, 1);
                    }
                }
                if (NumberPatternComputer.DoAddENUSSeparators(culture))
                {
                    patterns = NumberRegexRecognizer.ComputeRXPatterns(culture, NumberSeparatorMode.EnUS, out first);
                    AugmentPatterns(patterns, culture);

                    foreach (string p in patterns)
                    {
                        result.Add(p, first, 0);
                    }
                }

                result.OnlyIfFollowedByNonwordCharacter
                    = true;                     // otherwise "123 ABC" will be recognized as "123 A" "BC" in Japanese
                return(result);
            }
            catch             // (System.Exception e)
            {
                return(null);
            }
        }
예제 #2
0
        public static Recognizer Create(System.Globalization.CultureInfo culture, int priority)
        {
            try
            {
                NumberRegexRecognizer recog = new NumberRegexRecognizer(100, "DEFAULT_NUMBER_RECOGNIZER", culture.NumberFormat);

                CharacterSet first = null;
                foreach (string p in ComputeRXPatterns(culture, NumberSeparatorMode.CultureDefault, out first))
                {
                    recog.Add(p, first, 2);
                }

                SeparatorCombination defaultSc = new SeparatorCombination(culture, false);
                if (defaultSc.IsSwappable())
                {
                    foreach (string p in ComputeRXPatterns(culture, NumberSeparatorMode.Swapped, out first))
                    {
                        recog.Add(p, first, 1);
                    }
                }
                if (NumberPatternComputer.DoAddENUSSeparators(culture))
                {
                    foreach (string p in ComputeRXPatterns(culture, NumberSeparatorMode.EnUS, out first))
                    {
                        recog.Add(p, first, 1);
                    }
                }

                recog.OnlyIfFollowedByNonwordCharacter
                    = CultureInfoExtensions.UseBlankAsWordSeparator(culture);
                recog.AdditionalTerminators = new CharacterSet();
                recog.AdditionalTerminators.Add('-');                 // TODO other math symbols?
                recog.OverrideFallbackRecognizer = true;

                return(recog);
            }
            catch             // (System.Exception e)
            {
                return(null);
            }
        }