Esempio n. 1
0
 public static ParserContext CreateParserContext(string text, ParserPattern pattern)
 {
     ParserContext pc = new ParserContext();
     pc.Pattern = pattern;
     pc.Text = text;
     return pc;
 }
Esempio n. 2
0
        public ParseResultCollection Recognize(string text, ParserPattern pattern)
        {
            ParserContext context = new ParserContext();
            context.Pattern = pattern;
            context.Text = text;

            ParseResultCollection result = new ParseResultCollection();

            char[] chars = text.ToCharArray();

            int i = 0;

            while (i < chars.Length)
            {
                char c = chars[i];

                if (CharacterUtil.IsChinesePunctuation(c))
                {
                    i++;
                    continue;
                }
                bool isFound = false;
                //扫描地名(优先于姓名,用于排除不正确人名)
                foreach (ConstructorInfo ci in parserConstructors)
                {
                    IParser parser = ci.Invoke(new object[] { context }) as IParser;

                    try
                    {
                        ParseResultCollection prc = parser.Parse(i);

                        if (prc.Count > 0)
                        {
                            foreach (ParseResult pr in prc)
                            {
                                result.Add(pr);
                                i += pr.Length;
                            }
                            isFound = true;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }

                    if (!isFound)
                    {
                        i++;
                    }
                }
            }
            return result;
        }
Esempio n. 3
0
 ParseResultCollection ParsePhoneNo(string text)
 {
     ParserContext context = new ParserContext();
     context.Text = text;
     return ParseResultCollection.InternalParse(text, new PhoneNoParser(context));
 }
Esempio n. 4
0
 public EnglishDateTimeParser(ParserContext context)
 {
     this.context = context;
 }
 ParseResultCollection ParseChineseDateTime(string text)
 {
     ParserContext context = new ParserContext();
     context.Text = text;
     return ParseResultCollection.InternalParse(text, new SimChineseDateTimeParser(context));
 }
Esempio n. 6
0
 public PhoneNoParser(ParserContext context)
 {
     this.context = context;
 }
 public SimChineseQuantityParser(ParserContext context)
 {
     this.context = context;
     //this._text = NumeralUtil.ConvertChineseNumeral2Arabic(text);    //TODO::考虑在NEParser中一次性转换所有数字
 }
 public SimChinesePronounParser(ParserContext context)
 {
     this.context = context;
 }
Esempio n. 9
0
 public ParserContext Clone()
 {
     ParserContext pc = new ParserContext();
     pc.Text = this.Text;
     return pc;
 }
Esempio n. 10
0
 public SimChineseDateTimeParser(ParserContext context)
 {
     this.context = context;
 }
 //[Test]
 //public void FriBeforeLast()
 //{
 //    VerifyParse("fri before last fri",new DateTime(2008,2,1));
 //}
 //wed before last
 //years
 //next week
 //last week
 private void VerifyParse(string dateString, DateTime expectedDateTime)
 {
     ParserContext context = new ParserContext();
     EnglishDateTimeParser parser=new EnglishDateTimeParser(context);
     Assert.AreEqual(expectedDateTime, parser.ParseRelative(this.timeBase, dateString));
 }
Esempio n. 12
0
 public PostalCodeParser(ParserContext context)
 {
     this.context = context;
 }
Esempio n. 13
0
 public USAddressParser(ParserContext context)
 {
     this.context = context;
 }
Esempio n. 14
0
 public VerbParser(ParserContext context)
 {
     this.context = context;
 }