Пример #1
0
        /// <summary>
        /// Extracts and parses the hundreds from the specified regex Match object provided.
        /// </summary>
        /// <param name="m">The regex match object to extract from.</param>
        /// <returns></returns>
        private long ExtractHundreds(Match m)
        {
            long num = 0L;

            foreach (Capture c in m.Groups[HUNDS_NAME].Captures)
            {
                if (!PersianLiteral2NumMap.TryPersianString2Num(c.Value, out num))
                {
                    num = 0L;
                    foreach (Capture cc in m.Groups[HUNDSNUM_NAME].Captures)
                    {
                        long coef = 0L;
                        if (PersianLiteral2NumMap.TryPersianString2Num(cc.Value, out coef))
                        {
                            if (10 < coef && coef < 100)
                            {
                                coef = coef / 10;
                            }
                            else if (coef >= 100)
                            {
                                coef = 0;
                            }
                        }

                        num += coef * 100;
                    }
                }
            }
            return(num);
        }
Пример #2
0
        /// <summary>
        /// Extracts and parses the multiplier and number from the specified string.
        /// </summary>
        /// <param name="str">The string to be parsed.</param>
        /// <returns></returns>
        private long ExtractMultiplierAndNumber(string str)
        {
            long num     = 0L;
            long tempNum = 0L;

            if (!PersianLiteral2NumMap.TryPersianString2Num(str.Trim(), out num))
            {
                num = 0L;
                Regex regex = new Regex(BlockPlusMultiplier());
                foreach (Match m in regex.Matches(str))
                {
                    // should iterate only once
                    foreach (Capture c in m.Groups[THREEDB_NAME].Captures)
                    {
                        num += ExtractThreeDB(c.Value);
                    }

                    num = (num == 0)? 1 : num;

                    foreach (Capture c in m.Groups[MULTIPLIER_NAME].Captures)
                    {
                        if (PersianLiteral2NumMap.TryPersianString2Num(c.Value, out tempNum))
                        {
                            num *= tempNum;
                        }
                    }
                }
            }

            return(num);
        }
Пример #3
0
        /// <summary>
        /// Extracts and parses the week-day from the given regex Match instance.
        /// </summary>
        /// <param name="m">The regex Match instance to extract week-day from.</param>
        /// <returns></returns>
        private Weekdays ExtractWeekday(Match m)
        {
            Weekdays w = Weekdays.Illeagal;

            foreach (Capture c in m.Groups["Weekday"].Captures)
            {
                if (c.Value == "جمعه")
                {
                    w = Weekdays.Fri;
                }
                if (c.Value == "شنبه")
                {
                    w = Weekdays.Sat;
                }
                else
                {
                    foreach (Capture cc in m.Groups["WeekdayNum"].Captures)
                    {
                        string value = cc.Value;
                        if (Char.IsDigit(value[0]))
                        {
                            int n;
                            value = ParsingUtils.ConvertNumber2English(value);
                            if (Int32.TryParse(value, out n))
                            {
                                w = NthWeekday(n);
                            }
                            else
                            {
                                w = Weekdays.Illeagal;
                            }
                        }
                        else
                        {
                            Int64 n;
                            if (PersianLiteral2NumMap.TryPersianString2Num(value, out n))
                            {
                                w = NthWeekday((int)n);
                            }
                            else
                            {
                                w = Weekdays.Illeagal;
                            }
                        }
                    }
                }
            }

            return(w);
        }
Пример #4
0
        /// <summary>
        /// Extracts and parses the three digit block from the specified string.
        /// </summary>
        /// <param name="str">The string to extract number from.</param>
        /// <returns></returns>
        private long ExtractThreeDB(string str)
        {
            long num     = 0L;
            long tempNum = 0L;

            if (Char.IsDigit(str[0]))
            {
                string strNum = ParsingUtils.ConvertNumber2English(str.Trim());
                int    n;
                if (Int32.TryParse(strNum, out n))
                {
                    num = (long)n;
                }
            }
            else
            {
                Regex regex = new Regex(ThreeDigitBlockPattern());
                foreach (Match m in regex.Matches(str))
                {
                    foreach (Capture c in m.Groups[ONES_NAME].Captures)
                    {
                        if (PersianLiteral2NumMap.TryPersianString2Num(c.Value, out tempNum))
                        {
                            num += tempNum;
                        }
                    }

                    foreach (Capture c in m.Groups[TENS_NAME].Captures)
                    {
                        if (PersianLiteral2NumMap.TryPersianString2Num(c.Value, out tempNum))
                        {
                            num += tempNum;
                        }
                    }

                    foreach (Capture c in m.Groups[TENONES_NAME].Captures)
                    {
                        if (PersianLiteral2NumMap.TryPersianString2Num(c.Value, out tempNum))
                        {
                            num += tempNum;
                        }
                    }

                    num += ExtractHundreds(m);
                }
            }
            return(num);
        }