mirror of
https://github.com/facebook/duckling.git
synced 2024-09-11 21:27:13 +03:00
Fixed a problem with paring fractional time phrase for hours and minutes. (#483)
Summary: Current behavior: "an hour and 45 minutes" -> parsed as "1 hour" [dimension: "Duration"] "a minute and 30 seconds" ->parsed as "1 minute" [dimension: "Duration"] Expected behavior: "an hour and 45 minutes" -> "105 minutes" with dimension as "Duration" "a minute and 30 seconds" -> "90 seconds" with dimension as "Duration" The fix: adding new rule to handle this duration composition pattern. (<some duration> and <some other duration>) Pull Request resolved: https://github.com/facebook/duckling/pull/483 Reviewed By: haoxuany Differential Revision: D21850773 Pulled By: chinmay87 fbshipit-source-id: 62eb6859e0ce2b88cf8ae48d836a1a6a1ac8705d
This commit is contained in:
parent
1dac46a8ce
commit
4cfe88ead1
@ -120,4 +120,14 @@ allExamples = concat
|
||||
, "five and half min"
|
||||
, "5 and an half minute"
|
||||
]
|
||||
, examples (DurationData 105 Minute)
|
||||
[ "an hour and 45 minutes"
|
||||
, "one hour and 45 minutes"
|
||||
]
|
||||
, examples (DurationData 90 Second)
|
||||
[ "a minute and 30 seconds"
|
||||
, "one minute and 30 seconds"
|
||||
]
|
||||
, examples (DurationData 3630 Second)
|
||||
[ "an hour and 30 seconds"]
|
||||
]
|
||||
|
@ -240,9 +240,26 @@ ruleCompositeDuration = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleCompositeDurationAnd :: Rule
|
||||
ruleCompositeDurationAnd = Rule
|
||||
{ name = "composite <duration> and <duration>"
|
||||
, pattern =
|
||||
[ dimension Duration
|
||||
, regex ",|and"
|
||||
, dimension Duration
|
||||
]
|
||||
, prod = \case
|
||||
(Token Duration DurationData{TDuration.value = v, TDuration.grain = g}:
|
||||
_:
|
||||
Token Duration dd@DurationData{TDuration.grain = dg}:
|
||||
_) | g > dg -> Just . Token Duration $ duration g (v) <> dd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDurationQuarterOfAnHour
|
||||
[ ruleCompositeDurationCommasAnd
|
||||
, ruleDurationQuarterOfAnHour
|
||||
, ruleDurationHalfAnHourAbbrev
|
||||
, ruleDurationThreeQuartersOfAnHour
|
||||
, ruleDurationFortnight
|
||||
@ -257,5 +274,5 @@ rules =
|
||||
, ruleDurationPrecision
|
||||
, ruleNumeralQuotes
|
||||
, ruleCompositeDuration
|
||||
, ruleCompositeDurationCommasAnd
|
||||
, ruleCompositeDurationAnd
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user