event_nlp 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/event_nlp.rb +186 -172
- 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,18 +2,10 @@
|
|
2
2
|
|
3
3
|
# file: event_nlp.rb
|
4
4
|
|
5
|
-
|
6
|
-
#require 'chronic_cron'
|
7
5
|
require 'ostruct'
|
8
|
-
require '
|
9
|
-
|
10
|
-
code = Requestor.read('http://a0.jamesrobertson.me.uk/rorb/r/ruby') do |x|
|
11
|
-
x.require 'app-routes'
|
12
|
-
x.require 'chronic_cron'
|
13
|
-
end
|
6
|
+
require 'app-routes'
|
7
|
+
require 'chronic_cron'
|
14
8
|
|
15
|
-
eval code
|
16
|
-
#require 'app-routes'
|
17
9
|
|
18
10
|
module Ordinals
|
19
11
|
|
@@ -30,20 +22,22 @@ class EventNlp
|
|
30
22
|
include AppRoutes
|
31
23
|
using Ordinals
|
32
24
|
using ColouredText
|
33
|
-
|
25
|
+
|
34
26
|
attr_accessor :params
|
35
|
-
|
27
|
+
|
36
28
|
def initialize(now=Time.now, params: {}, debug: false)
|
37
|
-
|
29
|
+
|
38
30
|
super()
|
39
|
-
|
31
|
+
|
32
|
+
@debug = debug
|
33
|
+
|
40
34
|
@now = now
|
41
35
|
@params = params
|
42
36
|
expressions(@params)
|
43
|
-
@debug = debug
|
44
37
|
|
45
|
-
end
|
46
38
|
|
39
|
+
end
|
40
|
+
|
47
41
|
def parse(raws)
|
48
42
|
|
49
43
|
s = filter_irregular(raws)
|
@@ -54,17 +48,36 @@ class EventNlp
|
|
54
48
|
r = run_route(s)
|
55
49
|
|
56
50
|
return unless r.is_a? Hash
|
57
|
-
|
51
|
+
|
58
52
|
OpenStruct.new({input: s}.merge r)
|
59
|
-
|
53
|
+
|
60
54
|
end
|
61
55
|
|
62
56
|
# returns an Array object of dates, projected from a recurring event
|
63
57
|
#
|
58
|
+
# Example parameters:
|
59
|
+
#
|
60
|
+
# s: 'Council Tax 30th Monthly'
|
61
|
+
# s: 'Council Tax 30th Monthly until 2nd October'
|
62
|
+
#
|
64
63
|
def project(s, year: @now.year)
|
65
64
|
|
66
|
-
|
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
|
67
78
|
r = parse r0.input
|
79
|
+
puts 'project/r: ' + r.inspect if @debug
|
80
|
+
|
68
81
|
dates = []
|
69
82
|
now = @now
|
70
83
|
|
@@ -76,8 +89,9 @@ class EventNlp
|
|
76
89
|
end
|
77
90
|
|
78
91
|
return [r.date] if (r.date == EventNlp.new(r.date+1, debug: @debug).parse(r.input).date)
|
92
|
+
#year.to_i
|
79
93
|
|
80
|
-
while r.date
|
94
|
+
while r.date <= end_date do
|
81
95
|
|
82
96
|
dates << r.date
|
83
97
|
@now = if r.recurring == 'month' then
|
@@ -151,10 +165,10 @@ class EventNlp
|
|
151
165
|
|
152
166
|
end
|
153
167
|
|
154
|
-
def expressions(params)
|
168
|
+
def expressions(params)
|
155
169
|
|
156
170
|
starting = /(?:\(?\s*starting (\d+\w{2} \w+\s*\w*)(?: until (.*))?\s*\))?/
|
157
|
-
weekdays2 = (Date::DAYNAMES + Date::ABBR_DAYNAMES).join('|').downcase
|
171
|
+
weekdays2 = (Date::DAYNAMES + Date::ABBR_DAYNAMES).join('|').downcase
|
158
172
|
weekdays = "(%s)" % weekdays2
|
159
173
|
months = "(%s)" % (Date::MONTHNAMES[1..-1] + Date::ABBR_MONTHNAMES[1..-1])\
|
160
174
|
.join('|').downcase
|
@@ -162,41 +176,41 @@ class EventNlp
|
|
162
176
|
|
163
177
|
times = /(?: *(?:at |@ |from )?(\d+(?::\d+)?(?:[ap]m|\b)) *)/
|
164
178
|
times2 = /\d+(?::\d+)?[ap]m-\d+(?::\d+)?[ap]m|\d+(?::\d+)?-\d+(?::\d+)?/
|
165
|
-
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+)?)/
|
166
180
|
days = /(\d+(?:st|nd|rd|th))/
|
167
181
|
periods = /day|week|month/
|
168
|
-
|
182
|
+
|
169
183
|
#weekdays = Date::DAYNAMES.join('|').downcase
|
170
184
|
#
|
171
|
-
|
185
|
+
|
172
186
|
#times = /(?: *at )?\d[ap]m/
|
173
187
|
|
174
|
-
# e.g. electricity bill on the 28th of every month
|
188
|
+
# e.g. electricity bill on the 28th of every month
|
175
189
|
|
176
190
|
get /(.*) on the #{days} of every (month)/i do |title, day, recurring|
|
177
191
|
|
178
192
|
|
179
193
|
puts 'day: ' + day.inspect if @debug
|
180
194
|
raw_d = Chronic.parse(day + ' ' + Date::MONTHNAMES[@now.month], now: @now)
|
181
|
-
|
195
|
+
|
182
196
|
# if the date is less than now then increment it by a month
|
183
197
|
d = raw_d < @now ? (raw_d.to_date >> 1).to_time : raw_d
|
184
|
-
|
185
|
-
|
198
|
+
|
199
|
+
|
186
200
|
if @debug then
|
187
201
|
puts [0.1, title, recurring, d].inspect.debug
|
188
202
|
end
|
189
|
-
|
190
|
-
{title: title, recurring: recurring, date: d}
|
191
|
-
|
203
|
+
|
204
|
+
{title: title, recurring: recurring, date: d}
|
205
|
+
|
192
206
|
end
|
193
|
-
|
207
|
+
|
194
208
|
#
|
195
209
|
|
196
210
|
get /^(.*)\s+(every \d\w+ \w+#{times}\s*#{starting})/ do \
|
197
211
|
|title, recurring, time, raw_date, end_date|
|
198
212
|
|
199
|
-
input = params[:input].clone
|
213
|
+
input = params[:input].clone
|
200
214
|
d = Chronic.parse(raw_date + ' ' + time.to_s, now: @now)
|
201
215
|
|
202
216
|
if @debug then
|
@@ -204,7 +218,7 @@ class EventNlp
|
|
204
218
|
puts 'd: ' + d.inspect
|
205
219
|
puts 'recurring: ' + recurring.inspect
|
206
220
|
end
|
207
|
-
|
221
|
+
|
208
222
|
if recurring =~ /day|week/ then
|
209
223
|
|
210
224
|
if d < @now then
|
@@ -220,22 +234,22 @@ class EventNlp
|
|
220
234
|
puts 'new_date: ' + new_date.inspect if @debug
|
221
235
|
|
222
236
|
input.gsub!(raw_date, new_date\
|
223
|
-
.strftime("#{new_date.day.ordinal} %b %Y"))
|
237
|
+
.strftime("#{new_date.day.ordinal} %b %Y"))
|
224
238
|
d = new_date
|
225
|
-
|
239
|
+
|
226
240
|
end
|
227
241
|
end
|
228
|
-
|
242
|
+
|
229
243
|
if @debug then
|
230
244
|
puts 'd: ' + d.inspect
|
231
245
|
puts ["0.2", input, title, recurring, time, raw_date, end_date].inspect.debug
|
232
246
|
end
|
233
|
-
|
234
|
-
{input: input, title: title, recurring: recurring, date: d,
|
235
|
-
end_date: end_date}
|
236
|
-
|
247
|
+
|
248
|
+
{input: input, title: title, recurring: recurring, date: d,
|
249
|
+
end_date: end_date}
|
250
|
+
|
237
251
|
end
|
238
|
-
|
252
|
+
|
239
253
|
# e.g. some event 1st Monday of every month (starting 3rd Jul 2017)
|
240
254
|
|
241
255
|
get /^(.*)\s+(\d(?:st|nd|rd|th) \w+ of every \w+(?: at (\d+[ap]m) )?)\s*#{starting}/ do \
|
@@ -243,32 +257,32 @@ class EventNlp
|
|
243
257
|
|
244
258
|
input = params[:input].clone
|
245
259
|
d = Chronic.parse(raw_date, now: @now)
|
246
|
-
|
247
|
-
if recurring =~ /day|week|month/ then
|
248
|
-
|
260
|
+
|
261
|
+
if recurring =~ /day|week|month/ then
|
262
|
+
|
249
263
|
if d < @now then
|
250
264
|
|
251
265
|
new_date = CronFormat.new(ChronicCron.new(recurring)\
|
252
266
|
.to_expression, d).to_time
|
253
267
|
input.gsub!(raw_date, new_date\
|
254
|
-
.strftime("#{new_date.day.ordinal} %b %Y"))
|
268
|
+
.strftime("#{new_date.day.ordinal} %b %Y"))
|
255
269
|
d = new_date
|
256
270
|
else
|
257
271
|
d = ChronicCron.new(recurring, d.to_date.to_time).to_time
|
258
272
|
end
|
259
273
|
end
|
260
|
-
|
274
|
+
|
261
275
|
puts ['0.3'.highlight, title, recurring, time, raw_date, end_date].inspect.debug if @debug
|
262
|
-
{input: input, title: title, recurring: recurring, date: d, end_date:
|
276
|
+
{input: input, title: title, recurring: recurring, date: d, end_date:
|
263
277
|
end_date}
|
264
|
-
|
265
|
-
end
|
278
|
+
|
279
|
+
end
|
266
280
|
|
267
281
|
# some event every 2 weeks
|
268
282
|
# some event every 2 weeks at 6am starting from 14th Jan
|
269
283
|
# some event every 2 weeks at 6am starting from 18th Feb until 28th Oct
|
270
284
|
# some event every 2nd Monday (starting 7th Nov 2016)
|
271
|
-
# some event every 2nd Monday (starting 7th Nov until 3rd Dec)
|
285
|
+
# some event every 2nd Monday (starting 7th Nov until 3rd Dec)
|
272
286
|
# some event every 2 weeks (starting 02/11/17)
|
273
287
|
# some event every Wednesday 1pm-4pm
|
274
288
|
#
|
@@ -277,22 +291,22 @@ class EventNlp
|
|
277
291
|
input = params[:input].clone
|
278
292
|
puts 'recurring: ' + recurring.inspect if @debug
|
279
293
|
raw_start_date = recurring[/(?<=starting )[^\)]+/]
|
280
|
-
|
294
|
+
|
281
295
|
d = if raw_start_date then
|
282
|
-
start_date = Chronic.parse(raw_start_date, now: @now - 1,
|
296
|
+
start_date = Chronic.parse(raw_start_date, now: @now - 1,
|
283
297
|
:endian_precedence => :little)
|
284
298
|
|
285
299
|
puts ('recurring: ' + recurring.inspect).debug if @debug
|
286
300
|
puts ('start_date: ' + start_date.inspect).debug if @debug
|
287
|
-
|
301
|
+
|
288
302
|
if @now > start_date then
|
289
303
|
exp = ChronicCron.new(recurring, start_date, debug: @debug).to_expression
|
290
304
|
puts 'exp: ' + exp.inspect if @debug
|
291
|
-
|
305
|
+
|
292
306
|
cf = CronFormat.new(exp, start_date, debug: @debug)
|
293
307
|
puts ('cf.to_time: ' + cf.to_time.inspect).debug if @debug
|
294
308
|
cf.next until cf.to_time > start_date
|
295
|
-
|
309
|
+
|
296
310
|
new_date = cf.to_time
|
297
311
|
input.gsub!(/(?<=starting )[^\)]+/, new_date\
|
298
312
|
.strftime("#{new_date.day.ordinal} %b %Y"))
|
@@ -301,183 +315,183 @@ class EventNlp
|
|
301
315
|
else
|
302
316
|
start_date
|
303
317
|
end
|
304
|
-
|
318
|
+
|
305
319
|
else
|
306
320
|
exp = ChronicCron.new(recurring).to_expression
|
307
321
|
cf = CronFormat.new(exp, @now)
|
308
322
|
cf.to_time
|
309
323
|
end
|
324
|
+
|
310
325
|
|
311
|
-
|
312
|
-
|
326
|
+
|
313
327
|
if recurring =~ /-/ then
|
314
|
-
end_date = Chronic.parse d.to_date.to_s + ' ' +
|
328
|
+
end_date = Chronic.parse d.to_date.to_s + ' ' +
|
315
329
|
recurring[/(?<=-)\d+(?::\d+)?(?:[ap]m)?/], now: @now
|
316
330
|
end
|
317
|
-
|
331
|
+
|
318
332
|
puts ['0.5'.highlight, title, recurring, d].join("\n").debug if @debug
|
319
|
-
{input: input, title: title.rstrip, recurring: recurring,
|
333
|
+
{input: input, title: title.rstrip, recurring: recurring,
|
320
334
|
date: d, end_date: end_date }
|
321
|
-
|
322
|
-
end
|
323
|
-
|
335
|
+
|
336
|
+
end
|
337
|
+
|
324
338
|
# some meeting 3rd thursday of the month at 7:30pm
|
325
339
|
# some meeting First thursday of the month at 7:30pm
|
326
|
-
get /(.*)\s+(\w+ \w+day of (?:the|every) month at .*)/ do
|
340
|
+
get /(.*)\s+(\w+ \w+day of (?:the|every) month at .*)/ do
|
327
341
|
|title, recurring|
|
328
342
|
|
329
343
|
puts ['1'.highlight, title, recurring].inspect.debug if @debug
|
330
344
|
{ title: title, recurring: recurring }
|
331
345
|
|
332
346
|
end
|
333
|
-
|
334
|
-
|
347
|
+
|
348
|
+
|
335
349
|
# 7th Oct Euston Station (meet at Timothy's house at 7pm)
|
336
350
|
get /^(\d(?:st|nd|rd|th) \w+) *(.*)\s+at\s+(\w+)/i do \
|
337
351
|
|raw_day, title, time|
|
338
|
-
|
352
|
+
|
339
353
|
d = Chronic.parse(raw_day + ' ' + time, now: @now)
|
340
|
-
|
354
|
+
|
341
355
|
puts ['1.5'.highlight, title, raw_day, time].inspect.debug if @debug
|
342
356
|
{ title: title, date: d }
|
343
|
-
|
344
|
-
end
|
357
|
+
|
358
|
+
end
|
345
359
|
|
346
360
|
# some event Wednesday
|
347
361
|
# some event Wednesday 11am
|
348
|
-
|
362
|
+
|
349
363
|
relative_day = '|today|tomorrow|tonight'
|
350
364
|
get /^(.*)\s+(#{weekdays2+relative_day}\b)(?: \(([^\)]+)\)) (at \d{1,2}(?::\d{2})?(?:[ap]m)?)/i \
|
351
365
|
do |title, raw_date, date2, time2|
|
352
366
|
puts ('time2: ' + time2.inspect).debug if @debug
|
353
367
|
puts ('date2: ' + date2).debug if @debug
|
354
368
|
puts ('raw_date: ' + raw_date).debug if @debug
|
355
|
-
|
369
|
+
|
356
370
|
d = if date2 then
|
357
371
|
Chronic.parse(date2 + ' '+ time2.to_s, now: @now)
|
358
372
|
else
|
359
373
|
Chronic.parse(raw_date + ' '+ time2, now: @now)
|
360
374
|
end
|
361
|
-
|
375
|
+
|
362
376
|
puts ['4'.highlight, title, raw_date, date2, time2].inspect.debug if @debug
|
363
377
|
{title: title, date: d }
|
364
|
-
|
378
|
+
|
365
379
|
end
|
366
|
-
|
380
|
+
|
367
381
|
# Group meeting Red Hall 2pm-4pm on Monday (4th Dec 2017)
|
368
382
|
get /^(.*)\s+(#{times2})(?: on) +#{weekdays}\b(?: \(([^\)]+)\))?/i \
|
369
383
|
do |title, xtimes, raw_day, actual_date|
|
370
|
-
|
384
|
+
|
371
385
|
if @debug then
|
372
386
|
puts ('actual_date: ' + actual_date.inspect).debug
|
373
387
|
puts ('raw_day: ' + raw_day.inspect).debug
|
374
388
|
puts ('xtimes: ' + xtimes.inspect).debug
|
375
389
|
end
|
376
|
-
|
390
|
+
|
377
391
|
input = params[:input].clone
|
378
|
-
|
392
|
+
|
379
393
|
if actual_date then
|
380
394
|
d = Chronic.parse actual_date, now: @now
|
381
395
|
else
|
382
396
|
d = Chronic.parse(raw_day, now: @now)
|
383
397
|
input.sub!(/#{weekdays}\b/i,
|
384
|
-
%Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
|
398
|
+
%Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
|
385
399
|
end
|
386
400
|
|
387
401
|
t1, t2 = xtimes.split(/-/,2)
|
388
|
-
|
402
|
+
|
389
403
|
puts ('d: ' + d.inspect).debug if @debug
|
390
404
|
|
391
405
|
d1, d2 = [t1, t2].map {|t| Chronic.parse([d.to_date.to_s, t].join(' '), now: @now) }
|
392
|
-
|
406
|
+
|
393
407
|
puts ['4.65'.highlight, input, title, raw_day, d1, d2].inspect.debug if @debug
|
394
|
-
|
408
|
+
|
395
409
|
{input: input, title: title, date: d1, end_date: d2 }
|
396
|
-
|
397
|
-
end
|
398
|
-
|
410
|
+
|
411
|
+
end
|
412
|
+
|
399
413
|
# hall 2 friday at 11am
|
400
414
|
|
401
415
|
get /^(.*)\s+#{weekdays}\b(?: \(([^\)]+)\))?(?:#{times})? *(weekly)?/i \
|
402
416
|
do |title, raw_day, actual_date, time, recurring|
|
403
|
-
|
417
|
+
|
404
418
|
if @debug then
|
405
419
|
puts ('recurring: ' + recurring.inspect).debug
|
406
420
|
puts ('actual_date: ' + actual_date.inspect).debug
|
407
421
|
puts ('raw_day: ' + raw_day.inspect).debug
|
408
422
|
puts ('time: ' + time.inspect).debug
|
409
423
|
end
|
410
|
-
|
424
|
+
|
411
425
|
input = params[:input].clone
|
412
426
|
|
413
427
|
d = Chronic.parse(raw_day + ' ' + time.to_s, now: @now)
|
414
428
|
|
415
429
|
if recurring.nil?
|
416
430
|
input.sub!(/#{weekdays}/i,
|
417
|
-
%Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
|
431
|
+
%Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
|
418
432
|
end
|
419
|
-
|
433
|
+
|
420
434
|
puts ('d: ' + d.inspect).debug if @debug
|
421
|
-
|
435
|
+
|
422
436
|
puts [1.7, input, title, raw_day].inspect.debug if @debug
|
423
|
-
|
437
|
+
|
424
438
|
{input: input, title: title, date: d }
|
425
|
-
|
426
|
-
end
|
427
|
-
|
428
|
-
|
439
|
+
|
440
|
+
end
|
441
|
+
|
442
|
+
|
429
443
|
# e.g. 21/05/2017 Forum meetup at Roundpeg from 2pm
|
430
|
-
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
|
431
445
|
|raw_date, title, raw_time|
|
432
|
-
|
433
|
-
d = Chronic.parse(raw_date + ' ' +
|
446
|
+
|
447
|
+
d = Chronic.parse(raw_date + ' ' +
|
434
448
|
raw_time, now: @now, :endian_precedence => :little)
|
435
|
-
recurring = nil
|
436
|
-
|
449
|
+
recurring = nil
|
450
|
+
|
437
451
|
puts [3, title, raw_date].inspect.debug if @debug
|
438
452
|
{ title: title, date: d }
|
439
|
-
end
|
440
|
-
|
453
|
+
end
|
454
|
+
|
441
455
|
# friday hall 2 11am until 12am
|
442
456
|
get /^#{weekdays}\s+(.*)\s+#{times} until #{times}$/i do \
|
443
457
|
|raw_day, title, start_time, end_time|
|
444
|
-
|
458
|
+
|
445
459
|
venue = title[/^at +(.*)/,1]
|
446
460
|
d = Chronic.parse(raw_day + ' ' + start_time, now: @now)
|
447
461
|
d2 = Chronic.parse(raw_day + ' ' + end_time, now: @now)
|
448
|
-
|
462
|
+
|
449
463
|
puts ['1.44.3', title, raw_day].inspect.debug if @debug
|
450
464
|
{ title: title, date: d, end_date: d2, venue: venue }
|
451
|
-
|
452
|
-
end
|
453
|
-
|
465
|
+
|
466
|
+
end
|
467
|
+
|
454
468
|
# friday hall 2 11am
|
455
469
|
get /^#{weekdays}\b\s+(.*)\s+(\d+(?::\d{2})?[ap]m)$/i do \
|
456
470
|
|raw_day, title, time|
|
457
|
-
|
471
|
+
|
458
472
|
puts [raw_day, title, time].inspect if @debug
|
459
473
|
venue = title[/^at +(.*)/,1]
|
460
474
|
d = Chronic.parse(raw_day + ' ' + time, now: @now)
|
461
|
-
|
475
|
+
|
462
476
|
puts [1.44, title, raw_day].inspect.debug if @debug
|
463
477
|
{ title: title, date: d, venue: venue }
|
464
|
-
|
465
|
-
end
|
478
|
+
|
479
|
+
end
|
466
480
|
|
467
481
|
# Tuesday 10th July hall 2 at 11am
|
468
482
|
get /#{weekdays}\b\s+#{days}\s+#{months}\s+(?:at )?(.*)\s+at\s+(#{times})/i \
|
469
483
|
do |wday, day, month, title, time|
|
470
|
-
|
484
|
+
|
471
485
|
d = Chronic.parse([day, month, time].join(' '), now: @now)
|
472
|
-
|
486
|
+
|
473
487
|
puts ['1.44.5', day, month, title].inspect.debug if @debug
|
474
488
|
{ title: title, date: d }
|
475
|
-
|
476
|
-
end
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
489
|
+
|
490
|
+
end
|
491
|
+
|
492
|
+
|
493
|
+
|
494
|
+
|
481
495
|
# 27-Mar@1436 some important day
|
482
496
|
# 25/07/2017 11pm some important day
|
483
497
|
#
|
@@ -487,22 +501,22 @@ class EventNlp
|
|
487
501
|
d = Chronic.parse(raw_date + ' ' + time.to_s, now: @now,
|
488
502
|
:endian_precedence => :little)
|
489
503
|
recurring = nil
|
490
|
-
|
504
|
+
|
491
505
|
if annualar then
|
492
|
-
|
506
|
+
|
493
507
|
recurring = 'yearly'
|
494
508
|
if d < @now then
|
495
|
-
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))
|
496
510
|
end
|
497
511
|
end
|
498
|
-
|
499
|
-
|
512
|
+
|
513
|
+
|
500
514
|
puts [3, title, raw_date, time].inspect.debug if @debug
|
501
515
|
{ title: title, date: d, recurring: recurring }
|
502
516
|
end
|
503
517
|
|
504
518
|
|
505
|
-
|
519
|
+
|
506
520
|
# Some event (10 Woodhouse Lane) 30th Nov from 9:15-17:00
|
507
521
|
|
508
522
|
get /^(.*) #{days} #{months}(?: from)? (#{times2})/i do \
|
@@ -517,7 +531,7 @@ class EventNlp
|
|
517
531
|
|
518
532
|
{ title: title, date: d1, end_date: d2 }
|
519
533
|
end
|
520
|
-
|
534
|
+
|
521
535
|
# Some event (10 Woodhouse Lane) 30th Nov from 9:15-17:00
|
522
536
|
|
523
537
|
get /^#{weekdays}\b #{months} #{days} #{times3} (.*)/i do \
|
@@ -532,7 +546,7 @@ class EventNlp
|
|
532
546
|
puts [4.55, title, d1, d2].inspect.debug if @debug
|
533
547
|
|
534
548
|
{ title: title, date: d1, end_date: d2 }
|
535
|
-
end
|
549
|
+
end
|
536
550
|
|
537
551
|
# e.g. Wednesday 30th Nov at 9:15 10 Woodhouse Lane
|
538
552
|
|
@@ -573,7 +587,7 @@ class EventNlp
|
|
573
587
|
|
574
588
|
{ title: title.sub(/ on$/,''), date: d1 }
|
575
589
|
end
|
576
|
-
|
590
|
+
|
577
591
|
# Some event (10 Woodhouse Lane) 30th Nov at 9:15-
|
578
592
|
|
579
593
|
get /^(.*) #{days} #{months}(?: at)? (#{times})/i do \
|
@@ -590,73 +604,73 @@ class EventNlp
|
|
590
604
|
# hall 2 at 11am
|
591
605
|
#
|
592
606
|
get /(.*)\s+at\s+(#{times})/i do |title, time|
|
593
|
-
|
607
|
+
|
594
608
|
d = Chronic.parse(time, now: @now)
|
595
|
-
|
609
|
+
|
596
610
|
puts [1.45, title].inspect.debug if @debug
|
597
611
|
{ title: title, date: d }
|
598
|
-
|
599
|
-
end
|
600
|
-
|
601
|
-
|
612
|
+
|
613
|
+
end
|
614
|
+
|
615
|
+
|
602
616
|
# Council Tax on the last day of the month
|
603
617
|
#
|
604
618
|
get /^(.*) (?:o[nf] the)\s*last day of the month/i do |title|
|
605
|
-
|
619
|
+
|
606
620
|
td = @now.to_date
|
607
621
|
d = Date.civil(td.year, td.month, -1).to_time
|
608
|
-
|
622
|
+
|
609
623
|
puts [5, title].inspect.debug if @debug
|
610
624
|
{ title: title, date: d }
|
611
|
-
|
612
|
-
end
|
613
|
-
|
625
|
+
|
626
|
+
end
|
627
|
+
|
614
628
|
# Council Tax last day of the month
|
615
629
|
#
|
616
630
|
get /^(.*) +last day of the month/i do |title|
|
617
|
-
|
631
|
+
|
618
632
|
td = @now.to_date
|
619
633
|
d = Date.civil(td.year, td.month, -1).to_time
|
620
|
-
|
634
|
+
|
621
635
|
puts [5.1, title].inspect.debug if @debug
|
622
636
|
{ title: title, date: d }
|
623
|
-
|
624
|
-
end
|
625
|
-
|
637
|
+
|
638
|
+
end
|
639
|
+
|
626
640
|
# some important day 11 Oct *
|
627
641
|
#
|
628
642
|
get /^(.*) +(\d+) +#{months} *(\*)?/i \
|
629
643
|
do |title, day, month, annualar|
|
630
|
-
|
644
|
+
|
631
645
|
raw_date = day + ' ' + month
|
632
646
|
|
633
647
|
d = Chronic.parse(raw_date, now: @now,
|
634
648
|
:endian_precedence => :little)
|
635
649
|
recurring = nil
|
636
|
-
|
650
|
+
|
637
651
|
if annualar then
|
638
|
-
|
652
|
+
|
639
653
|
recurring = 'yearly'
|
640
654
|
if d < @now then
|
641
|
-
d = Chronic.parse(raw_date,
|
642
|
-
now: Time.local(@now.year + 1, 1, 1))
|
655
|
+
d = Chronic.parse(raw_date,
|
656
|
+
now: Time.local(@now.year + 1, 1, 1))
|
643
657
|
end
|
644
658
|
end
|
645
|
-
|
646
|
-
|
659
|
+
|
660
|
+
|
647
661
|
puts [6, title, raw_date].inspect.debug if @debug
|
648
662
|
{ title: title, date: d, recurring: recurring }
|
649
663
|
end
|
650
|
-
|
651
|
-
|
652
|
-
|
664
|
+
|
665
|
+
|
666
|
+
|
653
667
|
# Tuesday 3rd October gas service at Barbara's house morning 9am-1pm
|
654
668
|
#
|
655
669
|
get '*' do
|
656
|
-
|
670
|
+
|
657
671
|
s = params[:input]
|
658
|
-
|
659
|
-
time1, time2, month, weekday, day, end_date, annualar = nil, nil, nil,
|
672
|
+
|
673
|
+
time1, time2, month, weekday, day, end_date, annualar = nil, nil, nil,
|
660
674
|
nil, nil, nil, false
|
661
675
|
|
662
676
|
s2 = s.sub(/#{times}/i) {|x| time1 = x; ''}
|
@@ -671,29 +685,29 @@ class EventNlp
|
|
671
685
|
raw_date = [day, month].compact.join(' ')
|
672
686
|
raw_date = weekday if raw_date.empty?
|
673
687
|
|
674
|
-
d = Chronic.parse(raw_date + ' ' + time1.to_s,
|
688
|
+
d = Chronic.parse(raw_date + ' ' + time1.to_s,
|
675
689
|
:endian_precedence => :little, now: @now)
|
676
|
-
|
690
|
+
|
677
691
|
if time2 then
|
678
692
|
end_date = Chronic.parse(raw_date + ' ' + time2.to_s, now: @now,
|
679
693
|
:endian_precedence => :little)
|
680
694
|
end
|
681
|
-
|
695
|
+
|
682
696
|
recurring = nil
|
683
|
-
|
697
|
+
|
684
698
|
if annualar then
|
685
|
-
|
699
|
+
|
686
700
|
recurring = 'yearly'
|
687
701
|
if d < @now then
|
688
|
-
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))
|
689
703
|
end
|
690
|
-
end
|
691
|
-
|
704
|
+
end
|
705
|
+
|
692
706
|
puts [10, title, raw_date, time1].inspect.debug if @debug
|
693
707
|
{ title: title, date: d, end_date: end_date, recurring: recurring }
|
694
|
-
end
|
695
|
-
|
696
|
-
|
708
|
+
end
|
709
|
+
|
710
|
+
|
697
711
|
end
|
698
|
-
|
712
|
+
|
699
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
|