public KoreanDateTimePeriodParserConfiguration(ICJKCommonDateTimeParserConfiguration config)
            : base(config)
        {
            var numOptions = NumberOptions.None;

            if ((config.Options & DateTimeOptions.NoProtoCache) != 0)
            {
                numOptions = NumberOptions.NoProtoCache;
            }

            var numConfig = new BaseNumberOptionsConfiguration(config.Culture, numOptions);

            CardinalExtractor = config.CardinalExtractor;
            CardinalParser    = AgnosticNumberParserFactory.GetParser(
                AgnosticNumberParserType.Cardinal, new KoreanNumberParserConfiguration(numConfig));

            DateExtractor       = config.DateExtractor;
            DurationExtractor   = config.DurationExtractor;
            DateTimeExtractor   = config.DateTimeExtractor;
            TimeExtractor       = config.TimeExtractor;
            TimePeriodExtractor = config.TimePeriodExtractor;
            DateParser          = config.DateParser;
            TimeParser          = config.TimeParser;
            DateTimeParser      = config.DateTimeParser;
            TimePeriodParser    = config.TimePeriodParser;

            SpecificTimeOfDayRegex = KoreanDateTimePeriodExtractorConfiguration.SpecificTimeOfDayRegex;
            TimeOfDayRegex         = KoreanDateTimePeriodExtractorConfiguration.TimeOfDayRegex;
            NextRegex   = KoreanDateTimePeriodExtractorConfiguration.NextRegex;
            LastRegex   = KoreanDateTimePeriodExtractorConfiguration.LastRegex;
            PastRegex   = KoreanDateTimePeriodExtractorConfiguration.PastRegex;
            FutureRegex = KoreanDateTimePeriodExtractorConfiguration.FutureRegex;
            UnitRegex   = KoreanDateTimePeriodExtractorConfiguration.UnitRegex;
            UnitMap     = config.UnitMap;
        }
Exemplo n.º 2
0
 public DutchNumberWithUnitParserConfiguration(CultureInfo ci)
     : base(ci)
 {
     this.InternalNumberExtractor = NumberExtractor.GetInstance();
     this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new DutchNumberParserConfiguration());
     this.ConnectorToken          = string.Empty;
 }
Exemplo n.º 3
0
 private static IModel GetPercentageModel()
 {
     return
         (new PercentModel(
              AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Percentage, new EnglishNumberParserConfiguration()),
              new PercentageExtractor()));
 }
Exemplo n.º 4
0
 private static IModel GetNumberModel()
 {
     return
         (new NumberModel(
              AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new EnglishNumberParserConfiguration()),
              new NumberExtractor(NumberMode.PureNumber)));
 }
Exemplo n.º 5
0
 private static IModel GetOrdinalModel()
 {
     return
         (new OrdinalModel(
              AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Ordinal, new EnglishNumberParserConfiguration()),
              new OrdinalExtractor()));
 }
Exemplo n.º 6
0
 public FrenchNumberWithUnitParserConfiguration(CultureInfo ci)
     : base(ci)
 {
     this.InternalNumberExtractor = NumberExtractor.GetInstance();
     this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new FrenchNumberParserConfiguration());
     this.ConnectorToken          = NumbersWithUnitDefinitions.ConnectorToken;
 }
Exemplo n.º 7
0
 private static IModel GetWithoutWhiteListNumberModel()
 {
     return
         (new NumberModel(
              AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number,
                                                    new ChineseNumberParserConfiguration()), new NumberExtractor(ChineseNumberMode.ExtractAll)));
 }
Exemplo n.º 8
0
 public TestNumberRecognizerInitialization()
 {
     controlModel = new NumberModel(
         AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number,
                                               new EnglishNumberParserConfiguration(new BaseNumberOptionsConfiguration(EnglishCulture))),
         NumberExtractor.GetInstance(NumberMode.PureNumber));
 }
