当前位置: 首页>>代码示例>>C#>>正文


C# Question.AddToken方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:25,代码来源:TimezoneTokenizer.cs

示例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);
            }
        }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:25,代码来源:CityTokenizer.cs

示例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);
     }
 }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:10,代码来源:LiteralDateOrTimeTokenizer.cs

示例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);
     }
 }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:12,代码来源:DaylightSavingsTokenizer.cs


注:本文中的Question.AddToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。