brandonhorst / elliptical-datetime Goto Github PK
View Code? Open in Web Editor NEWEnable Lacona to parse natural language dates, times, and both together
License: MIT License
Enable Lacona to parse natural language dates, times, and both together
License: MIT License
Referring to brandonhorst/LaconaApp#73
As requested
I am trying to create a parser to capture a datetime within a sentence.
So far, playing with elliptical and this library I have the following grammar:
<sequence>
<literal text='due by ' />
<DateTime id='dueDate' past={false} prepositions />
<freetext consumeAll />
</sequence>
I want the freetext
to consume and throw away everything after the datetime has been parsed. The problem is with an example sentence like so: "due by Tuesday at 5pm blah blah blah"
, it correctly identifies next Tuesday, but does not correctly set the time to 5pm. (If I remove the freetext
element, it works without any text after the datetime).
Any insight would be appreciated.
I'm evaluating time strings (such as 3pm
) on my server, which might not be in the same timezone from where the string originates. This can result in incorrect parsing.
Do you have any pointers on how this can be fixed? I'm happy to file a PR.
The following code:
var lacona = require('lacona');
var laconaPhrase = require('lacona-phrase');
var datetime = require('lacona-phrase-datetime');
var string = require('lacona-phrase-string');
var parser = new lacona.Parser({
grammar: laconaPhrase.createElement('sequence', {
children: [
laconaPhrase.createElement('literal', {
text: 'remind me to '
}),
laconaPhrase.createElement(string.String, {
id: 'activity'
}),
laconaPhrase.createElement('literal', {
text: ' '
}),
laconaPhrase.createElement('choice', {
id: 'date',
children: [
laconaPhrase.createElement(datetime.DateTime, {
past: false
})
]
})
]
})
});
var _ = require('underscore');
var moment = require('moment');
function parse(text) {
var results = parser.parseArray(text);
var topResult = _.first(_.sortBy(results, 'score').reverse());
return topResult ? topResult.result : null;
}
console.log(parse('remind me to exercise well in 36 hours'))
produces the output in version 0.7.1:
{ activity: 'exercise well',
date: Tue Feb 16 2016 01:21:26 GMT-0800 (PST) }
but produces the output in version 0.8.0:
{ activity: 'exercise well',
date: { time: { hour: 1, minute: 21, second: 51 }, timeOfDay: {} } }
The date object is missing in 0.8.0. Is that intentional? It makes it less useful without the date object.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.