示例#1
0
        protected ParseResult TextNumberParse(ExtractResult extResult)
        {
            var result = new ParseResult
            {
                Start  = extResult.Start,
                Length = extResult.Length,
                Text   = extResult.Text,
                Type   = extResult.Type,
            };

            var handle = extResult.Text.ToLower();

            handle = Config.HalfADozenRegex.Replace(handle, Config.HalfADozenText);

            var numGroup = handle.Split(Config.WrittenDecimalSeparatorTexts.ToArray(), StringSplitOptions.RemoveEmptyEntries);

            var intPart  = numGroup[0];
            var strMatch = TextNumberRegex.Match(intPart);

            // Store all match str.
            var matchStrs = new List <string>();

            while (strMatch.Success)
            {
                var matchStr = strMatch.Groups[0].Value.ToLower();
                matchStrs.Add(matchStr);
                strMatch = strMatch.NextMatch();
            }

            // Get the value recursively
            var intPartRet = GetIntValue(matchStrs);

            double pointPartRet = 0;

            if (numGroup.Length == 2)
            {
                var pointPart = numGroup[1];
                strMatch = TextNumberRegex.Match(pointPart);
                matchStrs.Clear();

                while (strMatch.Success)
                {
                    var matchStr = strMatch.Groups[0].Value.ToLower();
                    matchStrs.Add(matchStr);
                    strMatch = strMatch.NextMatch();
                }

                pointPartRet += GetPointValue(matchStrs);
            }

            result.Value = intPartRet + pointPartRet;

            return(result);
        }
示例#2
0
        private List <string> GetMatches(string input)
        {
            var sMatch    = TextNumberRegex.Match(input);
            var matchStrs = new List <string>();

            //Store all match str.
            while (sMatch.Success)
            {
                var matchStr = sMatch.Groups[0].Value.ToLower();
                matchStrs.Add(matchStr);
                sMatch = sMatch.NextMatch();
            }

            return(matchStrs);
        }
示例#3
0
        public virtual ParseResult TextNumberParse(ExtractResult extResult)
        {
            var result = new ParseResult
            {
                Start    = extResult.Start,
                Length   = extResult.Length,
                Text     = extResult.Text,
                Type     = extResult.Type,
                Metadata = extResult.Metadata,
            };

            var handle = extResult.Text;

            handle = Config.HalfADozenRegex.Replace(handle, Config.HalfADozenText);

            // Handling cases like "last", "next one", "previous one"
            if ((this.Config.Config.Options & NumberOptions.SuppressExtendedTypes) == 0)
            {
                if (extResult.Metadata != null && extResult.Metadata.IsOrdinalRelative)
                {
                    return(result);
                }
            }

            var numGroup = handle.Split(Config.WrittenDecimalSeparatorTexts.ToArray(), StringSplitOptions.RemoveEmptyEntries);

            var intPart     = numGroup[0];
            var stringMatch = TextNumberRegex.Match(intPart);

            // Store all match str.
            var matchStrs = new List <string>();

            while (stringMatch.Success)
            {
                var matchStr = stringMatch.Groups[0].Value;
                matchStrs.Add(matchStr);
                stringMatch = stringMatch.NextMatch();
            }

            // Get the value recursively
            var intPartRet = GetIntValue(matchStrs);

            double pointPartRet = 0;

            if (numGroup.Length == 2)
            {
                var pointPart = numGroup[1];
                stringMatch = TextNumberRegex.Match(pointPart);
                matchStrs.Clear();

                while (stringMatch.Success)
                {
                    var matchStr = stringMatch.Groups[0].Value;
                    matchStrs.Add(matchStr);
                    stringMatch = stringMatch.NextMatch();
                }

                pointPartRet += GetPointValue(matchStrs);
            }

            result.Value = intPartRet + pointPartRet;

            return(result);
        }
        protected ParseResult TextNumberParse(ExtractResult extResult)
        {
            var result = new ParseResult
            {
                Start  = extResult.Start,
                Length = extResult.Length,
                Text   = extResult.Text,
                Type   = extResult.Type,
            };

            var handle = extResult.Text.ToLower();

            handle = Config.HalfADozenRegex.Replace(handle, Config.HalfADozenText);

            // Handling cases like "last", "next one", "previous one"
            if (Config.RelativeReferenceMap.ContainsKey(extResult.Text))
            {
                result.Value = Config.RelativeReferenceMap[extResult.Text];
            }
            else
            {
                var numGroup = handle.Split(Config.WrittenDecimalSeparatorTexts.ToArray(), StringSplitOptions.RemoveEmptyEntries);

                #region IntegerPart

                var intPart = numGroup[0];
                var sMatch  = TextNumberRegex.Match(intPart);

                // Store all match str.
                var matchStrs = new List <string>();

                while (sMatch.Success)
                {
                    var matchStr = sMatch.Groups[0].Value.ToLower();
                    matchStrs.Add(matchStr);
                    sMatch = sMatch.NextMatch();
                }

                //Get the value recursively
                var intPartRet = GetIntValue(matchStrs);

                #endregion

                #region DecimalPart

                double pointPartRet = 0;
                if (numGroup.Length == 2)
                {
                    var pointPart = numGroup[1];
                    sMatch = TextNumberRegex.Match(pointPart);
                    matchStrs.Clear();

                    while (sMatch.Success)
                    {
                        var matchStr = sMatch.Groups[0].Value.ToLower();
                        matchStrs.Add(matchStr);
                        sMatch = sMatch.NextMatch();
                    }

                    pointPartRet += GetPointValue(matchStrs);
                }

                #endregion

                result.Value = intPartRet + pointPartRet;
            }

            return(result);
        }