event_nlp 0.6.8 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/event_nlp.rb +215 -163
- data.tar.gz.sig +0 -0
- metadata +28 -27
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7bd2a0880cb2646bfd8241934a3f295f2790d1c8a6912058bf26dbd12c2f5e4
|
4
|
+
data.tar.gz: 1e62175f0137981d910a8e177f2f2ba6026e54e8f8306f17037f6f8d19d800aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 803ba376567fd1693bbc3618bda094d46608ba293ca1d43dd93df305d017ce2403190fb8b33df128ef260e9210f33a530a4aa1fb1a62923d9f35c9bd77bed026
|
7
|
+
data.tar.gz: 26385ac01d68d9162d57e822ec271c1993f214b2e5960198f5a13d30fbb2368e34d6db5ee6e13422a76cadeda6c06cc6f6072aac70f3733162cb0aada7aa3b8c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/event_nlp.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
# file: event_nlp.rb
|
4
4
|
|
5
|
-
require 'chronic_cron'
|
6
5
|
require 'ostruct'
|
7
6
|
require 'app-routes'
|
7
|
+
require 'chronic_cron'
|
8
8
|
|
9
9
|
|
10
10
|
module Ordinals
|
@@ -22,20 +22,22 @@ class EventNlp
|
|
22
22
|
include AppRoutes
|
23
23
|
using Ordinals
|
24
24
|
using ColouredText
|
25
|
-
|
25
|
+
|
26
26
|
attr_accessor :params
|
27
|
-
|
27
|
+
|
28
28
|
def initialize(now=Time.now, params: {}, debug: false)
|
29
|
-
|
29
|
+
|
30
30
|
super()
|
31
|
-
|
31
|
+
|
32
|
+
@debug = debug
|
33
|
+
|
32
34
|
@now = now
|
33
35
|
@params = params
|
34
36
|
expressions(@params)
|
35
|
-
@debug = debug
|
36
37
|
|
37
|
-
end
|
38
38
|
|
39
|
+
end
|
40
|
+
|
39
41
|
def parse(raws)
|
40
42
|
|
41
43
|
s = filter_irregular(raws)
|
@@ -46,17 +48,36 @@ class EventNlp
|
|
46
48
|
r = run_route(s)
|
47
49
|
|
48
50
|
return unless r.is_a? Hash
|
49
|
-
|
51
|
+
|
50
52
|
OpenStruct.new({input: s}.merge r)
|
51
|
-
|
53
|
+
|
52
54
|
end
|
53
55
|
|
54
56
|
# returns an Array object of dates, projected from a recurring event
|
55
57
|
#
|
58
|
+
# Example parameters:
|
59
|
+
#
|
60
|
+
# s: 'Council Tax 30th Monthly'
|
61
|
+
# s: 'Council Tax 30th Monthly until 2nd October'
|
62
|
+
#
|
56
63
|
def project(s, year: @now.year)
|
57
64
|
|
58
|
-
|
65
|
+
s2, raw_end_date = s.split(/ +\buntil\b +/)
|
66
|
+
|
67
|
+
end_date = if raw_end_date then
|
68
|
+
EventNlp.new().parse(raw_end_date).date
|
69
|
+
else
|
70
|
+
(Date.parse('1 Jan ' + (year+1).to_s) - 1).to_time
|
71
|
+
end
|
72
|
+
|
73
|
+
puts 'project/end_date: ' + end_date.inspect if @debug
|
74
|
+
|
75
|
+
# filter the input to ensure validity
|
76
|
+
r0 = parse s2
|
77
|
+
puts 'project/r0: ' + r0.inspect if @debug
|
59
78
|
r = parse r0.input
|
79
|
+
puts 'project/r: ' + r.inspect if @debug
|
80
|
+
|
60
81
|
dates = []
|
61
82
|
now = @now
|
62
83
|
|
@@ -68,8 +89,9 @@ class EventNlp
|
|
68
89
|
end
|
69
90
|
|
70
91
|
return [r.date] if (r.date == EventNlp.new(r.date+1, debug: @debug).parse(r.input).date)
|
92
|
+
#year.to_i
|
71
93
|
|
72
|
-
while r.date
|
94
|
+
while r.date <= end_date do
|
73
95
|
|
74
96
|
dates << r.date
|
75
97
|
@now = if r.recurring == 'month' then
|
@@ -143,50 +165,52 @@ class EventNlp
|
|
143
165
|
|
144
166
|
end
|
145
167
|
|
146
|
-
def expressions(params)
|
168
|
+
def expressions(params)
|
147
169
|
|
148
170
|
starting = /(?:\(?\s*starting (\d+\w{2} \w+\s*\w*)(?: until (.*))?\s*\))?/
|
149
|
-
weekdays2 = (Date::DAYNAMES + Date::ABBR_DAYNAMES).join('|').downcase
|
171
|
+
weekdays2 = (Date::DAYNAMES + Date::ABBR_DAYNAMES).join('|').downcase
|
150
172
|
weekdays = "(%s)" % weekdays2
|
151
173
|
months = "(%s)" % (Date::MONTHNAMES[1..-1] + Date::ABBR_MONTHNAMES[1..-1])\
|
152
174
|
.join('|').downcase
|
175
|
+
years = /(20[0-9]{2})/
|
176
|
+
|
153
177
|
times = /(?: *(?:at |@ |from )?(\d+(?::\d+)?(?:[ap]m|\b)) *)/
|
154
178
|
times2 = /\d+(?::\d+)?[ap]m-\d+(?::\d+)?[ap]m|\d+(?::\d+)?-\d+(?::\d+)?/
|
155
|
-
times3 = /(\d+(?::\d+)?[ap]m-\d+(?::\d+)?[ap]m|\d+(?::\d+)?-\d+(?::\d+)?)/
|
179
|
+
times3 = /(\d+(?::\d+)?[ap]m-\d+(?::\d+)?[ap]m|\d+(?::\d+)?-\d+(?::\d+)?)/
|
156
180
|
days = /(\d+(?:st|nd|rd|th))/
|
157
181
|
periods = /day|week|month/
|
158
|
-
|
182
|
+
|
159
183
|
#weekdays = Date::DAYNAMES.join('|').downcase
|
160
184
|
#
|
161
|
-
|
185
|
+
|
162
186
|
#times = /(?: *at )?\d[ap]m/
|
163
187
|
|
164
|
-
# e.g. electricity bill on the 28th of every month
|
188
|
+
# e.g. electricity bill on the 28th of every month
|
165
189
|
|
166
190
|
get /(.*) on the #{days} of every (month)/i do |title, day, recurring|
|
167
191
|
|
168
192
|
|
169
193
|
puts 'day: ' + day.inspect if @debug
|
170
194
|
raw_d = Chronic.parse(day + ' ' + Date::MONTHNAMES[@now.month], now: @now)
|
171
|
-
|
195
|
+
|
172
196
|
# if the date is less than now then increment it by a month
|
173
197
|
d = raw_d < @now ? (raw_d.to_date >> 1).to_time : raw_d
|
174
|
-
|
175
|
-
|
198
|
+
|
199
|
+
|
176
200
|
if @debug then
|
177
201
|
puts [0.1, title, recurring, d].inspect.debug
|
178
202
|
end
|
179
|
-
|
180
|
-
{title: title, recurring: recurring, date: d}
|
181
|
-
|
203
|
+
|
204
|
+
{title: title, recurring: recurring, date: d}
|
205
|
+
|
182
206
|
end
|
183
|
-
|
207
|
+
|
184
208
|
#
|
185
209
|
|
186
210
|
get /^(.*)\s+(every \d\w+ \w+#{times}\s*#{starting})/ do \
|
187
211
|
|title, recurring, time, raw_date, end_date|
|
188
212
|
|
189
|
-
input = params[:input].clone
|
213
|
+
input = params[:input].clone
|
190
214
|
d = Chronic.parse(raw_date + ' ' + time.to_s, now: @now)
|
191
215
|
|
192
216
|
if @debug then
|
@@ -194,7 +218,7 @@ class EventNlp
|
|
194
218
|
puts 'd: ' + d.inspect
|
195
219
|
puts 'recurring: ' + recurring.inspect
|
196
220
|
end
|
197
|
-
|
221
|
+
|
198
222
|
if recurring =~ /day|week/ then
|
199
223
|
|
200
224
|
if d < @now then
|
@@ -210,22 +234,22 @@ class EventNlp
|
|
210
234
|
puts 'new_date: ' + new_date.inspect if @debug
|
211
235
|
|
212
236
|
input.gsub!(raw_date, new_date\
|
213
|
-
.strftime("#{new_date.day.ordinal} %b %Y"))
|
237
|
+
.strftime("#{new_date.day.ordinal} %b %Y"))
|
214
238
|
d = new_date
|
215
|
-
|
239
|
+
|
216
240
|
end
|
217
241
|
end
|
218
|
-
|
242
|
+
|
219
243
|
if @debug then
|
220
244
|
puts 'd: ' + d.inspect
|
221
245
|
puts ["0.2", input, title, recurring, time, raw_date, end_date].inspect.debug
|
222
246
|
end
|
223
|
-
|
224
|
-
{input: input, title: title, recurring: recurring, date: d,
|
225
|
-
end_date: end_date}
|
226
|
-
|
247
|
+
|
248
|
+
{input: input, title: title, recurring: recurring, date: d,
|
249
|
+
end_date: end_date}
|
250
|
+
|
227
251
|
end
|
228
|
-
|
252
|
+
|
229
253
|
# e.g. some event 1st Monday of every month (starting 3rd Jul 2017)
|
230
254
|
|
231
255
|
get /^(.*)\s+(\d(?:st|nd|rd|th) \w+ of every \w+(?: at (\d+[ap]m) )?)\s*#{starting}/ do \
|
@@ -233,32 +257,32 @@ class EventNlp
|
|
233
257
|
|
234
258
|
input = params[:input].clone
|
235
259
|
d = Chronic.parse(raw_date, now: @now)
|
236
|
-
|
237
|
-
if recurring =~ /day|week|month/ then
|
238
|
-
|
260
|
+
|
261
|
+
if recurring =~ /day|week|month/ then
|
262
|
+
|
239
263
|
if d < @now then
|
240
264
|
|
241
265
|
new_date = CronFormat.new(ChronicCron.new(recurring)\
|
242
266
|
.to_expression, d).to_time
|
243
267
|
input.gsub!(raw_date, new_date\
|
244
|
-
.strftime("#{new_date.day.ordinal} %b %Y"))
|
268
|
+
.strftime("#{new_date.day.ordinal} %b %Y"))
|
245
269
|
d = new_date
|
246
270
|
else
|
247
271
|
d = ChronicCron.new(recurring, d.to_date.to_time).to_time
|
248
272
|
end
|
249
273
|
end
|
250
|
-
|
274
|
+
|
251
275
|
puts ['0.3'.highlight, title, recurring, time, raw_date, end_date].inspect.debug if @debug
|
252
|
-
{input: input, title: title, recurring: recurring, date: d, end_date:
|
276
|
+
{input: input, title: title, recurring: recurring, date: d, end_date:
|
253
277
|
end_date}
|
254
|
-
|
255
|
-
end
|
278
|
+
|
279
|
+
end
|
256
280
|
|
257
281
|
# some event every 2 weeks
|
258
282
|
# some event every 2 weeks at 6am starting from 14th Jan
|
259
283
|
# some event every 2 weeks at 6am starting from 18th Feb until 28th Oct
|
260
284
|
# some event every 2nd Monday (starting 7th Nov 2016)
|
261
|
-
# some event every 2nd Monday (starting 7th Nov until 3rd Dec)
|
285
|
+
# some event every 2nd Monday (starting 7th Nov until 3rd Dec)
|
262
286
|
# some event every 2 weeks (starting 02/11/17)
|
263
287
|
# some event every Wednesday 1pm-4pm
|
264
288
|
#
|
@@ -267,22 +291,22 @@ class EventNlp
|
|
267
291
|
input = params[:input].clone
|
268
292
|
puts 'recurring: ' + recurring.inspect if @debug
|
269
293
|
raw_start_date = recurring[/(?<=starting )[^\)]+/]
|
270
|
-
|
294
|
+
|
271
295
|
d = if raw_start_date then
|
272
|
-
start_date = Chronic.parse(raw_start_date, now: @now - 1,
|
296
|
+
start_date = Chronic.parse(raw_start_date, now: @now - 1,
|
273
297
|
:endian_precedence => :little)
|
274
298
|
|
275
299
|
puts ('recurring: ' + recurring.inspect).debug if @debug
|
276
300
|
puts ('start_date: ' + start_date.inspect).debug if @debug
|
277
|
-
|
301
|
+
|
278
302
|
if @now > start_date then
|
279
303
|
exp = ChronicCron.new(recurring, start_date, debug: @debug).to_expression
|
280
304
|
puts 'exp: ' + exp.inspect if @debug
|
281
|
-
|
305
|
+
|
282
306
|
cf = CronFormat.new(exp, start_date, debug: @debug)
|
283
307
|
puts ('cf.to_time: ' + cf.to_time.inspect).debug if @debug
|
284
308
|
cf.next until cf.to_time > start_date
|
285
|
-
|
309
|
+
|
286
310
|
new_date = cf.to_time
|
287
311
|
input.gsub!(/(?<=starting )[^\)]+/, new_date\
|
288
312
|
.strftime("#{new_date.day.ordinal} %b %Y"))
|
@@ -291,183 +315,183 @@ class EventNlp
|
|
291
315
|
else
|
292
316
|
start_date
|
293
317
|
end
|
294
|
-
|
318
|
+
|
295
319
|
else
|
296
320
|
exp = ChronicCron.new(recurring).to_expression
|
297
321
|
cf = CronFormat.new(exp, @now)
|
298
322
|
cf.to_time
|
299
323
|
end
|
324
|
+
|
300
325
|
|
301
|
-
|
302
|
-
|
326
|
+
|
303
327
|
if recurring =~ /-/ then
|
304
|
-
end_date = Chronic.parse d.to_date.to_s + ' ' +
|
328
|
+
end_date = Chronic.parse d.to_date.to_s + ' ' +
|
305
329
|
recurring[/(?<=-)\d+(?::\d+)?(?:[ap]m)?/], now: @now
|
306
330
|
end
|
307
|
-
|
331
|
+
|
308
332
|
puts ['0.5'.highlight, title, recurring, d].join("\n").debug if @debug
|
309
|
-
{input: input, title: title.rstrip, recurring: recurring,
|
333
|
+
{input: input, title: title.rstrip, recurring: recurring,
|
310
334
|
date: d, end_date: end_date }
|
311
|
-
|
312
|
-
end
|
313
|
-
|
335
|
+
|
336
|
+
end
|
337
|
+
|
314
338
|
# some meeting 3rd thursday of the month at 7:30pm
|
315
339
|
# some meeting First thursday of the month at 7:30pm
|
316
|
-
get /(.*)\s+(\w+ \w+day of (?:the|every) month at .*)/ do
|
340
|
+
get /(.*)\s+(\w+ \w+day of (?:the|every) month at .*)/ do
|
317
341
|
|title, recurring|
|
318
342
|
|
319
343
|
puts ['1'.highlight, title, recurring].inspect.debug if @debug
|
320
344
|
{ title: title, recurring: recurring }
|
321
345
|
|
322
346
|
end
|
323
|
-
|
324
|
-
|
347
|
+
|
348
|
+
|
325
349
|
# 7th Oct Euston Station (meet at Timothy's house at 7pm)
|
326
350
|
get /^(\d(?:st|nd|rd|th) \w+) *(.*)\s+at\s+(\w+)/i do \
|
327
351
|
|raw_day, title, time|
|
328
|
-
|
352
|
+
|
329
353
|
d = Chronic.parse(raw_day + ' ' + time, now: @now)
|
330
|
-
|
354
|
+
|
331
355
|
puts ['1.5'.highlight, title, raw_day, time].inspect.debug if @debug
|
332
356
|
{ title: title, date: d }
|
333
|
-
|
334
|
-
end
|
357
|
+
|
358
|
+
end
|
335
359
|
|
336
360
|
# some event Wednesday
|
337
361
|
# some event Wednesday 11am
|
338
|
-
|
362
|
+
|
339
363
|
relative_day = '|today|tomorrow|tonight'
|
340
364
|
get /^(.*)\s+(#{weekdays2+relative_day}\b)(?: \(([^\)]+)\)) (at \d{1,2}(?::\d{2})?(?:[ap]m)?)/i \
|
341
365
|
do |title, raw_date, date2, time2|
|
342
366
|
puts ('time2: ' + time2.inspect).debug if @debug
|
343
367
|
puts ('date2: ' + date2).debug if @debug
|
344
368
|
puts ('raw_date: ' + raw_date).debug if @debug
|
345
|
-
|
369
|
+
|
346
370
|
d = if date2 then
|
347
371
|
Chronic.parse(date2 + ' '+ time2.to_s, now: @now)
|
348
372
|
else
|
349
373
|
Chronic.parse(raw_date + ' '+ time2, now: @now)
|
350
374
|
end
|
351
|
-
|
375
|
+
|
352
376
|
puts ['4'.highlight, title, raw_date, date2, time2].inspect.debug if @debug
|
353
377
|
{title: title, date: d }
|
354
|
-
|
378
|
+
|
355
379
|
end
|
356
|
-
|
380
|
+
|
357
381
|
# Group meeting Red Hall 2pm-4pm on Monday (4th Dec 2017)
|
358
382
|
get /^(.*)\s+(#{times2})(?: on) +#{weekdays}\b(?: \(([^\)]+)\))?/i \
|
359
383
|
do |title, xtimes, raw_day, actual_date|
|
360
|
-
|
384
|
+
|
361
385
|
if @debug then
|
362
386
|
puts ('actual_date: ' + actual_date.inspect).debug
|
363
387
|
puts ('raw_day: ' + raw_day.inspect).debug
|
364
388
|
puts ('xtimes: ' + xtimes.inspect).debug
|
365
389
|
end
|
366
|
-
|
390
|
+
|
367
391
|
input = params[:input].clone
|
368
|
-
|
392
|
+
|
369
393
|
if actual_date then
|
370
394
|
d = Chronic.parse actual_date, now: @now
|
371
395
|
else
|
372
396
|
d = Chronic.parse(raw_day, now: @now)
|
373
397
|
input.sub!(/#{weekdays}\b/i,
|
374
|
-
%Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
|
398
|
+
%Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
|
375
399
|
end
|
376
400
|
|
377
401
|
t1, t2 = xtimes.split(/-/,2)
|
378
|
-
|
402
|
+
|
379
403
|
puts ('d: ' + d.inspect).debug if @debug
|
380
404
|
|
381
405
|
d1, d2 = [t1, t2].map {|t| Chronic.parse([d.to_date.to_s, t].join(' '), now: @now) }
|
382
|
-
|
406
|
+
|
383
407
|
puts ['4.65'.highlight, input, title, raw_day, d1, d2].inspect.debug if @debug
|
384
|
-
|
408
|
+
|
385
409
|
{input: input, title: title, date: d1, end_date: d2 }
|
386
|
-
|
387
|
-
end
|
388
|
-
|
410
|
+
|
411
|
+
end
|
412
|
+
|
389
413
|
# hall 2 friday at 11am
|
390
414
|
|
391
415
|
get /^(.*)\s+#{weekdays}\b(?: \(([^\)]+)\))?(?:#{times})? *(weekly)?/i \
|
392
416
|
do |title, raw_day, actual_date, time, recurring|
|
393
|
-
|
417
|
+
|
394
418
|
if @debug then
|
395
419
|
puts ('recurring: ' + recurring.inspect).debug
|
396
420
|
puts ('actual_date: ' + actual_date.inspect).debug
|
397
421
|
puts ('raw_day: ' + raw_day.inspect).debug
|
398
422
|
puts ('time: ' + time.inspect).debug
|
399
423
|
end
|
400
|
-
|
424
|
+
|
401
425
|
input = params[:input].clone
|
402
426
|
|
403
427
|
d = Chronic.parse(raw_day + ' ' + time.to_s, now: @now)
|
404
428
|
|
405
429
|
if recurring.nil?
|
406
430
|
input.sub!(/#{weekdays}/i,
|
407
|
-
%Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
|
431
|
+
%Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
|
408
432
|
end
|
409
|
-
|
433
|
+
|
410
434
|
puts ('d: ' + d.inspect).debug if @debug
|
411
|
-
|
435
|
+
|
412
436
|
puts [1.7, input, title, raw_day].inspect.debug if @debug
|
413
|
-
|
437
|
+
|
414
438
|
{input: input, title: title, date: d }
|
415
|
-
|
416
|
-
end
|
417
|
-
|
418
|
-
|
439
|
+
|
440
|
+
end
|
441
|
+
|
442
|
+
|
419
443
|
# e.g. 21/05/2017 Forum meetup at Roundpeg from 2pm
|
420
|
-
get /^(\d+\/\d+\/\d+)\s+(.*)(?: from|at)\s+(\d+[ap]m)/ do
|
444
|
+
get /^(\d+\/\d+\/\d+)\s+(.*)(?: from|at)\s+(\d+[ap]m)/ do
|
421
445
|
|raw_date, title, raw_time|
|
422
|
-
|
423
|
-
d = Chronic.parse(raw_date + ' ' +
|
446
|
+
|
447
|
+
d = Chronic.parse(raw_date + ' ' +
|
424
448
|
raw_time, now: @now, :endian_precedence => :little)
|
425
|
-
recurring = nil
|
426
|
-
|
449
|
+
recurring = nil
|
450
|
+
|
427
451
|
puts [3, title, raw_date].inspect.debug if @debug
|
428
452
|
{ title: title, date: d }
|
429
|
-
end
|
430
|
-
|
453
|
+
end
|
454
|
+
|
431
455
|
# friday hall 2 11am until 12am
|
432
456
|
get /^#{weekdays}\s+(.*)\s+#{times} until #{times}$/i do \
|
433
457
|
|raw_day, title, start_time, end_time|
|
434
|
-
|
458
|
+
|
435
459
|
venue = title[/^at +(.*)/,1]
|
436
460
|
d = Chronic.parse(raw_day + ' ' + start_time, now: @now)
|
437
461
|
d2 = Chronic.parse(raw_day + ' ' + end_time, now: @now)
|
438
|
-
|
462
|
+
|
439
463
|
puts ['1.44.3', title, raw_day].inspect.debug if @debug
|
440
464
|
{ title: title, date: d, end_date: d2, venue: venue }
|
441
|
-
|
442
|
-
end
|
443
|
-
|
465
|
+
|
466
|
+
end
|
467
|
+
|
444
468
|
# friday hall 2 11am
|
445
469
|
get /^#{weekdays}\b\s+(.*)\s+(\d+(?::\d{2})?[ap]m)$/i do \
|
446
470
|
|raw_day, title, time|
|
447
|
-
|
471
|
+
|
448
472
|
puts [raw_day, title, time].inspect if @debug
|
449
473
|
venue = title[/^at +(.*)/,1]
|
450
474
|
d = Chronic.parse(raw_day + ' ' + time, now: @now)
|
451
|
-
|
475
|
+
|
452
476
|
puts [1.44, title, raw_day].inspect.debug if @debug
|
453
477
|
{ title: title, date: d, venue: venue }
|
454
|
-
|
455
|
-
end
|
478
|
+
|
479
|
+
end
|
456
480
|
|
457
481
|
# Tuesday 10th July hall 2 at 11am
|
458
482
|
get /#{weekdays}\b\s+#{days}\s+#{months}\s+(?:at )?(.*)\s+at\s+(#{times})/i \
|
459
483
|
do |wday, day, month, title, time|
|
460
|
-
|
484
|
+
|
461
485
|
d = Chronic.parse([day, month, time].join(' '), now: @now)
|
462
|
-
|
486
|
+
|
463
487
|
puts ['1.44.5', day, month, title].inspect.debug if @debug
|
464
488
|
{ title: title, date: d }
|
465
|
-
|
466
|
-
end
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
489
|
+
|
490
|
+
end
|
491
|
+
|
492
|
+
|
493
|
+
|
494
|
+
|
471
495
|
# 27-Mar@1436 some important day
|
472
496
|
# 25/07/2017 11pm some important day
|
473
497
|
#
|
@@ -477,22 +501,22 @@ class EventNlp
|
|
477
501
|
d = Chronic.parse(raw_date + ' ' + time.to_s, now: @now,
|
478
502
|
:endian_precedence => :little)
|
479
503
|
recurring = nil
|
480
|
-
|
504
|
+
|
481
505
|
if annualar then
|
482
|
-
|
506
|
+
|
483
507
|
recurring = 'yearly'
|
484
508
|
if d < @now then
|
485
|
-
d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
|
509
|
+
d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
|
486
510
|
end
|
487
511
|
end
|
488
|
-
|
489
|
-
|
512
|
+
|
513
|
+
|
490
514
|
puts [3, title, raw_date, time].inspect.debug if @debug
|
491
515
|
{ title: title, date: d, recurring: recurring }
|
492
516
|
end
|
493
517
|
|
494
518
|
|
495
|
-
|
519
|
+
|
496
520
|
# Some event (10 Woodhouse Lane) 30th Nov from 9:15-17:00
|
497
521
|
|
498
522
|
get /^(.*) #{days} #{months}(?: from)? (#{times2})/i do \
|
@@ -507,7 +531,7 @@ class EventNlp
|
|
507
531
|
|
508
532
|
{ title: title, date: d1, end_date: d2 }
|
509
533
|
end
|
510
|
-
|
534
|
+
|
511
535
|
# Some event (10 Woodhouse Lane) 30th Nov from 9:15-17:00
|
512
536
|
|
513
537
|
get /^#{weekdays}\b #{months} #{days} #{times3} (.*)/i do \
|
@@ -522,7 +546,7 @@ class EventNlp
|
|
522
546
|
puts [4.55, title, d1, d2].inspect.debug if @debug
|
523
547
|
|
524
548
|
{ title: title, date: d1, end_date: d2 }
|
525
|
-
end
|
549
|
+
end
|
526
550
|
|
527
551
|
# e.g. Wednesday 30th Nov at 9:15 10 Woodhouse Lane
|
528
552
|
|
@@ -536,12 +560,40 @@ class EventNlp
|
|
536
560
|
{ title: title, date: d1 }
|
537
561
|
end
|
538
562
|
|
563
|
+
# Some event (10 Woodhouse Lane) 30th Nov at 9:15-10:00
|
564
|
+
|
565
|
+
get /^(.*) #{days} #{months} #{years}(?: at)? (#{times2})/i do \
|
566
|
+
|title, day, month, years, xtimes|
|
567
|
+
|
568
|
+
t1, t2 = xtimes.split(/-/,2)
|
569
|
+
puts '[title, years, day, month, t1] ' + [title, years, day, month, t1].inspect if @debug
|
570
|
+
d1 = Chronic.parse([month, day, years, t1].join(' '), now: @now)
|
571
|
+
d2 = Chronic.parse([month, day, years, t2].join(' '), now: @now)
|
572
|
+
|
573
|
+
puts [4.655, title, d1].inspect.debug if @debug
|
574
|
+
|
575
|
+
{ title: title.sub(/ on$/,''), date: d1, end_date: d2 }
|
576
|
+
end
|
577
|
+
|
578
|
+
# Some event (10 Woodhouse Lane) 30th Nov at 9:15
|
579
|
+
|
580
|
+
get /^(.*) #{days} #{months} #{years}(?: at)? (#{times})/i do \
|
581
|
+
|title, day, month, years, t1|
|
582
|
+
|
583
|
+
puts '[title, years, day, month, t1] ' + [title, years, day, month, t1].inspect if @debug
|
584
|
+
d1 = Chronic.parse([month, day, years, t1].join(' '), now: @now)
|
585
|
+
|
586
|
+
puts [4.66, title, d1].inspect.debug if @debug
|
587
|
+
|
588
|
+
{ title: title.sub(/ on$/,''), date: d1 }
|
589
|
+
end
|
590
|
+
|
539
591
|
# Some event (10 Woodhouse Lane) 30th Nov at 9:15-
|
540
592
|
|
541
593
|
get /^(.*) #{days} #{months}(?: at)? (#{times})/i do \
|
542
594
|
|title, day, month, t1|
|
543
595
|
|
544
|
-
|
596
|
+
puts '[title, day, month, t1] ' + [title, day, month, t1].inspect if @debug
|
545
597
|
d1 = Chronic.parse([month, day, t1].join(' '), now: @now)
|
546
598
|
|
547
599
|
puts [4.7, title, d1].inspect.debug if @debug
|
@@ -552,73 +604,73 @@ class EventNlp
|
|
552
604
|
# hall 2 at 11am
|
553
605
|
#
|
554
606
|
get /(.*)\s+at\s+(#{times})/i do |title, time|
|
555
|
-
|
607
|
+
|
556
608
|
d = Chronic.parse(time, now: @now)
|
557
|
-
|
609
|
+
|
558
610
|
puts [1.45, title].inspect.debug if @debug
|
559
611
|
{ title: title, date: d }
|
560
|
-
|
561
|
-
end
|
562
|
-
|
563
|
-
|
612
|
+
|
613
|
+
end
|
614
|
+
|
615
|
+
|
564
616
|
# Council Tax on the last day of the month
|
565
617
|
#
|
566
618
|
get /^(.*) (?:o[nf] the)\s*last day of the month/i do |title|
|
567
|
-
|
619
|
+
|
568
620
|
td = @now.to_date
|
569
621
|
d = Date.civil(td.year, td.month, -1).to_time
|
570
|
-
|
622
|
+
|
571
623
|
puts [5, title].inspect.debug if @debug
|
572
624
|
{ title: title, date: d }
|
573
|
-
|
574
|
-
end
|
575
|
-
|
625
|
+
|
626
|
+
end
|
627
|
+
|
576
628
|
# Council Tax last day of the month
|
577
629
|
#
|
578
630
|
get /^(.*) +last day of the month/i do |title|
|
579
|
-
|
631
|
+
|
580
632
|
td = @now.to_date
|
581
633
|
d = Date.civil(td.year, td.month, -1).to_time
|
582
|
-
|
634
|
+
|
583
635
|
puts [5.1, title].inspect.debug if @debug
|
584
636
|
{ title: title, date: d }
|
585
|
-
|
586
|
-
end
|
587
|
-
|
637
|
+
|
638
|
+
end
|
639
|
+
|
588
640
|
# some important day 11 Oct *
|
589
641
|
#
|
590
642
|
get /^(.*) +(\d+) +#{months} *(\*)?/i \
|
591
643
|
do |title, day, month, annualar|
|
592
|
-
|
644
|
+
|
593
645
|
raw_date = day + ' ' + month
|
594
646
|
|
595
647
|
d = Chronic.parse(raw_date, now: @now,
|
596
648
|
:endian_precedence => :little)
|
597
649
|
recurring = nil
|
598
|
-
|
650
|
+
|
599
651
|
if annualar then
|
600
|
-
|
652
|
+
|
601
653
|
recurring = 'yearly'
|
602
654
|
if d < @now then
|
603
|
-
d = Chronic.parse(raw_date,
|
604
|
-
now: Time.local(@now.year + 1, 1, 1))
|
655
|
+
d = Chronic.parse(raw_date,
|
656
|
+
now: Time.local(@now.year + 1, 1, 1))
|
605
657
|
end
|
606
658
|
end
|
607
|
-
|
608
|
-
|
659
|
+
|
660
|
+
|
609
661
|
puts [6, title, raw_date].inspect.debug if @debug
|
610
662
|
{ title: title, date: d, recurring: recurring }
|
611
663
|
end
|
612
|
-
|
613
|
-
|
614
|
-
|
664
|
+
|
665
|
+
|
666
|
+
|
615
667
|
# Tuesday 3rd October gas service at Barbara's house morning 9am-1pm
|
616
668
|
#
|
617
669
|
get '*' do
|
618
|
-
|
670
|
+
|
619
671
|
s = params[:input]
|
620
|
-
|
621
|
-
time1, time2, month, weekday, day, end_date, annualar = nil, nil, nil,
|
672
|
+
|
673
|
+
time1, time2, month, weekday, day, end_date, annualar = nil, nil, nil,
|
622
674
|
nil, nil, nil, false
|
623
675
|
|
624
676
|
s2 = s.sub(/#{times}/i) {|x| time1 = x; ''}
|
@@ -633,29 +685,29 @@ class EventNlp
|
|
633
685
|
raw_date = [day, month].compact.join(' ')
|
634
686
|
raw_date = weekday if raw_date.empty?
|
635
687
|
|
636
|
-
d = Chronic.parse(raw_date + ' ' + time1.to_s,
|
688
|
+
d = Chronic.parse(raw_date + ' ' + time1.to_s,
|
637
689
|
:endian_precedence => :little, now: @now)
|
638
|
-
|
690
|
+
|
639
691
|
if time2 then
|
640
692
|
end_date = Chronic.parse(raw_date + ' ' + time2.to_s, now: @now,
|
641
693
|
:endian_precedence => :little)
|
642
694
|
end
|
643
|
-
|
695
|
+
|
644
696
|
recurring = nil
|
645
|
-
|
697
|
+
|
646
698
|
if annualar then
|
647
|
-
|
699
|
+
|
648
700
|
recurring = 'yearly'
|
649
701
|
if d < @now then
|
650
|
-
d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
|
702
|
+
d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
|
651
703
|
end
|
652
|
-
end
|
653
|
-
|
704
|
+
end
|
705
|
+
|
654
706
|
puts [10, title, raw_date, time1].inspect.debug if @debug
|
655
707
|
{ title: title, date: d, end_date: end_date, recurring: recurring }
|
656
|
-
end
|
657
|
-
|
658
|
-
|
708
|
+
end
|
709
|
+
|
710
|
+
|
659
711
|
end
|
660
|
-
|
712
|
+
|
661
713
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_nlp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,32 +10,33 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
13
|
+
MIIEljCCAv6gAwIBAgIBATANBgkqhkiG9w0BAQsFADBIMRIwEAYDVQQDDAlnZW1t
|
14
|
+
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
+
8ixkARkWAmV1MB4XDTIzMDMzMDA4MjEwNVoXDTI0MDMyOTA4MjEwNVowSDESMBAG
|
16
|
+
A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
|
17
|
+
EjAQBgoJkiaJk/IsZAEZFgJldTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoC
|
18
|
+
ggGBAJ3t5zUzzxNb3KZVNPAwz7SKx8E0tp1n0lvbIpXWROKLbiVVWEL6PAnikGIU
|
19
|
+
3DOdMm4ZyQUiY2PIoEVHS++OeA+fT8ZTIU9fVS/kWomrIraqhz2vImY2oewD/Qxp
|
20
|
+
6cCvr+2/diAn7C8A2HYBaiGgMr75b64mnWAIcDGnj6Eg3ec5Y0qMTC/Eo/NIJCGN
|
21
|
+
GAtd/fWBqvx5BwHfo3YX1ES0UjNLmNjS0zQy5YD6jaTElJ31qvzqtZbU3bCuJpB8
|
22
|
+
CN/TyOuuBANdyICrrf1iizYoOfXvs44JNE0j7Kj4SBSy28hHWMlQ9s83Q3EktNwW
|
23
|
+
AzeofToLHSD5XSxTw7tSUG5GdW01vq/7jnhVkv5pi43DnoTQ1SJjkZAetR5QIqk9
|
24
|
+
uUVCLoTLTqP9T4CDcdngO/qGKRKS5OwkdsZJeAQQSlL+1u1u0NQIPqurCn2sf+Iv
|
25
|
+
WUnnxnSS9ZhQphqxJPFd/RVThd6CpS9tzIWG2SZzMOqQ7NiLwVWhtK/snL9Hh2/q
|
26
|
+
6CJfcQIDAQABo4GKMIGHMAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
|
27
|
+
BBSySBT3LMLi7K/V+ff+nI2zJEYqiDAmBgNVHREEHzAdgRtnZW1tYXN0ZXJAamFt
|
28
|
+
ZXNyb2JlcnRzb24uZXUwJgYDVR0SBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
|
29
|
+
c29uLmV1MA0GCSqGSIb3DQEBCwUAA4IBgQBsGD0pCs6dJJJNHbzmoe3LscVkeAu6
|
30
|
+
BzuKZSzuHnDCTreuZnt5JyiaIVwFgI9nIDv5xv1ql+p/7IakOQhGG/p8WqG7H53C
|
31
|
+
Fb6yuV11CtjXKRpN9z4bSCUAuID/R/x0+yqOWqb+0GJj0DKd33Q2r00nWZ6XOCx2
|
32
|
+
m/J/exb7p8PaZWyoPiJToMfSRz7BRt1nokig/rDny4ahBea6Flw9kqyQ2zbCagas
|
33
|
+
yvMvDmSrgyGWir/kj+aNI/64l0hciWoQCdG+cEn4fmv9YWx977Vy+v5theRiRtjb
|
34
|
+
pmBQP3C37V0RxFbgTDEIqwJcOdvZ1y+QJ9788CkydluVi/yL3Nh8684or3ih4WMX
|
35
|
+
1WrKCmIHqObF6xSQx4LJnsaLf/scFwT1xewudG+A+aWkP/vLY68EWCnU5DSw1Z/a
|
36
|
+
hlofVJ6Yrd5wJGF95qQqR5NCHCDnm/eSuJqV68pEJDK2GBYtGeCSQK0WAB0drsKe
|
37
|
+
Ff0VKkMErJ7dvr9XcKLCxlft1WhzfHIByj0=
|
37
38
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
39
|
+
date: 2023-03-30 00:00:00.000000000 Z
|
39
40
|
dependencies:
|
40
41
|
- !ruby/object:Gem::Dependency
|
41
42
|
name: chronic_cron
|
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
104
|
- !ruby/object:Gem::Version
|
104
105
|
version: '0'
|
105
106
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
107
|
+
rubygems_version: 3.4.4
|
107
108
|
signing_key:
|
108
109
|
specification_version: 4
|
109
110
|
summary: 'Parses a calendar event for date, time, and description e.g. hall 2 friday
|
metadata.gz.sig
CHANGED
Binary file
|