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


C# Question.GetToken方法代码示例

本文整理汇总了C#中Question.GetToken方法的典型用法代码示例。如果您正苦于以下问题:C# Question.GetToken方法的具体用法?C# Question.GetToken怎么用?C# Question.GetToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Question的用法示例。


在下文中一共展示了Question.GetToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetAnswer

 public Answer GetAnswer(Question question)
 {
     var cityToken = question.GetToken<CityToken>();
     var dateToken = question.GetToken<DateToken>();
     int? year = null;
     if (dateToken != null) year = dateToken.Year;
     DaylightSavingInformation daylightSavingInfo;
     if (year.HasValue)
     {
         var firstDateInTheYear = new LocalDateTime(year.Value, 1, 1, 0, 0).InZone(DateTimeZoneProviders.Tzdb[cityToken.City.Timezone], Resolvers.LenientResolver);
         var firstZoneIntervalInTheYear = firstDateInTheYear.GetZoneInterval();
         if (firstZoneIntervalInTheYear.IsoLocalEnd.Year > 10000) {
             daylightSavingInfo = DaylightSavingInformation.CreateWithNoDaylightSavings();
         }
         else
         {
             var firstDateInTheNextZoneInterval = firstDateInTheYear.Plus(firstZoneIntervalInTheYear.Duration).Plus(Duration.FromMilliseconds(1));
             daylightSavingInfo = GetDaylightSavingInfo(firstDateInTheNextZoneInterval);
         }
     }
     else
     {
         daylightSavingInfo = GetDaylightSavingInfo(cityToken.GetCurrentTime());
     }
     var answerText = GetFormattedDaylightSavingInfo(daylightSavingInfo, cityToken.City);
     return new Answer(question, true, true, answerText);
 }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:27,代码来源:WhenDaylightSavingsStartStopInCityQuestionHandler.cs

示例2: LiteralDateOrTimeTokenizer_should_find_all_occurrences_of_time

        public void LiteralDateOrTimeTokenizer_should_find_all_occurrences_of_time()
        {
            var question = new Question("what time is it");
            var token = question.GetToken<LiteralDateOrTimeToken>();
            Assert.AreEqual("time", token.Value);

            question = new Question("what's the time and another time here");
            token = question.GetToken<LiteralDateOrTimeToken>();
            Assert.AreEqual("time", token.Value);
            token = question.GetToken<LiteralDateOrTimeToken>(2);
            Assert.AreEqual("time", token.Value);

            question = new Question("time in new york");
            token = question.GetToken<LiteralDateOrTimeToken>();
            Assert.AreEqual("time", token.Value);
        }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:16,代码来源:LiteralDateOrTimeTokenizer_Test.cs

示例3: WhenDaylightSavingsStartStopInCityQuestionHandler_should_answer_when_asking_for_dst

 public void WhenDaylightSavingsStartStopInCityQuestionHandler_should_answer_when_asking_for_dst()
 {
     var question = new Question("DST time in London");
     var handler = new WhenDaylightSavingInCityQuestionHandler();
     Assert.IsNotNull(question.GetToken<DaylightSavingsToken>());
     Assert.IsTrue(handler.CanAnswerQuestion(question));
 }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:7,代码来源:WhenDaylightSavingsStartStopInCityQuestionHandler_Test.cs

示例4: Question

 public void WhenDaylightSavingsStartStopInCityQuestionHandler_should_answer_question_only_if_a_city_token_is_found()
 {
     var question = new Question("When does daylight savings start");
     var handler = new WhenDaylightSavingInCityQuestionHandler();
     Assert.IsNull(question.GetToken<CityToken>());
     Assert.IsFalse(handler.CanAnswerQuestion(question));
 }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:7,代码来源:WhenDaylightSavingsStartStopInCityQuestionHandler_Test.cs

