mirror of
https://github.com/facebook/duckling.git
synced 2024-09-11 21:27:13 +03:00
Fixed the problem with parsing fractional hour phrase that contains "quarter" or "quarters" (#485)
Summary: Current: if the fractional hour expression describes the hour fraction with term like "quarter or quarters", then duckling couldn't correctly recognize it. Expected: Duckling should be able to identify this kind of expression and parse it correctly. Fix: Add new rule to parse the fractional hour pattern that contains the keyword like "quarter or quarters". Pull Request resolved: https://github.com/facebook/duckling/pull/485 Test Plan: Imported from GitHub, without a Test Plan: line. Reviewed By: haoxuany Differential Revision: D21850804 Pulled By: chinmay87 fbshipit-source-id: 818b7b3f37e3f8a6d1a7d579db19fb2cfb2763f4
This commit is contained in:
parent
220c0f2d7d
commit
558b38c1cb
@ -87,10 +87,20 @@ allExamples = concat
|
||||
, "1 hour and thirty"
|
||||
, "1.5 hours"
|
||||
, "1.5 hrs"
|
||||
, "one and two quarter hour"
|
||||
, "one and two quarters hour"
|
||||
, "one and two quarter of hour"
|
||||
, "one and two quarters of hour"
|
||||
]
|
||||
, examples (DurationData 75 Minute)
|
||||
[ "1 hour fifteen"
|
||||
, "1 hour and fifteen"
|
||||
, "one and quarter hour"
|
||||
, "one and a quarter hour"
|
||||
, "one and one quarter hour"
|
||||
, "one and quarter of hour"
|
||||
, "one and a quarter of hour"
|
||||
, "one and one quarter of hour"
|
||||
]
|
||||
, examples (DurationData 130 Minute)
|
||||
[ "2 hours ten"
|
||||
@ -120,6 +130,20 @@ allExamples = concat
|
||||
, "five and half min"
|
||||
, "5 and an half minute"
|
||||
]
|
||||
, examples (DurationData 105 Minute)
|
||||
[ "one and three quarter hour"
|
||||
, "one and three quarters hour"
|
||||
, "one and three quarter of hour"
|
||||
, "one and three quarters of hour"
|
||||
, "one and three quarter of hours"
|
||||
, "one and three quarters of hours"
|
||||
]
|
||||
, examples (DurationData 135 Minute)
|
||||
[ "two and quarter hour"
|
||||
, "two and a quarter of hour"
|
||||
, "two and quarter of hours"
|
||||
, "two and a quarter of hours"
|
||||
]
|
||||
, examples (DurationData 105 Minute)
|
||||
[ "an hour and 45 minutes"
|
||||
, "one hour and 45 minutes"
|
||||
|
@ -268,7 +268,29 @@ ruleDurationDotNumeralMinutes = Rule
|
||||
mm <- parseInteger m
|
||||
ss <- parseInteger s
|
||||
let sden = 10 ^ Text.length s
|
||||
Just . Token Duration $ secondsFromHourMixedFraction mm ss sden
|
||||
Just $ Token Duration $ secondsFromHourMixedFraction mm ss sden
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDurationNumeralAndQuarterHour :: Rule
|
||||
ruleDurationNumeralAndQuarterHour = Rule
|
||||
{ name = "<Integer> and <Integer> quarter of hour"
|
||||
, pattern =
|
||||
[ Predicate isNatural
|
||||
, regex "and (a |an |one |two |three )?quarters?( of)?( an)?"
|
||||
, Predicate $ isGrain TG.Hour
|
||||
]
|
||||
, prod = \case
|
||||
(Token Numeral NumeralData{TNumeral.value = h}:
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> do
|
||||
q <- case Text.strip $ Text.toLower match of "a" -> Just 1
|
||||
"an" -> Just 1
|
||||
"one" -> Just 1
|
||||
"two" -> Just 2
|
||||
"three" -> Just 3
|
||||
_ -> Just 1
|
||||
Just . Token Duration . duration TG.Minute $ 15 * q + 60 * floor h
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -293,4 +315,5 @@ rules =
|
||||
, ruleCompositeDurationAnd
|
||||
, ruleCompositeDurationCommasAnd
|
||||
, ruleDurationDotNumeralMinutes
|
||||
, ruleDurationNumeralAndQuarterHour
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user