Comments (8)
Hey @nsanthanam
You can provide the reference time in the context, when calling parse.
Here's an example:
module Duckling.TimezoneExample
( parseText ) where
import Data.Text (Text)
import Duckling.Core
import Duckling.Data.TimeZone
parseText :: Text -> Text -> Lang -> IO [Entity]
parseText text tz lang = do
tzs <- loadTimeZoneSeries "/usr/share/zoneinfo/"
refTime <- currentReftime tzs tz
let
context = Context
{ referenceTime = refTime
, lang = lang
}
return $ parse text context [This Time]
Now if we did parseText "in 2 minutes" "UTC" EN
You will get
[Entity {dim = "time", body = "in 2 minutes", value = Object (fromList [("values",Array [Object (fromList [("value",String "2017-09-01T19:51:15.246+00:00"),("grain",String "second"),("type",String "value")])]),("value",String "2017-09-01T19:51:15.246+00:00"),("grain",String "second"),("type",String "value")]), start = 0, end = 12}]
from duckling.
Excellent thanks for the feedback, I was wondering why the code didn't work. From what you're saying, I can do something like:
parseText :: Text -> Text -> Locale -> IO [Entity]
parseText text tz locale = do
tzs <- loadTimeZoneSeries "/usr/share/zoneinfo/"
refTime <- currentReftime tzs tz
let
context = Context
{ referenceTime = refTime
, locale = locale
}
return $ parse text context [This Time]
Here I'm assuming that locale
is of type Locale
rather than constructing Locale
from lang
and region
. Is this correct?
How would I have to change my input to reflect this?
Thanks so much for all the help so far, really appreciate it.
from duckling.
HI @stopachka, I compiled the code that you provided using :l parseText.hs
(where parseText.hs
is the filename, stored in the Duckling
directory) in the stack
repl (loaded with stack repl --no-load
) and I see the following error:
[316 of 319] Compiling Duckling.Rules ( /Users/navaneethan/Documents/freshML/duckling/Duckling/Rules.hs, interpreted )
[317 of 319] Compiling Duckling.Api ( /Users/navaneethan/Documents/freshML/duckling/Duckling/Api.hs, interpreted )
[318 of 319] Compiling Duckling.Core ( /Users/navaneethan/Documents/freshML/duckling/Duckling/Core.hs, interpreted )
[319 of 319] Compiling Duckling.TimezoneExample ( parseText.hs, interpreted )
parseText.hs:16:9: error: Not in scope: βlangβ
Failed, modules loaded: Duckling.AmountOfMoney.BG.Rules, ...
...
...
It appears that the line , lang = lang
(line 16) is causing the problem, but I don't understand Haskell well at all, so I'm not sure.
Could you help understand what the issue is?
Steps followed:
MacBook-Pro-4:Duckling navaneethan$ stack repl --no-load
Prelude> :l parseText.hs
from duckling.
Hi @stopachka, I think I've managed to figure out the issue and wanted to see if this was the right way to fix it.
module Duckling.TimezoneExample
( parseText ) where
import Data.Text (Text)
import Duckling.Core
import Duckling.Data.TimeZone
import Duckling.Locale
parseText :: Text -> Text -> Lang -> Maybe Region -> IO [Entity]
parseText text tz lang region = do
tzs <- loadTimeZoneSeries "/usr/share/zoneinfo/"
refTime <- currentReftime tzs tz
let
context = Context
{ referenceTime = refTime
, locale = Locale lang (region)
}
return $ parse text context [This Time]
I made two changes
- Line 11: I changed
parseText :: Text -> Text -> Lang -> IO [Entity]
toparseText :: Text -> Text -> Lang -> Maybe Region -> IO [Entity]
. - Line 18: I changed
, lang = lang
to, locale = Locale lang (region)
The reason (I think) this works is because Context
consists of a referenceTime
and a locale
, not a lang
. And locale
is composed of a lang
and region
. I don't yet understand how Maybe
works, though.
Now the code compiles and when I present it with timezones of the format Asia/Tbilisi
or America/Chicago
, it parses the string and returns the time relative to that timezone.
Could you tell me if this is the correct way of doing things? Also, I'm guessing I can expose parseText
as an API endpoint, but wanted to check.
from duckling.
Hi @nsanthanam, since then we've implemented locales (this is why @stopachka's example isn't working anymore). What you did works, though I would suggest to have parseText
directly accepts a Locale
. For an example on how to wrap this into a server, you can look into exe/ExampleMain.hs
.
from duckling.
That's correct, you'd have to move the locale construction from the function to the callsite.
from duckling.
Hi @nsanthanam, since then we've implemented locales (this is why @stopachka's example isn't working anymore). What you did works, though I would suggest to have
parseText
directly accepts aLocale
. For an example on how to wrap this into a server, you can look intoexe/ExampleMain.hs
.
@stopachka, Do you know if the server duckling-example-exe in exe/ExampleMain.hs already support specifying timezone and how? I can't find information I can use.
from duckling.
@chiapas Yes, through the tz parameter.
from duckling.
Related Issues (20)
- Support Persian(fa) Languages HOT 4
- [Persian][Numeral] Extract incorrect number from text
- ghc: panic! when stack build.
- Error building on MacOS with M1 Pro HOT 4
- Can't build Docker image HOT 2
- [it_IT] add time corpus/rules
- Default log files are created even if different paths are provided via options
- [ERROR] Network.Socket.sendBuf: resource vanished HOT 1
- Time intervals are too large by one grain HOT 1
- [Question] Which elements are relevant for Test-Failures? HOT 3
- Will not run on new Macbook HOT 1
- Reject common phrases like "guten morgen"
- Up Text and Hashable constraints
- Ne dimension is not working. HOT 1
- Custom Dimension doesn't return the actual value!
- Intervals with leap year dates return incorrect years
- how can I detect the date and time separately? anyone knows?
- Inconsistent date range parsing HOT 1
- Incorrect abbreviation of 'millions' in locale DE HOT 1
- overalaping body in the extracted entities
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from duckling.