Exemplo n.º 9
0
 public JapaneseNumberWithUnitParserConfiguration(CultureInfo ci)
     : base(ci)
 {
     this.InternalNumberExtractor = new NumberExtractor();
     this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new JapaneseNumberParserConfiguration());
     this.ConnectorToken          = string.Empty;
 }
 public PortugueseNumberWithUnitParserConfiguration(CultureInfo ci)
     : base(ci)
 {
     this.InternalNumberExtractor = NumberExtractor.GetInstance();
     this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new PortugueseNumberParserConfiguration(
                                                                              new BaseNumberOptionsConfiguration(ci.Name)));
     this.ConnectorToken = NumbersWithUnitDefinitions.ConnectorToken;
 }
Exemplo n.º 11
0
 public EnglishNumberWithUnitParserConfiguration(CultureInfo ci)
     : base(ci)
 {
     this.InternalNumberExtractor = NumberExtractor.GetInstance();
     this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new EnglishNumberParserConfiguration(
                                                                              new BaseNumberOptionsConfiguration(ci.Name)));
     this.ConnectorToken = string.Empty;
 }
Exemplo n.º 12
0
        public void TestKoreanParser()
        {
            var config = new KoreanNumberParserConfiguration(new BaseNumberOptionsConfiguration(Culture.Korean, NumberOptions.None));

            IParser parserNumber = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, config);

            Assert.IsTrue(parserNumber is BaseCJKNumberParser);
        }
Exemplo n.º 13
0
        public void TestKoreanParser()
        {
            IParser parserNumber   = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new KoreanNumberParserConfiguration());
            IParser parserCardinal = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Cardinal, new KoreanNumberParserConfiguration());

            Assert.IsTrue(parserNumber is BaseCJKNumberParser);
            Assert.IsTrue(parserCardinal is BaseCJKNumberParser);
        }
Exemplo n.º 14
0
        public void ParseTest(ArabicType type, string query, string value)
        {
            char decimalSep = '.', nonDecimalSep = ',';

            switch (type)
            {
            case ArabicType.DoubleNumBlankComma:
            case ArabicType.DoubleNumBlankDot:
            case ArabicType.IntegerNumBlank:
                nonDecimalSep = ' ';
                break;

            case ArabicType.DoubleNumCommaCdot:
            case ArabicType.DoubleNumCommaDot:
            case ArabicType.IntegerNumComma:
                nonDecimalSep = ',';
                break;

            case ArabicType.DoubleNumDotComma:
            case ArabicType.IntegerNumDot:
                nonDecimalSep = '.';
                break;

            case ArabicType.DoubleNumQuoteComma:
            case ArabicType.IntegerNumQuote:
                nonDecimalSep = '\'';
                break;
            }
            switch (type)
            {
            case ArabicType.DoubleNumQuoteComma:
            case ArabicType.DoubleNumBlankComma:
            case ArabicType.DoubleNumDotComma:
                decimalSep = ',';
                break;

            case ArabicType.DoubleNumBlankDot:
            case ArabicType.DoubleNumCommaDot:
                decimalSep = '.';
                break;

            case ArabicType.DoubleNumCommaCdot:
                decimalSep = '·';
                break;
            }

            var parser = AgnosticNumberParserFactory.GetParser(
                AgnosticNumberParserType.Double,
                new ArabicNumberTestConfiguration(decimalSep, nonDecimalSep));
            var resultJson =
                parser.Parse(
                    new ExtractResult()
            {
                Text = query, Start = 0, Length = query.Length, Type = "builtin.num.double", Data = "Num"
            });

            Assert.AreEqual(value, resultJson.ResolutionStr);
        }
        public ChineseNumberWithUnitParserConfiguration(CultureInfo ci)
            : base(ci)
        {
            var numConfig = new BaseNumberOptionsConfiguration(ci.Name, NumberOptions.None);

            this.InternalNumberExtractor = new NumberExtractor(numConfig);
            this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number,
                                                                                 new ChineseNumberParserConfiguration(numConfig));
            this.ConnectorToken = string.Empty;
        }
