Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dimension kelvin #692

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Duckling/Temperature/EN/Corpus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ allExamples = concat
[ examples (simple Celsius 37)
[ "37°C"
, "37 ° celsius"
, "37 degrees C"
, "37 degrees Celsius"
, "thirty seven celsius"
, "37 degrees Celsius"
, "thirty seven celsius"
, "thirty seven Celsius"
]
, examples (simple Fahrenheit 70)
[ "70°F"
, "70 ° Fahrenheit"
, "70 degrees F"
, "seventy Fahrenheit"
, "seventy fahrenheit"
]
, examples (simple Fahrenheit 98.6)
[ "98.6°F"
Expand All @@ -52,6 +53,13 @@ allExamples = concat
, "2 degrees below zero"
, "2 below zero"
]
, examples (simple Kelvin 44)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these examples look good, classifiers need to be regenerated

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've run
stack build :duckling-regen-exe && stack exec duckling-regen-exe && stack test

And I can parse out kelvins.

curl -XPOST http://0.0.0.0:8000/parse --data 'locale=en_GB&text=44 kelvin'        
[{"body":"44 kelvin","start":0,"value":{"value":44,"type":"value","unit":"kelvin"},"end":9,"dim":"temperature","latent":false}]
curl -XPOST http://0.0.0.0:8000/parse --data 'locale=en_GB&text=11 kelvins'
[{"body":"11 kelvins","start":0,"value":{"value":11,"type":"value","unit":"kelvin"},"end":10,"dim":"temperature","latent":false}]

The only classifier that updated was IT_XX.hs 🤷🏽 I was expecting EN_XX.hs to update.

[ "44°K"
, "44 kelvin"
, "44 kelvins"
, "fourty four kelvins"
, "44 kelvins"
]
, examples (between Degree (30, 40))
[ "between 30 and 40 degrees"
, "from 30 degrees to 40 degrees"
Expand Down
14 changes: 14 additions & 0 deletions Duckling/Temperature/EN/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ ruleTemperatureFahrenheit = Rule
_ -> Nothing
}

ruleTemperatureKelvin :: Rule
ruleTemperatureKelvin = Rule
{ name = "<temp> Kelvin"
, pattern =
[ Predicate $ isValueOnly True
, regex "k(el?vi?n?s?)?\\.?"
ofhope marked this conversation as resolved.
Show resolved Hide resolved
]
, prod = \case
(Token Temperature td:_) -> Just . Token Temperature $
withUnit TTemperature.Kelvin td
_ -> Nothing
}

ruleTemperatureBelowZero :: Rule
ruleTemperatureBelowZero = Rule
{ name = "<temp> below zero"
Expand Down Expand Up @@ -153,6 +166,7 @@ rules =
[ ruleTemperatureDegrees
, ruleTemperatureCelsius
, ruleTemperatureFahrenheit
, ruleTemperatureKelvin
, ruleTemperatureBelowZero
, ruleIntervalBetween
, ruleIntervalDash
Expand Down
2 changes: 1 addition & 1 deletion Duckling/Temperature/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import qualified Data.Text as Text
import Duckling.Resolve (Resolve(..))

data TemperatureUnit =
Degree | Celsius | Fahrenheit
Degree | Celsius | Fahrenheit | Kelvin
deriving (Eq, Generic, Hashable, Show, Ord, NFData)

instance ToJSON TemperatureUnit where
Expand Down