EN/FR support temperature with decimal values (#408)

Summary:
Allowing the support of decimal values like in human body temperature. Example: 98.6°F
Pull Request resolved: https://github.com/facebook/duckling/pull/408

Reviewed By: girifb

Differential Revision: D17401806

Pulled By: patapizza

fbshipit-source-id: f04b768e2f6cb48c9c50977a5807d62e38f8d545
This commit is contained in:
l5t 2019-09-17 10:20:53 -07:00 committed by Facebook Github Bot
parent 1fa17b01d4
commit de8af2395d
4 changed files with 21 additions and 16 deletions

View File

@ -36,6 +36,11 @@ allExamples = concat
, "70 degrees F"
, "seventy Fahrenheit"
]
, examples (simple Fahrenheit 98.6)
[ "98.6°F"
, "98.6 ° Fahrenheit"
, "98.6 degrees F"
]
, examples (simple Degree 45)
[ "45°"
, "45 degrees"

View File

@ -55,21 +55,21 @@ isSimpleTemperature _ = False
withUnit :: TTemperature.TemperatureUnit -> TemperatureData -> TemperatureData
withUnit u td = td {TTemperature.unit = Just u}
withInterval :: (Int, Int) -> TemperatureData -> TemperatureData
withInterval :: (Double, Double) -> TemperatureData -> TemperatureData
withInterval (from, to) td = td
{ TTemperature.value = Nothing
, TTemperature.minValue = Just from
, TTemperature.maxValue = Just to
}
withValue :: Int -> TemperatureData -> TemperatureData
withValue :: Double -> TemperatureData -> TemperatureData
withValue v td = td
{ TTemperature.value = Just v
, TTemperature.minValue = Nothing
, TTemperature.maxValue = Nothing
}
valueOnly :: Int -> TemperatureData
valueOnly :: Double -> TemperatureData
valueOnly v = TemperatureData
{ TTemperature.unit = Nothing
, TTemperature.value = Just v
@ -85,14 +85,14 @@ unitOnly u = TemperatureData
, TTemperature.maxValue = Nothing
}
withMax :: Int -> TemperatureData -> TemperatureData
withMax :: Double -> TemperatureData -> TemperatureData
withMax v td = td
{ TTemperature.value = Nothing
, TTemperature.minValue = Nothing
, TTemperature.maxValue = Just v
}
withMin :: Int -> TemperatureData -> TemperatureData
withMin :: Double -> TemperatureData -> TemperatureData
withMin v td = td
{ TTemperature.value = Nothing
, TTemperature.minValue = Just v

View File

@ -31,7 +31,7 @@ ruleNumeralAsTemp = Rule
]
, prod = \case
(Token Numeral nd:_) ->
Just . Token Temperature $ valueOnly $ floor $ TNumeral.value nd
Just . Token Temperature $ valueOnly $ TNumeral.value nd
_ -> Nothing
}

View File

@ -34,9 +34,9 @@ instance ToJSON TemperatureUnit where
data TemperatureData = TemperatureData
{ unit :: Maybe TemperatureUnit
, value :: Maybe Int
, minValue :: Maybe Int
, maxValue :: Maybe Int
, value :: Maybe Double
, minValue :: Maybe Double
, maxValue :: Maybe Double
} deriving (Eq, Generic, Hashable, Show, Ord, NFData)
instance Resolve TemperatureData where
@ -58,7 +58,7 @@ data IntervalDirection = Above | Under
data SingleValue = SingleValue
{ vUnit :: TemperatureUnit
, vValue :: Int
, vValue :: Double
}
deriving (Eq, Show)
@ -95,22 +95,22 @@ instance ToJSON TemperatureValue where
-- -----------------------------------------------------------------
-- Value helpers
simple :: TemperatureUnit -> Int -> TemperatureValue
simple :: TemperatureUnit -> Double -> TemperatureValue
simple u v = SimpleValue $ single u v
between :: TemperatureUnit -> (Int, Int) -> TemperatureValue
between :: TemperatureUnit -> (Double, Double) -> TemperatureValue
between u (from, to) = IntervalValue (single u from, single u to)
above :: TemperatureUnit -> Int -> TemperatureValue
above :: TemperatureUnit -> Double -> TemperatureValue
above = openInterval Above
under :: TemperatureUnit -> Int -> TemperatureValue
under :: TemperatureUnit -> Double -> TemperatureValue
under = openInterval Under
openInterval :: IntervalDirection -> TemperatureUnit -> Int -> TemperatureValue
openInterval :: IntervalDirection -> TemperatureUnit -> Double -> TemperatureValue
openInterval direction u v = OpenIntervalValue (single u v, direction)
single :: TemperatureUnit -> Int -> SingleValue
single :: TemperatureUnit -> Double -> SingleValue
single u v = SingleValue {vUnit = u, vValue = v}
unitsAreCompatible :: Maybe TemperatureUnit -> TemperatureUnit -> Bool