コード例 #1
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);
        }
コード例 #2
0
        protected Regex GenerateArabicNumberRegex(ArabicType type, string placeholder = @"\D|\b")
        {
            Regex  addedRegex      = null;
            string integerTemplate = "(((?<!\\d+\\s*)-\\s*)|((?<=\\b)(?<!(\\d+\\.|\\d+,))))\\d{{1,3}}({0}\\d{{3}})+" + $@"(?={placeholder})";
            string doubleTemplate  = "(((?<!\\d+\\s*)-\\s*)|((?<=\\b)(?<!\\d+\\.|\\d+,)))\\d{{1,3}}({0}\\d{{3}})+{1}\\d+" + $@"(?={placeholder})";

            switch (type)
            {
            case ArabicType.IntegerNumComma:
                addedRegex = new Regex(string.Format(integerTemplate, ","), RegexOptions.IgnoreCase | RegexOptions.Singleline);
                break;

            case ArabicType.IntegerNumDot:
                addedRegex = new Regex(string.Format(integerTemplate, Regex.Escape(".")), RegexOptions.IgnoreCase | RegexOptions.Singleline);
                break;

            case ArabicType.IntegerNumBlank:
                addedRegex = new Regex(string.Format(integerTemplate, " "), RegexOptions.IgnoreCase | RegexOptions.Singleline);
                break;

            case ArabicType.IntegerNumQuote:
                addedRegex = new Regex(string.Format(integerTemplate, Regex.Escape("'")), RegexOptions.IgnoreCase | RegexOptions.Singleline);
                break;

            case ArabicType.DoubleNumCommaDot:
                addedRegex = new Regex(string.Format(doubleTemplate, ",", Regex.Escape(".")), RegexOptions.IgnoreCase | RegexOptions.Singleline);
                break;

            case ArabicType.DoubleNumDotComma:
                addedRegex = new Regex(string.Format(doubleTemplate, Regex.Escape("."), ","), RegexOptions.IgnoreCase | RegexOptions.Singleline);
                break;

            case ArabicType.DoubleNumBlankComma:
                addedRegex = new Regex(string.Format(doubleTemplate, " ", ","), RegexOptions.IgnoreCase | RegexOptions.Singleline);
                break;

            case ArabicType.DoubleNumBlankDot:
                addedRegex = new Regex(string.Format(doubleTemplate, " ", Regex.Escape(".")), RegexOptions.IgnoreCase | RegexOptions.Singleline);
                break;

            case ArabicType.DoubleNumCommaCdot:
                addedRegex = new Regex(string.Format(doubleTemplate, ",", "·"), RegexOptions.IgnoreCase | RegexOptions.Singleline);
                break;

            case ArabicType.DoubleNumQuoteComma:
                addedRegex = new Regex(string.Format(doubleTemplate, Regex.Escape("'"), ","), RegexOptions.IgnoreCase | RegexOptions.Singleline);
                break;
            }
            return(addedRegex);
        }