Esempio n. 1
0
        public static OrdinalExtractor GetInstance(NumberOptions options = NumberOptions.None)
        {
            var cacheKey = options.ToString();

            if (!Instances.ContainsKey(cacheKey))
            {
                var instance = new OrdinalExtractor(options);
                Instances.TryAdd(cacheKey, instance);
            }

            return(Instances[cacheKey]);
        }
Esempio n. 2
0
        private NumberRecognizer(NumberOptions options)
        {
            RegisterModel(Culture.English, options.ToString(), new Dictionary <Type, IModel>
            {
                [typeof(NumberModel)] = new NumberModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new EnglishNumberParserConfiguration()),
                    English.NumberExtractor.GetInstance(NumberMode.PureNumber)),
                [typeof(OrdinalModel)] = new OrdinalModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Ordinal, new EnglishNumberParserConfiguration()),
                    English.OrdinalExtractor.GetInstance()),
                [typeof(PercentModel)] = new PercentModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Percentage, new EnglishNumberParserConfiguration()),
                    new English.PercentageExtractor())
            });

            RegisterModel(Culture.Chinese, options.ToString(), new Dictionary <Type, IModel>
            {
                [typeof(NumberModel)] = new NumberModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new ChineseNumberParserConfiguration()),
                    new Chinese.NumberExtractor()),
                [typeof(OrdinalModel)] = new OrdinalModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Ordinal, new ChineseNumberParserConfiguration()),
                    new Chinese.OrdinalExtractor()),
                [typeof(PercentModel)] = new PercentModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Percentage, new ChineseNumberParserConfiguration()),
                    new Chinese.PercentageExtractor())
            });

            RegisterModel(Culture.Spanish, options.ToString(), new Dictionary <Type, IModel>
            {
                [typeof(NumberModel)] = new NumberModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new SpanishNumberParserConfiguration()),
                    new Spanish.NumberExtractor(NumberMode.PureNumber)),
                [typeof(OrdinalModel)] = new OrdinalModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Ordinal, new SpanishNumberParserConfiguration()),
                    new Spanish.OrdinalExtractor()),
                [typeof(PercentModel)] = new PercentModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Percentage, new SpanishNumberParserConfiguration()),
                    new Spanish.PercentageExtractor())
            });

            RegisterModel(Culture.Portuguese, options.ToString(), new Dictionary <Type, IModel>
            {
                [typeof(NumberModel)] = new NumberModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new PortugueseNumberParserConfiguration()),
                    new Portuguese.NumberExtractor(NumberMode.PureNumber)),
                [typeof(OrdinalModel)] = new OrdinalModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Ordinal, new PortugueseNumberParserConfiguration()),
                    new Portuguese.OrdinalExtractor()),
                [typeof(PercentModel)] = new PercentModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Percentage, new PortugueseNumberParserConfiguration()),
                    new Portuguese.PercentageExtractor())
            });

            RegisterModel(Culture.French, options.ToString(), new Dictionary <Type, IModel>
            {
                [typeof(NumberModel)] = new NumberModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new FrenchNumberParserConfiguration()),
                    new French.NumberExtractor(NumberMode.PureNumber)),
                [typeof(OrdinalModel)] = new OrdinalModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Ordinal, new FrenchNumberParserConfiguration()),
                    new French.OrdinalExtractor()),
                [typeof(PercentModel)] = new PercentModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Percentage, new FrenchNumberParserConfiguration()),
                    new French.PercentageExtractor())
            });

            RegisterModel(Culture.German, options.ToString(), new Dictionary <Type, IModel>
            {
                [typeof(NumberModel)] = new NumberModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new GermanNumberParserConfiguration()),
                    German.NumberExtractor.GetInstance(NumberMode.PureNumber)),
                [typeof(OrdinalModel)] = new OrdinalModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Ordinal, new GermanNumberParserConfiguration()),
                    German.OrdinalExtractor.GetInstance()),
                [typeof(PercentModel)] = new PercentModel(
                    AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Percentage, new GermanNumberParserConfiguration()),
                    new German.PercentageExtractor())
            });
        }