public static ParserContext CreateParserContext(string text, ParserPattern pattern) { ParserContext pc = new ParserContext(); pc.Pattern = pattern; pc.Text = text; return pc; }
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; }
ParseResultCollection ParsePhoneNo(string text) { ParserContext context = new ParserContext(); context.Text = text; return ParseResultCollection.InternalParse(text, new PhoneNoParser(context)); }
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)); }
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; }
public ParserContext Clone() { ParserContext pc = new ParserContext(); pc.Text = this.Text; return pc; }
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)); }
public PostalCodeParser(ParserContext context) { this.context = context; }
public USAddressParser(ParserContext context) { this.context = context; }
public VerbParser(ParserContext context) { this.context = context; }