Recognizing years without preposition with Duckling - named-entity-recognition

I'm trying to get the year from this sentence :
"events 2015"
Only grabs 2015 as a number.
But if I put the sentence in https://duckling.wit.ai/ grabs 2015 correctly as year, even if I just put 2015.
What can I do to have this behav in my side?
Regards

Try to add locale in your request.
It works with "en_us" or "en_gb"

Related

Icefaces datetimeentry starting year as 00 instead 20 when i enter two digit year

I’m using icefaces datetimeentry, everything works fine except one thing. When I enter two digit year like 19, it is showing as 0019 instead of 2019. Is there any help to convert it to 2019?
Do I need any converter or ajax call?
you must set the "pattern" attribute on the dateTimeEntry tag to a two digits year format (like "dd/MM/yy"). The default value for this property is "MM/dd/yyyy" (see icefaces taglib docs ) that yields 00yy when you set a two digits year (see SimpleDateFormat Javadoc).

Format time to show day and month

For a project I am working on I receive date and time in this format:
2015-08-16 15:00:00 UTC
yyyy-mm-dd hh-mm-ss UTC
How can I make the time display as "Saturday, August 16th 2015 at 3:30PM"? ("15:00" would be fine as well.)
And how would I make it so it checks if the date has already passed or not, so that it only displays dates that have not passed?
How would I make it so I can so that the time display as "Saturday, August 16th 2015 at 3:30PM (15:00 would be fine as well)?
Time.parse('2015-10-20 15:23 UTC').strftime('%A, %B %dth %Y at %l:%M%p')
#=> "Tuesday, October 20th 2015 at 3:23PM"
You might have to tweak it a bit to fix the suffixes (1st, 2nd, 3rd, etc)
And how would I make it so it checks if the date has already pasted or not?
You could do it like this (I'm sure there's a simpler way):
EDIT: Yes, there is a much simpler way -- check Matt's answer.
require 'time'
if Time.parse(my_date).to_i - Time.now.to_i > 0
# my_date is in the future.
end
To start, convert your string to a Time object via Time.parse(string) (APIDock).
After that you have all of the Time class to play with.
time.strftime
time.past?

Validate date strings in Ruby with multiple accepted formats?

I have some strings that might or might not be dates like:
"Hello World", "Sept 12, 2013", "Hello World Sept 12"
In this case, I'd like only the second one to be considered a proper date.
So far, I have been using Date.parse and the Chronic gem but they very lenient and convert strings like "a a" or "12-UNKN/34/OWN1" into acceptable dates.
For example:
Date.parse '12-UNKN/34/OWN1'
would return:
Tue, 12 Nov 2013
So, I am trying to restrict the accepted formats to a set of formats I can control:
09/12/2013
9/12/2013
9/12/13
09-12-2013
9-12-2013
9-12-13
and some formats with text inside like:
Sept 9, 2013 - with or without the coma, accepting Sep, Sept or September and with or without a dot after the month name, covering things like:
Sept. 9, 2013
Sept 09, 2013
Sept. 09, 2013
September 9, 2013
September 09, 2013
Any suggestion on a good way to do this in Ruby, either pure Ruby or with Rails?
I'll take a stab at this and elaborate on my comment. Separating the date from the other string allows you to validate the date in multiple formats before handing it off to Chronic:
validates_format_of :date, with: /\d{2,4}[-/]\d{1,2}[-/]\d{1,4}/, on: :create
That should handle most of the date formats you described.
However, a big issue is you won't know if someone is submitting a date in the US format or non-US format.
The bigger issue is know what part of the title string is in fact a date, and that would either be a more complicated regular expression, or make it easy on yourself and make it a separate field. You're getting somewhat close to trying to parse natural language which isn't cut and dry by any means.
Try something like this
validate :validate_some_date
private
def validate_some_date
errors.add("Created at date", "is invalid.") unless [
date_case_one,
date_case_two,
date_case_three
].all?
end
def date_case_one
# some regex
end
def date_case_two
# some regex
end
def date_case_three
# some regex
end

Validate Date String

We have a new field being added to our app where the client wants to be able to put in Sept 22. The input will be part of an import with 100 or so records. I know there are many libraries for parsing it but we want to be able to validate it. In case someone were to make a typo. Any thoughts or libraries to do this?
DateTime.parse will parse "Sept 22" with current year.
you can just make a dateTime with specified year as
date = DateTime.parse("Sept 22")
date_time_with_year = DateTime.new(year, date.month, date.day)
Check out Chronic
You can do things like
Chronic.parse('may 27th', :now => Time.local(2000, 1, 1))
#=> Sat May 27 12:00:00 PDT 2000
It will attempt to guess what the string was trying to convey, by default (ie: "Sept 27" will actually parse to something like 2013-09-27 12:00:00 -0500

Date format bug when date is in Portuguese?

I'm seeing some odd behavior in our application coming from a user working in what I believe to be Portuguese.
I realized that Rails seems to be mis-interpreting the dates she is submitting. Here's some examples:
Date.parse("ter, 30 abr 2013 07:00:00 GMT-07:00")
=> Thu, 30 May 2013
Date.parse("dom, 5 mai 2013 07:00:00 GMT-07:00 -07:00")
ArgumentError: invalid date
Is there something extra I need to do correctly identify dates being submitted in other languages?
Date are parsed with Ruby Date class with the following documentation
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-c-parse
I'm not sure it's a great idea to allow your users to type in the full date by themselves - they can mistype or assume different format. I suggest to use datepicker that with localized presentation based on the users location? One of the the many date pickers that allow this is http://docs.jquery.com/UI/Datepicker/Localization

Resources