Exemplo n.º 16
0
        public void TestGermanParser()
        {
            IParser parseNumber     = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new GermanNumberParserConfiguration());
            IParser parseCardinal   = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Cardinal, new GermanNumberParserConfiguration());
            IParser parsePercentage = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Percentage, new GermanNumberParserConfiguration());

            Assert.IsTrue(parseNumber is BaseNumberParser);
            Assert.IsTrue(parseCardinal is BaseNumberParser);
            Assert.IsTrue(parsePercentage is BasePercentageParser);
        }
Exemplo n.º 17
0
        public void TestJapaneseParser()
        {
            IParser parserNumber     = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new JapaneseNumberParserConfiguration());
            IParser parserCardinal   = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Cardinal, new JapaneseNumberParserConfiguration());
            IParser parserPercentaje = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Percentage, new JapaneseNumberParserConfiguration());

            Assert.IsTrue(parserNumber is BaseCJKNumberParser);
            Assert.IsTrue(parserCardinal is BaseCJKNumberParser);
            Assert.IsTrue(parserPercentaje is BaseCJKNumberParser);
        }
        public ItalianNumberWithUnitParserConfiguration(CultureInfo ci)
            : base(ci)
        {
            var numConfig = new BaseNumberOptionsConfiguration(Culture.Italian, NumberOptions.None);

            this.InternalNumberExtractor = NumberExtractor.GetInstance();
            this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number,
                                                                                 new ItalianNumberParserConfiguration(numConfig));
            this.ConnectorToken = NumbersWithUnitDefinitions.ConnectorToken;
        }
        public TurkishNumberWithUnitParserConfiguration(CultureInfo ci)
            : base(ci)
        {
            var numConfig = new BaseNumberOptionsConfiguration(Culture.Turkish, NumberOptions.None);

            this.InternalNumberExtractor = NumberExtractor.GetInstance();
            this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number,
                                                                                 new TurkishNumberParserConfiguration(numConfig));
            this.ConnectorToken = string.Empty;
        }
Exemplo n.º 20
0
        public PortugueseNumberWithUnitParserConfiguration(CultureInfo ci)
            : base(ci)
        {
            var numConfig = new BaseNumberOptionsConfiguration(Culture.Portuguese, NumberOptions.None);

            this.InternalNumberExtractor = NumberExtractor.GetInstance(numConfig);
            this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number,
                                                                                 new PortugueseNumberParserConfiguration(numConfig));
            this.ConnectorToken = NumbersWithUnitDefinitions.ConnectorToken;

            this.TypeList = DimensionExtractorConfiguration.DimensionTypeList;
        }
        public EnglishNumberWithUnitParserConfiguration(CultureInfo ci)
            : base(ci)
        {
            var numConfig = new BaseNumberOptionsConfiguration(Culture.English, NumberOptions.None);

            this.InternalNumberExtractor = NumberExtractor.GetInstance(numConfig);
            this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number,
                                                                                 new EnglishNumberParserConfiguration(numConfig));
            this.ConnectorToken = string.Empty;

            this.TypeList = DimensionExtractorConfiguration.DimensionTypeList;
        }
Exemplo n.º 22
0
        public void TestJapaneseParser()
        {
            var config = new JapaneseNumberParserConfiguration(new BaseNumberOptionsConfiguration(Culture.Japanese, NumberOptions.None));

            IParser parserNumber     = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, config);
            IParser parserCardinal   = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Cardinal, config);
            IParser parserPercentage = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Percentage, config);

            Assert.IsTrue(parserNumber is BaseCJKNumberParser);
            Assert.IsTrue(parserCardinal is BaseCJKNumberParser);
            Assert.IsTrue(parserPercentage is BaseCJKNumberParser);
        }
        public void TestFrenchParser()
        {
            var config = new FrenchNumberParserConfiguration(new BaseNumberOptionsConfiguration(Culture.French));

            IParser parseNumber     = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, config);
            IParser parseCardinal   = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Cardinal, config);
            IParser parsePercentage = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Percentage, config);

            Assert.IsTrue(parseNumber is BaseNumberParser);
            Assert.IsTrue(parseCardinal is BaseNumberParser);
            Assert.IsTrue(parsePercentage is BasePercentageParser);
        }