示例5: GetAnswerToWhatTimeInCity

 private Answer GetAnswerToWhatTimeInCity(Question question)
 {
     CityOrTimezoneToken  cityOrTimezoneToken = question.GetToken<CityOrTimezoneToken >();
     var answerText = String.Format("The current time in {0} is {1}.",
                                     cityOrTimezoneToken.GetFormattedNameAndTimezone(cityOrTimezoneToken.GetCurrentTimeAsOffsetDateTime().ToInstant()),
                                     cityOrTimezoneToken.GetCurrentTimeAsOffsetDateTime().LocalDateTime.GetFormattedTimeAndDate());
     return new Answer(question, true, true, answerText);
 }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:8,代码来源:WhatTimeInCityQuestionHandler.cs

示例6: LiteralDateOrTimeTokenizer_should_find_all_occurrences_of_date

        public void LiteralDateOrTimeTokenizer_should_find_all_occurrences_of_date()
        {
            var question = new Question("what date is it in vancouver");
            var token = question.GetToken<LiteralDateOrTimeToken>();
            Assert.AreEqual("date", token.Value);

            question = new Question("date in new york");
            token = question.GetToken<LiteralDateOrTimeToken>();
            Assert.AreEqual("date", token.Value);
        }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:10,代码来源:LiteralDateOrTimeTokenizer_Test.cs

