本文整理汇总了C#中Question.AddToken方法的典型用法代码示例。如果您正苦于以下问题:C# Question.AddToken方法的具体用法?C# Question.AddToken怎么用?C# Question.AddToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Question
的用法示例。
在下文中一共展示了Question.AddToken方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TokenizeTheQuestion
public void TokenizeTheQuestion(Question question)
{
var timezoneRegex = new StringBuilder();
timezoneRegex.Append("(");
var isFirstIteration = true;
foreach (var timezone in Timezones.GetAllTimezones())
{
if (!isFirstIteration)
timezoneRegex.Append("|");
if(timezone.TokenizeOnAbbreviation)
timezoneRegex.Append(String.Format("{0}|{1}", timezone.Name, timezone.Abbreviation));
else
timezoneRegex.Append(timezone.Name);
isFirstIteration = false;
}
timezoneRegex.Append(")");
var matches = Regex.Matches(question.QuestionText, @"(^|\s)" + timezoneRegex.ToString() + @"(\s|$|,)", RegexOptions.IgnoreCase);
foreach (Match match in matches)
{
Group group = match.Groups[0];
var token = new TimezoneToken(group.Value, group.Index);
question.AddToken(token);
}
}
示例2: TokenizeTheQuestion
public void TokenizeTheQuestion(Question question)
{
var matches = Regex.Matches(question.QuestionText, @"(^|\s)(in|at)\s(the\s)?", RegexOptions.IgnoreCase);
foreach (Match match in matches)
{
Group group = match.Groups[0];
var startPosition = (group.Index + group.Length );
var cityName = question.QuestionText.Substring(startPosition);
var endPosition = question.QuestionText.Length;
var possibleEarlierTerminations = Regex.Matches(cityName, @"(^|\s)(when|what('?s?)|\d|(on|in|at|a|right|now|if|then|\?)(\s|$))", RegexOptions.IgnoreCase);
if(possibleEarlierTerminations.Count > 0)
{
Group terminationGroup = GetEarlierOccurrenceOfGroup(possibleEarlierTerminations);
endPosition = startPosition + terminationGroup.Index;
}
cityName = question.QuestionText.Substring(startPosition, endPosition - startPosition);
if(cityName.Replace(" ","").Length == 0) continue;
var tokenResult = new CityToken(cityName, startPosition);
question.AddToken(tokenResult);
}
}
示例3: TokenizeTheQuestion
public void TokenizeTheQuestion(Question question)
{
var matches = Regex.Matches(question.QuestionText, @"(^|\s)(date|time)(\s|$)", RegexOptions.IgnoreCase);
foreach (Match match in matches)
{
Group group = match.Groups[0];
var token = new LiteralDateOrTimeToken(group.Value, group.Index);
question.AddToken(token);
}
}
示例4: TokenizeTheQuestion
public void TokenizeTheQuestion(Question question)
{
var daylightSavingsTimeRegex = @"(day(\s)?light)\ssaving('s|s)?\s(time('s|s)?)?";
var dstRegex = @"dst(\stime)?\s";
var matches = Regex.Matches(question.QuestionText, string.Format(@"(^|\s)({0})|({1})", daylightSavingsTimeRegex, dstRegex), RegexOptions.IgnoreCase);
foreach (Match match in matches)
{
Group group = match.Groups[0];
var token = new DaylightSavingsToken(group.Value, group.Index);
question.AddToken(token);
}
}