Exemplo n.º 24
0
        private static IModel GetCustomModelFor(string language)
        {
            switch (language)
            {
            case Culture.Chinese:
                return(new NumberModel(
                           AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new ChineseNumberParserConfiguration()),
                           new NumberExtractor(ChineseNumberMode.ExtractAll)));
            }

            throw new Exception($"Custom Model for '{language}' not supported");
        }
Exemplo n.º 25
0
        public FrenchNumberWithUnitParserConfiguration(CultureInfo ci)
            : base(ci)
        {
            var numConfig = new BaseNumberOptionsConfiguration(Culture.French, NumberOptions.None);

            this.InternalNumberExtractor = NumberExtractor.GetInstance(numConfig);
            this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number,
                                                                                 new FrenchNumberParserConfiguration(numConfig));

            // A space is added to the token to avoid interpreting part of a unit as a connector (e.g. 'de' in 'degrés')
            this.ConnectorToken = NumbersWithUnitDefinitions.ConnectorToken + " ";

            this.TypeList = DimensionExtractorConfiguration.DimensionTypeList;
        }
Exemplo n.º 26
0
        public void ParseTest(LongFormatType type, string query, string value)
        {
            char decimalSep = type.DecimalsMark, nonDecimalSep = type.ThousandsMark;

            var parser = AgnosticNumberParserFactory.GetParser(
                AgnosticNumberParserType.Double, new LongFormTestConfiguration(decimalSep, nonDecimalSep));

            var resultJson = parser.Parse(new ExtractResult()
            {
                Text = query, Start = 0, Length = query.Length, Type = "builtin.num.double", Data = "Num",
            });

            Assert.AreEqual(value, resultJson.ResolutionStr);
        }
        public JapaneseDateTimePeriodParserConfiguration(IFullDateTimeParserConfiguration configuration)
        {
            config = configuration;

            var numOptions = NumberOptions.None;

            if ((config.Options & DateTimeOptions.NoProtoCache) != 0)
            {
                numOptions = NumberOptions.NoProtoCache;
            }

            var numConfig = new BaseNumberOptionsConfiguration(config.Culture, numOptions);

            cardinalParser = AgnosticNumberParserFactory.GetParser(
                AgnosticNumberParserType.Cardinal, new JapaneseNumberParserConfiguration(numConfig));
        }
Exemplo n.º 28
0
 public SpanishNumberWithUnitParserConfiguration(CultureInfo ci) : base(ci)
 {
     this.InternalNumberExtractor = new NumberExtractor(NumberMode.Default);
     this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new SpanishNumberParserConfiguration());
     this.ConnectorToken          = NumbersWithUnitDefinitions.ConnectorToken;
 }
 public PortugueseNumberWithUnitParserConfiguration(CultureInfo ci) : base(ci)
 {
     this.InternalNumberExtractor = new NumberExtractor(NumberMode.Default);
     this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new PortugueseNumberParserConfiguration());
     this.ConnectorToken          = "de";
 }
 public EnglishNumberWithUnitParserConfiguration(CultureInfo ci) : base(ci)
 {
     this.InternalNumberExtractor = new NumberExtractor(NumberMode.Default);
     this.InternalNumberParser    = AgnosticNumberParserFactory.GetParser(AgnosticNumberParserType.Number, new EnglishNumberParserConfiguration());
     this.ConnectorToken          = string.Empty;
 }