示例7: TimeTokenizer_should_find_all_occurrences_of_abbreviations

        public void TimeTokenizer_should_find_all_occurrences_of_abbreviations()
        {
            var question = new Question("when its noon in Sydney");
            var token = question.GetToken<TimeToken>();
            Assert.AreEqual("noon", token.Value);
            Assert.AreEqual(12, token.Hour);
            Assert.AreEqual(null, token.Minute);
            Assert.AreEqual(Meridiem.PM, token.Meridiem);

            question = new Question("when its midday in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("midday", token.Value);
            Assert.AreEqual(12, token.Hour);
            Assert.AreEqual(null, token.Minute);
            Assert.AreEqual(Meridiem.PM, token.Meridiem);

            question = new Question("when its mid-day  in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("mid-day", token.Value);
            Assert.AreEqual(12, token.Hour);
            Assert.AreEqual(null, token.Minute);
            Assert.AreEqual(Meridiem.PM, token.Meridiem);

            question = new Question("when its mid day in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("mid day", token.Value);
            Assert.AreEqual(12, token.Hour);
            Assert.AreEqual(null, token.Minute);
            Assert.AreEqual(Meridiem.PM, token.Meridiem);

            question = new Question("when its midnight in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("midnight", token.Value);
            Assert.AreEqual(12, token.Hour);
            Assert.AreEqual(null, token.Minute);
            Assert.AreEqual(Meridiem.AM, token.Meridiem);

            question = new Question("when its mid-night  in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("mid-night", token.Value);
            Assert.AreEqual(12, token.Hour);
            Assert.AreEqual(null, token.Minute);
            Assert.AreEqual(Meridiem.AM, token.Meridiem);

            question = new Question("when its mid night in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("mid night", token.Value);
            Assert.AreEqual(12, token.Hour);
            Assert.AreEqual(null, token.Minute);
            Assert.AreEqual(Meridiem.AM, token.Meridiem);
        }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:51,代码来源:TimeTokenizer_Test.cs

示例8: DateTokenizer_should_find_all_occurrences_of_hyphenated_dates

        public void DateTokenizer_should_find_all_occurrences_of_hyphenated_dates()
        {
            var question = new Question("its 4/24/2012 in Sydney");
            var token = question.GetToken<DateToken>();
            Assert.AreEqual("4/24/2012", token.Value);
            Assert.AreEqual (24, token.Day);
            Assert.AreEqual (4, token.Month);
            Assert.AreEqual (2012, token.Year);

            question = new Question("its 4/24/12 in Sydney");
            token = question.GetToken<DateToken>();
            Assert.AreEqual("4/24/12", token.Value);
            Assert.AreEqual (24, token.Day);
            Assert.AreEqual (4, token.Month);
            Assert.AreEqual (2012, token.Year);

            question = new Question("its 4-24-12 in Sydney");
            token = question.GetToken<DateToken>();
            Assert.AreEqual("4-24-12", token.Value);
            Assert.AreEqual (24, token.Day);
            Assert.AreEqual (4, token.Month);
            Assert.AreEqual (2012, token.Year);

            question = new Question("its 4-24-2012 in Sydney");
            token = question.GetToken<DateToken>();
            Assert.AreEqual("4-24-2012", token.Value);
            Assert.AreEqual (24, token.Day);
            Assert.AreEqual (4, token.Month);
            Assert.AreEqual (2012, token.Year);

            question = new Question("its 24-4-2012 in Sydney");
            token = question.GetToken<DateToken>();
            Assert.AreEqual("24-4-2012", token.Value);
            Assert.AreEqual (24, token.Day);
            Assert.AreEqual (4, token.Month);
            Assert.AreEqual (2012, token.Year);

            question = new Question("its 24/4/2012 in Sydney");
            token = question.GetToken<DateToken>();
            Assert.AreEqual("24/4/2012", token.Value);
            Assert.AreEqual (24, token.Day);
            Assert.AreEqual (4, token.Month);
            Assert.AreEqual (2012, token.Year);

            question = new Question("its 24/4/12 in Sydney");
            token = question.GetToken<DateToken>();
            Assert.AreEqual("24/4/12", token.Value);
            Assert.AreEqual (24, token.Day);
            Assert.AreEqual (4, token.Month);
            Assert.AreEqual (2012, token.Year);
        }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:51,代码来源:DateTokenizer_Test.cs

示例9: TimezoneTokenizer_should_find_all_occurrences

        public void TimezoneTokenizer_should_find_all_occurrences()
        {
            var question = new Question("time in AEST");
            var token = question.GetToken<TimezoneToken>();
            Assert.AreEqual("AEST", token.Value);

            question = new Question("whats the time in pacific time");
            token = question.GetToken<TimezoneToken>();
            Assert.AreEqual("pacific time", token.Value);

            question = new Question("whats the time in ET if its 4pm in Sydney");
            token = question.GetToken<TimezoneToken>();
            Assert.AreEqual("ET", token.Value);
        }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:14,代码来源:TimezoneTokenizer_Test.cs

示例10: CityTokenizer_should_find_all_occurrences_of_the_city

        public void CityTokenizer_should_find_all_occurrences_of_the_city()
        {
            var question = new Question("what time is it in Melbourne");
            var token = question.GetToken<CityToken>();
            Assert.AreEqual("Melbourne", token.Value);

            question = new Question("whats the time in New England, USA");
            token = question.GetToken<CityToken>();
            Assert.AreEqual("New England, USA", token.Value);

            question = new Question("when its the 24th of April at 8pm in Sydney what time is it in Bangladesh");
            token = question.GetToken<CityToken>();
            Assert.AreEqual("Sydney", token.Value);
            token = question.GetToken<CityToken>(2);
            Assert.AreEqual("Bangladesh", token.Value);

            question = new Question("whats the time at Mexico when its the 24th of April at 7PM in New York, USA");
            token = question.GetToken<CityToken>();
            Assert.AreEqual("Mexico", token.Value);
            token = question.GetToken<CityToken>(2);
            Assert.AreEqual("New York, USA", token.Value);

            question = new Question("how many days in a year");
            Assert.IsNull(question.GetToken<CityToken>());

            question = new Question("whats the time in the Phillipines");
            token = question.GetToken<CityToken>();
            Assert.AreEqual("Phillipines", token.Value);

            question = new Question("time in the new york right now");
            token = question.GetToken<CityToken>();
            Assert.AreEqual("new york", token.Value);

            question = new Question("time in the new york now");
            token = question.GetToken<CityToken>();
            Assert.AreEqual("new york", token.Value);
        }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:37,代码来源:CityTokenizer_Test.cs

示例11: DaylightSavingsTokenizer_should_find_all_occurrences

        public void DaylightSavingsTokenizer_should_find_all_occurrences()
        {
            var question = new Question("when does daylight savings begin in New York");
            var token = question.GetToken<DaylightSavingsToken>();
            Assert.AreEqual("daylight savings", token.Value);

            question = new Question("when does daylight savings end in New York");
            token = question.GetToken<DaylightSavingsToken>();
            Assert.AreEqual("daylight savings", token.Value);

            question = new Question("when does daylight saving's end in New York");
            token = question.GetToken<DaylightSavingsToken>();
            Assert.AreEqual("daylight saving's", token.Value);

            question = new Question("when does day light savings end in New York");
            token = question.GetToken<DaylightSavingsToken>();
            Assert.AreEqual("day light savings", token.Value);

            question = new Question("when does day light saving's end in New York");
            token = question.GetToken<DaylightSavingsToken>();
            Assert.AreEqual("day light saving's", token.Value);
        }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:22,代码来源:DaylightSavingsTokenizer_Test.cs

示例12: DateTokenizer_should_find_all_occurrences_of_day_month_year_dates

        public void DateTokenizer_should_find_all_occurrences_of_day_month_year_dates()
        {
            var question = new Question("its 24-apr-12 in Sydney");
            var token = question.GetToken<DateToken>();
            Assert.AreEqual("24-apr-12", token.Value);
            Assert.AreEqual (24, token.Day);
            Assert.AreEqual (4, token.Month);
            Assert.AreEqual (2012, token.Year);

            question = new Question("its 24-apr-2012 in Sydney");
            token = question.GetToken<DateToken>();
            Assert.AreEqual("24-apr-2012", token.Value);
            Assert.AreEqual (24, token.Day);
            Assert.AreEqual (4, token.Month);
            Assert.AreEqual (2012, token.Year);

            question = new Question("its 24th of april 2012 in Sydney");
            token = question.GetToken<DateToken>();
            Assert.AreEqual("24th of april 2012", token.Value);
            Assert.AreEqual (24, token.Day);
            Assert.AreEqual (4, token.Month);
            Assert.AreEqual (2012, token.Year);

            question = new Question("its 24th april in Sydney");
            token = question.GetToken<DateToken>();
            Assert.AreEqual("24th april", token.Value);
            Assert.AreEqual (24, token.Day);
            Assert.AreEqual (4, token.Month);
            Assert.AreEqual (null, token.Year);

            question = new Question("its 24 april in Sydney");
            token = question.GetToken<DateToken>();
            Assert.AreEqual("24 april", token.Value);
            Assert.AreEqual (24, token.Day);
            Assert.AreEqual (4, token.Month);
            Assert.AreEqual (null, token.Year);
        }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:37,代码来源:DateTokenizer_Test.cs

示例13: TimeTokenizer_should_find_all_occurrences_of_known_formats

        public void TimeTokenizer_should_find_all_occurrences_of_known_formats()
        {
            var question = new Question("when its 7am in Sydney");
            var token = question.GetToken<TimeToken>();
            Assert.AreEqual("7am", token.Value);
            Assert.AreEqual (7, token.Hour);
            Assert.AreEqual (null, token.Minute);
            Assert.AreEqual (Meridiem.AM, token.Meridiem);

            question = new Question("when its 7oclock in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("7oclock", token.Value);
            Assert.AreEqual (7, token.Hour);
            Assert.AreEqual (null, token.Minute);
            Assert.AreEqual (Meridiem.NONE, token.Meridiem);

            question = new Question("when its 7 o'clock in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("7 o'clock", token.Value);
            Assert.AreEqual (7, token.Hour);
            Assert.AreEqual (null, token.Minute);
            Assert.AreEqual (Meridiem.NONE, token.Meridiem);

            question = new Question("when its 7 pm in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("7 pm", token.Value);
            Assert.AreEqual (7, token.Hour);
            Assert.AreEqual (null, token.Minute);
            Assert.AreEqual (Meridiem.PM, token.Meridiem);

            question = new Question("when its 7 p.m in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("7 p.m", token.Value);
            Assert.AreEqual(7, token.Hour);
            Assert.AreEqual(null, token.Minute);
            Assert.AreEqual(Meridiem.PM, token.Meridiem);

            question = new Question("when its 7 a.m in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("7 a.m", token.Value);
            Assert.AreEqual(7, token.Hour);
            Assert.AreEqual(null, token.Minute);
            Assert.AreEqual(Meridiem.AM, token.Meridiem);

            question = new Question("when its 7 in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("7", token.Value);
            Assert.AreEqual (7, token.Hour);
            Assert.AreEqual (null, token.Minute);
            Assert.AreEqual (Meridiem.NONE, token.Meridiem);

            question = new Question("when its 7:30am in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("7:30am", token.Value);
            Assert.AreEqual (7, token.Hour);
            Assert.AreEqual (30, token.Minute);
            Assert.AreEqual (Meridiem.AM, token.Meridiem);

            question = new Question("when its 7:30 pm in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("7:30 pm", token.Value);
            Assert.AreEqual (7, token.Hour);
            Assert.AreEqual (30, token.Minute);
            Assert.AreEqual (Meridiem.PM, token.Meridiem);

            question = new Question("when its 10:22 in Sydney");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("10:22", token.Value);
            Assert.AreEqual (10, token.Hour);
            Assert.AreEqual (22, token.Minute);
            Assert.AreEqual (Meridiem.NONE, token.Meridiem);

            question = new Question("if it is 9.00 am in india what will be the time in macau");
            token = question.GetToken<TimeToken>();
            Assert.AreEqual("9.00 am", token.Value);
            Assert.AreEqual (9, token.Hour);
            Assert.AreEqual (0, token.Minute);
            Assert.AreEqual (Meridiem.AM, token.Meridiem);

            question = new Question("on the 24th of April 2012");
            Assert.IsNull (question.GetToken<TimeToken>());
        }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:82,代码来源:TimeTokenizer_Test.cs

示例14: DateTokenizer_should_find_all_occurrences_of_year

        public void DateTokenizer_should_find_all_occurrences_of_year()
        {
            var question = new Question("how long until 2012");
            var token = question.GetToken<DateToken>();
            Assert.AreEqual("2012", token.Value);
            Assert.AreEqual (null, token.Day);
            Assert.AreEqual (null, token.Month);
            Assert.AreEqual (2012, token.Year);

            question = new Question("its 2013 in Sydney");
            token = question.GetToken<DateToken>();
            Assert.AreEqual("2013", token.Value);
            Assert.AreEqual (null, token.Day);
            Assert.AreEqual (null, token.Month);
            Assert.AreEqual (2013, token.Year);
        }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:16,代码来源:DateTokenizer_Test.cs

示例15: GetAnswerToWhenTimeInKnownCityWhatTimeInUnknownCity

 private Answer GetAnswerToWhenTimeInKnownCityWhatTimeInUnknownCity(Question question)
 {
     var knownCityOrTimezoneToken = question.GetToken<CityOrTimezoneToken >();
     var knownTimeToken = question.GetToken<TimeToken>();
     var knownDateToken = question.GetToken<DateToken>();
     var unknownCityOrTimezoneToken = question.GetToken<CityOrTimezoneToken >(2);
     return GetAnswerToTimeConversionQuestion(question, knownDateToken, knownTimeToken, knownCityOrTimezoneToken, unknownCityOrTimezoneToken);
 }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:8,代码来源:WhatTimeInCityWhenTimeInAnotherCityQuestionHandler.cs


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