diff --git a/CHANGELOG.md b/CHANGELOG.md index cd03d1ce..e4e5df04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * EN (English) * Time: Allow latent match for \ \ * Time: Avoid parsing phrases like 'two five' as times + * Time: Add support to parse spelled-out times like 'five-thirty' * RU (Russian) * Duration: Diminutives for minutes and hours diff --git a/Duckling/Time/EN/Corpus.hs b/Duckling/Time/EN/Corpus.hs index 53be6233..9fc98ccf 100644 --- a/Duckling/Time/EN/Corpus.hs +++ b/Duckling/Time/EN/Corpus.hs @@ -132,6 +132,7 @@ latentCorpus = (testContext, testOptions {withLatent = True}, xs) ] , examples (datetime (2013, 2, 12, 10, 30, 0) Minute) [ "ten thirty" + , "ten-thirty" ] , examples (datetime (1974, 1, 1, 0, 0, 0) Year) [ "1974" @@ -163,6 +164,8 @@ latentCorpus = (testContext, testOptions {withLatent = True}, xs) , "twelve o three" , "twelve ou three" , "twelve oh three" + , "twelve-zero-three" + , "twelve-oh-three" ] , examples (datetimeInterval ((1960, 1, 1, 0, 0, 0), (1962, 1, 1, 0, 0, 0)) Year) [ "1960 - 1961" diff --git a/Duckling/Time/EN/Rules.hs b/Duckling/Time/EN/Rules.hs index 3d927d84..b1e7fca7 100644 --- a/Duckling/Time/EN/Rules.hs +++ b/Duckling/Time/EN/Rules.hs @@ -780,6 +780,26 @@ ruleHONumeral = Rule _ -> Nothing } +ruleHONumeralDash :: Rule +ruleHONumeralDash = Rule + { name = " - " + , pattern = + [ Predicate isAnHourOfDay + , regex "-(?!\\d)" + , Predicate $ isIntegerBetween 10 59 + ] + , prod = \tokens -> case tokens of + (Token Time TimeData{TTime.form = Just (TTime.TimeOfDay (Just hours) is12H) + ,TTime.latent = isLatent}: + _: + token: + _) -> do + n <- getIntValue token + let lt = if isLatent then mkLatent else id + tt $ lt $ hourMinute is12H hours n + _ -> Nothing + } + ruleHONumeralAlt :: Rule ruleHONumeralAlt = Rule { name = " zero " @@ -803,6 +823,30 @@ ruleHONumeralAlt = Rule _ -> Nothing } +ruleHONumeralAltDash :: Rule +ruleHONumeralAltDash = Rule + { name = " - zero - " + , pattern = + [ Predicate isAnHourOfDay + , regex "-" + , regex "(zero|o(h|u)?)" + , regex "-(?!\\d)" + , Predicate $ isIntegerBetween 1 9 + ] + , prod = \case + ( + Token Time TimeData{TTime.form = Just (TTime.TimeOfDay + (Just hours) is12H) + , TTime.latent = isLatent}: + _:_:_: + token: + _) -> do + n <- getIntValue token + let lt = if isLatent then mkLatent else id + tt $ lt $ hourMinute is12H hours n + _ -> Nothing + } + ruleHODHalf :: Rule ruleHODHalf = Rule { name = " half" @@ -2729,7 +2773,9 @@ rules = , ruleMilitarySpelledOutAMPM2 , ruleTODAMPM , ruleHONumeral + , ruleHONumeralDash , ruleHONumeralAlt + , ruleHONumeralAltDash , ruleHODHalf , ruleHODQuarter , ruleNumeralToHOD