event_nlp 0.5.3 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/event_nlp.rb +219 -184
  4. data.tar.gz.sig +2 -1
  5. metadata +36 -31
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42e47f457a1e07759fc8b3de0ae3f85d35fc0679e252c9c52570457e5d389125
4
- data.tar.gz: 58cabc06778bed4444a025092f47699089627145c06ab91befc1f02050e1a61a
3
+ metadata.gz: c4ec4582a9a97efbf6e4b24803edb1675c8cc8bbcdff692b90472502bfd71c1e
4
+ data.tar.gz: 63226f49c9ad8b5f2219cc8506152c5ddaed21e97e0e7c6e55c017bc83d3e644
5
5
  SHA512:
6
- metadata.gz: e223d22b9a2404c8467fce4b9b8f58b9889dfffa15a3c83aaccc5c8d3912abaf50cf26bc46fbfc84744f345afa6905fbfcd7f27a49293d4b915c6cba72e49a47
7
- data.tar.gz: b8f40f7a4168aaed947b00a2bbab9fd7864fc81388305cd8f6ede785bf84added0bef7fa3561f16400f35e2309eb0aefc0bdfab44ebef53df088058103eb3c19
6
+ metadata.gz: eab396db7a03c0416d71eb911d4bd35d573f33a265c8aa773dcbbf45368a8702df0f695701ee3f2472c084106de6c60d3aee5826e68ec8c032770be191db7a76
7
+ data.tar.gz: b70f2239f852026b7b3559c0814c331be502a47410ecdf8808646faec727c5adc17e282d8d9159c2bf4658d2ce03ddf161d0b84433b95cbe529658cf965b0b29
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/event_nlp.rb CHANGED
@@ -12,7 +12,7 @@ module Ordinals
12
12
 
13
13
  refine Integer do
14
14
  def ordinal
15
- self.to_s + ( (10...20).include?(self) ? 'th' :
15
+ self.to_s + ( self.between?(10,20) ? 'th' :
16
16
  %w{ th st nd rd th th th th th th }[self % 10] )
17
17
  end
18
18
  end
@@ -23,99 +23,132 @@ class EventNlp
23
23
  include AppRoutes
24
24
  using Ordinals
25
25
  using ColouredText
26
-
26
+
27
27
  attr_accessor :params
28
-
28
+
29
29
  def initialize(now=Time.now, params: {}, debug: false)
30
-
30
+
31
31
  super()
32
-
32
+
33
33
  @now = now
34
34
  @params = params
35
35
  expressions(@params)
36
36
  @debug = debug
37
37
 
38
38
  end
39
-
40
- def parse(s)
39
+
40
+ def parse(raws)
41
+
42
+ # catch irregular expressions and interpret them in advance
43
+ #
44
+ # e.g. Cafe meeting Thursday every 2 weeks =>
45
+ # Cafe meeting every 2nd Thursday
46
+ #
47
+ weekdays2 = (Date::DAYNAMES + Date::ABBR_DAYNAMES).join('|').downcase
48
+ pattern = /(?<day>#{weekdays2}) every (?<n>\d) weeks/i
49
+ found = raws.match(pattern)
50
+
51
+ s = if found then
52
+ s2 = "every %s %s" % [found[:n].to_i.ordinal, found[:day]]
53
+ raws.sub(pattern, s2)
54
+ else
55
+ raws
56
+ end
57
+
58
+ #-----------------------------------------------------------
41
59
 
42
60
  @params[:input] = s
43
61
  r = run_route(s)
44
62
 
45
63
  return unless r.is_a? Hash
46
-
64
+
47
65
  OpenStruct.new({input: s}.merge r)
48
-
49
- end
66
+
67
+ end
50
68
 
51
69
  private
52
70
 
53
- def expressions(params)
71
+ def expressions(params)
54
72
 
55
73
  starting = /(?:\(?\s*starting (\d+\w{2} \w+\s*\w*)(?: until (.*))?\s*\))?/
56
- weekdays2 = (Date::DAYNAMES + Date::ABBR_DAYNAMES).join('|').downcase
74
+ weekdays2 = (Date::DAYNAMES + Date::ABBR_DAYNAMES).join('|').downcase
57
75
  weekdays = "(%s)" % weekdays2
58
76
  months = "(%s)" % (Date::MONTHNAMES[1..-1] + Date::ABBR_MONTHNAMES[1..-1])\
59
77
  .join('|').downcase
60
78
  times = /(?: *(?:at |@ |from )?(\d+(?::\d+)?(?:[ap]m|\b)) *)/
61
79
  times2 = /\d+(?::\d+)?[ap]m-\d+(?::\d+)?[ap]m|\d+(?::\d+)?-\d+(?::\d+)?/
62
- times3 = /(\d+(?::\d+)?[ap]m-\d+(?::\d+)?[ap]m|\d+(?::\d+)?-\d+(?::\d+)?)/
80
+ times3 = /(\d+(?::\d+)?[ap]m-\d+(?::\d+)?[ap]m|\d+(?::\d+)?-\d+(?::\d+)?)/
63
81
  days = /(\d+(?:st|nd|rd|th))/
64
82
  periods = /day|week|month/
65
-
83
+
66
84
  #weekdays = Date::DAYNAMES.join('|').downcase
67
85
  #
68
-
86
+
69
87
  #times = /(?: *at )?\d[ap]m/
70
88
 
71
- # e.g. electricity bill on the 28th of every month
89
+ # e.g. electricity bill on the 28th of every month
72
90
 
73
91
  get /(.*) on the (#{days}) of every (#{periods})/ do |title, day, recurring|
74
92
 
75
93
 
76
94
  raw_d = Chronic.parse(day)
77
-
95
+
78
96
  # if the date is less than now then increment it by a month
79
97
  d = raw_d < @now ? (raw_d.to_date >> 1).to_time : raw_d
80
-
81
-
98
+
99
+
82
100
  if @debug then
83
101
  puts [0.1, title, recurring, d].inspect.debug
84
102
  end
85
-
86
- {title: title, recurring: recurring, date: d}
87
-
103
+
104
+ {title: title, recurring: recurring, date: d}
105
+
88
106
  end
89
-
90
107
 
91
- get /^(.*)\s+(every \d\w+ \w+#{times})\s*#{starting}/ do \
108
+
109
+ get /^(.*)\s+(every \d\w+ \w+#{times}\s*#{starting})/ do \
92
110
  |title, recurring, time, raw_date, end_date|
93
111
 
94
- input = params[:input].clone
112
+ input = params[:input].clone
95
113
  d = Chronic.parse(raw_date + ' ' + time.to_s)
96
-
114
+
115
+ if @debug then
116
+ puts 'e300'
117
+ puts 'd: ' + d.inspect
118
+ puts 'recurring: ' + recurring.inspect
119
+ end
120
+
97
121
  if recurring =~ /day|week/ then
98
122
 
99
123
  if d < @now then
100
124
 
101
- new_date = CronFormat.new(ChronicCron.new(recurring)\
102
- .to_expression, d).to_time
125
+ cc = ChronicCron.new(recurring, d)
126
+ exp = cc.to_expression
127
+ puts 'exp: ' + exp.inspect if @debug
128
+
129
+ cf = CronFormat.new(exp, d)
130
+ cf.next until cf.to_time > @now
131
+
132
+ new_date = cf.to_time
133
+ puts 'new_date: ' + new_date.inspect if @debug
134
+
103
135
  input.gsub!(raw_date, new_date\
104
- .strftime("#{new_date.day.ordinal} %b %Y"))
136
+ .strftime("#{new_date.day.ordinal} %b %Y"))
105
137
  d = new_date
106
-
138
+
107
139
  end
108
140
  end
109
-
141
+
110
142
  if @debug then
111
- puts [0.2, input, title, recurring, time, raw_date, end_date].inspect.debug
143
+ puts 'd: ' + d.inspect
144
+ puts ["0.2", input, title, recurring, time, raw_date, end_date].inspect.debug
112
145
  end
113
-
114
- {input: input, title: title, recurring: recurring, date: d,
115
- end_date: end_date}
116
-
146
+
147
+ {input: input, title: title, recurring: recurring, date: d,
148
+ end_date: end_date}
149
+
117
150
  end
118
-
151
+
119
152
  # e.g. some event 1st Monday of every month (starting 3rd Jul 2017)
120
153
 
121
154
  get /^(.*)\s+(\d(?:st|nd|rd|th) \w+ of every \w+(?: at (\d+[ap]m) )?)\s*#{starting}/ do \
@@ -123,54 +156,56 @@ class EventNlp
123
156
 
124
157
  input = params[:input].clone
125
158
  d = Chronic.parse(raw_date)
126
-
127
- if recurring =~ /day|week|month/ then
128
-
159
+
160
+ if recurring =~ /day|week|month/ then
161
+
129
162
  if d < @now then
130
163
 
131
164
  new_date = CronFormat.new(ChronicCron.new(recurring)\
132
165
  .to_expression, d).to_time
133
166
  input.gsub!(raw_date, new_date\
134
- .strftime("#{new_date.day.ordinal} %b %Y"))
167
+ .strftime("#{new_date.day.ordinal} %b %Y"))
135
168
  d = new_date
136
169
  else
137
170
  d = ChronicCron.new(recurring, d.to_date.to_time).to_time
138
171
  end
139
172
  end
140
-
141
- puts [0.3, title, recurring, time, raw_date, end_date].inspect.debug if @debug
142
- {input: input, title: title, recurring: recurring, date: d, end_date:
173
+
174
+ puts ['0.3'.highlight, title, recurring, time, raw_date, end_date].inspect.debug if @debug
175
+ {input: input, title: title, recurring: recurring, date: d, end_date:
143
176
  end_date}
144
-
145
- end
177
+
178
+ end
146
179
 
147
180
  # some event every 2 weeks
148
181
  # some event every 2 weeks at 6am starting from 14th Jan
149
182
  # some event every 2 weeks at 6am starting from 18th Feb until 28th Oct
150
183
  # some event every 2nd Monday (starting 7th Nov 2016)
151
- # some event every 2nd Monday (starting 7th Nov until 3rd Dec)
184
+ # some event every 2nd Monday (starting 7th Nov until 3rd Dec)
152
185
  # some event every 2 weeks (starting 02/11/17)
153
186
  # some event every Wednesday 1pm-4pm
154
187
  #
155
188
  get /^(.*)(every .*)/ do |title, recurring|
156
189
 
157
190
  input = params[:input].clone
191
+ puts 'recurring: ' + recurring.inspect if @debug
158
192
  raw_start_date = recurring[/(?<=starting )[^\)]+/]
159
-
193
+
160
194
  d = if raw_start_date then
161
- start_date = Chronic.parse(raw_start_date, now: @now - 1,
195
+ start_date = Chronic.parse(raw_start_date, now: @now - 1,
162
196
  :endian_precedence => :little)
163
197
 
198
+ puts ('recurring: ' + recurring.inspect).debug if @debug
164
199
  puts ('start_date: ' + start_date.inspect).debug if @debug
165
-
200
+
166
201
  if @now > start_date then
167
- exp = ChronicCron.new(recurring, start_date).to_expression
202
+ exp = ChronicCron.new(recurring, start_date, debug: @debug).to_expression
168
203
  puts 'exp: ' + exp.inspect if @debug
169
-
170
- cf = CronFormat.new(exp, start_date)
171
- puts cf.to_time if @debug
172
- #cf.next until cf.to_time >= start_date
173
-
204
+
205
+ cf = CronFormat.new(exp, start_date, debug: @debug)
206
+ puts ('cf.to_time: ' + cf.to_time.inspect).debug if @debug
207
+ cf.next until cf.to_time > start_date
208
+
174
209
  new_date = cf.to_time
175
210
  input.gsub!(/(?<=starting )[^\)]+/, new_date\
176
211
  .strftime("#{new_date.day.ordinal} %b %Y"))
@@ -179,208 +214,208 @@ class EventNlp
179
214
  else
180
215
  start_date
181
216
  end
182
-
217
+
183
218
  else
184
219
  exp = ChronicCron.new(recurring).to_expression
185
220
  cf = CronFormat.new(exp, @now)
186
221
  cf.to_time
187
222
  end
188
-
189
223
 
190
-
224
+
225
+
191
226
  if recurring =~ /-/ then
192
- end_date = Chronic.parse d.to_date.to_s + ' ' +
193
- recurring[/(?<=-)\d+(?::\d+)?(?:[ap]m)?/]
227
+ end_date = Chronic.parse d.to_date.to_s + ' ' +
228
+ recurring[/(?<=-)\d+(?::\d+)?(?:[ap]m)?/]
194
229
  end
195
-
196
- puts [0.5, title, recurring, d].inspect.debug if @debug
197
- {input: input, title: title.rstrip, recurring: recurring,
230
+
231
+ puts ['0.5'.highlight, title, recurring, d].join("\n").debug if @debug
232
+ {input: input, title: title.rstrip, recurring: recurring,
198
233
  date: d, end_date: end_date }
199
-
200
- end
201
-
234
+
235
+ end
236
+
202
237
  # some meeting 3rd thursday of the month at 7:30pm
203
238
  # some meeting First thursday of the month at 7:30pm
204
- get /(.*)\s+(\w+ \w+day of (?:the|every) month at .*)/ do
239
+ get /(.*)\s+(\w+ \w+day of (?:the|every) month at .*)/ do
205
240
  |title, recurring|
206
241
 
207
- puts [1, title, recurring].inspect.debug if @debug
242
+ puts ['1'.highlight, title, recurring].inspect.debug if @debug
208
243
  { title: title, recurring: recurring }
209
244
 
210
245
  end
211
-
212
-
246
+
247
+
213
248
  # 7th Oct Euston Station (meet at Timothy's house at 7pm)
214
249
  get /^(\d(?:st|nd|rd|th) \w+) *(.*)\s+at\s+(\w+)/i do \
215
250
  |raw_day, title, time|
216
-
251
+
217
252
  d = Chronic.parse(raw_day + ' ' + time)
218
-
219
- puts [1.5, title, raw_day, time].inspect.debug if @debug
253
+
254
+ puts ['1.5'.highlight, title, raw_day, time].inspect.debug if @debug
220
255
  { title: title, date: d }
221
-
222
- end
256
+
257
+ end
223
258
 
224
259
  # some event Wednesday
225
260
  # some event Wednesday 11am
226
-
261
+
227
262
  relative_day = '|today|tomorrow|tonight'
228
263
  get /^(.*)\s+(#{weekdays2+relative_day}\b)(?: \(([^\)]+)\)) (at \d{1,2}(?::\d{2})?(?:[ap]m)?)/i \
229
264
  do |title, raw_date, date2, time2|
230
265
  puts ('time2: ' + time2.inspect).debug if @debug
231
266
  puts ('date2: ' + date2).debug if @debug
232
267
  puts ('raw_date: ' + raw_date).debug if @debug
233
-
268
+
234
269
  d = if date2 then
235
270
  Chronic.parse(date2 + ' '+ time2.to_s)
236
271
  else
237
272
  Chronic.parse(raw_date + ' '+ time2)
238
273
  end
239
-
240
- puts [4, title, raw_date, date2, time2].inspect.debug if @debug
274
+
275
+ puts ['4'.highlight, title, raw_date, date2, time2].inspect.debug if @debug
241
276
  {title: title, date: d }
242
-
277
+
243
278
  end
244
-
279
+
245
280
  # Group meeting Red Hall 2pm-4pm on Monday (4th Dec 2017)
246
281
  get /^(.*)\s+(#{times2})(?: on) +#{weekdays}\b(?: \(([^\)]+)\))?/i \
247
282
  do |title, xtimes, raw_day, actual_date|
248
-
283
+
249
284
  if @debug then
250
285
  puts ('actual_date: ' + actual_date.inspect).debug
251
286
  puts ('raw_day: ' + raw_day.inspect).debug
252
287
  puts ('xtimes: ' + xtimes.inspect).debug
253
288
  end
254
-
289
+
255
290
  input = params[:input].clone
256
-
291
+
257
292
  if actual_date then
258
293
  d = Chronic.parse actual_date
259
294
  else
260
- d = Chronic.parse(raw_day)
295
+ d = Chronic.parse(raw_day)
261
296
  input.sub!(/#{weekdays}\b/i,
262
- %Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
297
+ %Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
263
298
  end
264
299
 
265
300
  t1, t2 = xtimes.split(/-/,2)
266
-
301
+
267
302
  puts ('d: ' + d.inspect).debug if @debug
268
303
 
269
304
  d1, d2 = [t1, t2].map {|t| Chronic.parse([d.to_date.to_s, t].join(' ')) }
270
-
271
- puts [4.65, input, title, raw_day, d1, d2].inspect.debug if @debug
272
-
305
+
306
+ puts ['4.65'.highlight, input, title, raw_day, d1, d2].inspect.debug if @debug
307
+
273
308
  {input: input, title: title, date: d1, end_date: d2 }
274
-
275
- end
276
-
309
+
310
+ end
311
+
277
312
  # hall 2 friday at 11am
278
313
 
279
314
  get /^(.*)\s+#{weekdays}\b(?: \(([^\)]+)\))?(#{times})?/i \
280
315
  do |title, raw_day, actual_date, time|
281
-
316
+
282
317
  if @debug then
283
318
  puts ('actual_date: ' + actual_date.inspect).debug
284
319
  puts ('raw_day: ' + raw_day.inspect).debug
285
320
  puts ('time: ' + time.inspect).debug
286
321
  end
287
-
322
+
288
323
  input = params[:input].clone
289
-
324
+
290
325
  if actual_date then
291
326
  d = Chronic.parse(raw_day + ' ' + time.to_s)
292
327
  else
293
- d = Chronic.parse(raw_day + ' ' + time.to_s)
328
+ d = Chronic.parse(raw_day + ' ' + time.to_s)
294
329
  input.sub!(/#{weekdays}/i,
295
- %Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
330
+ %Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
296
331
  end
297
-
332
+
298
333
  puts ('d: ' + d.inspect).debug if @debug
299
-
334
+
300
335
  puts [1.7, input, title, raw_day].inspect.debug if @debug
301
-
336
+
302
337
  {input: input, title: title, date: d }
303
-
304
- end
305
-
306
-
338
+
339
+ end
340
+
341
+
307
342
  # e.g. 21/05/2017 Forum meetup at Roundpeg from 2pm
308
- get /^(\d+\/\d+\/\d+)\s+(.*)(?: from|at)\s+(\d+[ap]m)/ do
343
+ get /^(\d+\/\d+\/\d+)\s+(.*)(?: from|at)\s+(\d+[ap]m)/ do
309
344
  |raw_date, title, raw_time|
310
-
311
- d = Chronic.parse(raw_date + ' ' +
345
+
346
+ d = Chronic.parse(raw_date + ' ' +
312
347
  raw_time, :endian_precedence => :little)
313
- recurring = nil
314
-
348
+ recurring = nil
349
+
315
350
  puts [3, title, raw_date].inspect.debug if @debug
316
351
  { title: title, date: d }
317
- end
318
-
352
+ end
353
+
319
354
  # friday hall 2 11am until 12am
320
355
  get /^#{weekdays}\s+(.*)\s+#{times} until #{times}$/i do \
321
356
  |raw_day, title, start_time, end_time|
322
-
357
+
323
358
  venue = title[/^at +(.*)/,1]
324
359
  d = Chronic.parse(raw_day + ' ' + start_time)
325
360
  d2 = Chronic.parse(raw_day + ' ' + end_time)
326
-
361
+
327
362
  puts ['1.44.3', title, raw_day].inspect.debug if @debug
328
363
  { title: title, date: d, end_date: d2, venue: venue }
329
-
330
- end
331
-
364
+
365
+ end
366
+
332
367
  # friday hall 2 11am
333
368
  get /^#{weekdays}\b\s+(.*)\s+(\d+(?::\d{2})?[ap]m)$/i do \
334
369
  |raw_day, title, time|
335
-
370
+
336
371
  puts [raw_day, title, time].inspect if @debug
337
372
  venue = title[/^at +(.*)/,1]
338
373
  d = Chronic.parse(raw_day + ' ' + time)
339
-
374
+
340
375
  puts [1.44, title, raw_day].inspect.debug if @debug
341
376
  { title: title, date: d, venue: venue }
342
-
343
- end
377
+
378
+ end
344
379
 
345
380
  # Tuesday 10th July hall 2 at 11am
346
381
  get /#{weekdays}\b\s+#{days}\s+#{months}\s+(?:at )?(.*)\s+at\s+(#{times})/i \
347
382
  do |wday, day, month, title, time|
348
-
383
+
349
384
  d = Chronic.parse([day, month, time].join(' '))
350
-
385
+
351
386
  puts ['1.44.5', day, month, title].inspect.debug if @debug
352
387
  { title: title, date: d }
353
-
354
- end
355
-
356
-
357
-
358
-
388
+
389
+ end
390
+
391
+
392
+
393
+
359
394
  # 27-Mar@1436 some important day
360
395
  # 25/07/2017 11pm some important day
361
396
  #
362
397
  get /^(\d+\/\d+\/\d+)\s*(\d+(?:\:\d+)?[ap]m)?\s+([^\*]+)(\*)?/ \
363
398
  do |raw_date, time, title, annualar|
364
399
 
365
- d = Chronic.parse(raw_date + ' ' + time.to_s,
400
+ d = Chronic.parse(raw_date + ' ' + time.to_s,
366
401
  :endian_precedence => :little)
367
402
  recurring = nil
368
-
403
+
369
404
  if annualar then
370
-
405
+
371
406
  recurring = 'yearly'
372
407
  if d < @now then
373
- d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
408
+ d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
374
409
  end
375
410
  end
376
-
377
-
411
+
412
+
378
413
  puts [3, title, raw_date, time].inspect.debug if @debug
379
414
  { title: title, date: d, recurring: recurring }
380
415
  end
381
416
 
382
417
 
383
-
418
+
384
419
  # Some event (10 Woodhouse Lane) 30th Nov from 9:15-17:00
385
420
 
386
421
  get /^(.*) #{days} #{months}(?: from)? (#{times2})/i do \
@@ -395,7 +430,7 @@ class EventNlp
395
430
 
396
431
  { title: title, date: d1, end_date: d2 }
397
432
  end
398
-
433
+
399
434
  # Some event (10 Woodhouse Lane) 30th Nov from 9:15-17:00
400
435
 
401
436
  get /^#{weekdays}\b #{months} #{days} #{times3} (.*)/i do \
@@ -410,7 +445,7 @@ class EventNlp
410
445
  puts [4.55, title, d1, d2].inspect.debug if @debug
411
446
 
412
447
  { title: title, date: d1, end_date: d2 }
413
- end
448
+ end
414
449
 
415
450
  # e.g. Wednesday 30th Nov at 9:15 10 Woodhouse Lane
416
451
 
@@ -422,8 +457,8 @@ class EventNlp
422
457
  puts [4.6, title, d1].inspect.debug if @debug
423
458
 
424
459
  { title: title, date: d1 }
425
- end
426
-
460
+ end
461
+
427
462
  # Some event (10 Woodhouse Lane) 30th Nov at 9:15-
428
463
 
429
464
  get /^(.*) #{days} #{months}(?: at)? (#{times})/i do \
@@ -440,73 +475,73 @@ class EventNlp
440
475
  # hall 2 at 11am
441
476
  #
442
477
  get /(.*)\s+at\s+(#{times})/i do |title, time|
443
-
478
+
444
479
  d = Chronic.parse(time)
445
-
480
+
446
481
  puts [1.45, title].inspect.debug if @debug
447
482
  { title: title, date: d }
448
-
449
- end
450
-
451
-
483
+
484
+ end
485
+
486
+
452
487
  # Council Tax on the last day of the month
453
488
  #
454
489
  get /^(.*) (?:o[nf] the)\s*last day of the month/i do |title|
455
-
490
+
456
491
  td = @now.to_date
457
492
  d = Date.civil(td.year, td.month, -1).to_time
458
-
493
+
459
494
  puts [5, title].inspect.debug if @debug
460
495
  { title: title, date: d }
461
-
462
- end
463
-
496
+
497
+ end
498
+
464
499
  # Council Tax last day of the month
465
500
  #
466
501
  get /^(.*) +last day of the month/i do |title|
467
-
502
+
468
503
  td = @now.to_date
469
504
  d = Date.civil(td.year, td.month, -1).to_time
470
-
505
+
471
506
  puts [5.1, title].inspect.debug if @debug
472
507
  { title: title, date: d }
473
-
474
- end
475
-
508
+
509
+ end
510
+
476
511
  # some important day 11 Oct *
477
512
  #
478
513
  get /^(.*) +(\d+) +#{months} *(\*)?/i \
479
514
  do |title, day, month, annualar|
480
-
515
+
481
516
  raw_date = day + ' ' + month
482
517
 
483
- d = Chronic.parse(raw_date,
518
+ d = Chronic.parse(raw_date,
484
519
  :endian_precedence => :little)
485
520
  recurring = nil
486
-
521
+
487
522
  if annualar then
488
-
523
+
489
524
  recurring = 'yearly'
490
525
  if d < @now then
491
- d = Chronic.parse(raw_date,
492
- now: Time.local(@now.year + 1, 1, 1))
526
+ d = Chronic.parse(raw_date,
527
+ now: Time.local(@now.year + 1, 1, 1))
493
528
  end
494
529
  end
495
-
496
-
530
+
531
+
497
532
  puts [6, title, raw_date].inspect.debug if @debug
498
533
  { title: title, date: d, recurring: recurring }
499
534
  end
500
-
501
-
502
-
535
+
536
+
537
+
503
538
  # Tuesday 3rd October gas service at Barbara's house morning 9am-1pm
504
539
  #
505
540
  get '*' do
506
-
541
+
507
542
  s = params[:input]
508
-
509
- time1, time2, month, weekday, day, end_date, annualar = nil, nil, nil,
543
+
544
+ time1, time2, month, weekday, day, end_date, annualar = nil, nil, nil,
510
545
  nil, nil, nil, false
511
546
 
512
547
  s2 = s.sub(/#{times}/i) {|x| time1 = x; ''}
@@ -521,29 +556,29 @@ class EventNlp
521
556
  raw_date = [day, month].compact.join(' ')
522
557
  raw_date = weekday if raw_date.empty?
523
558
 
524
- d = Chronic.parse(raw_date + ' ' + time1.to_s,
559
+ d = Chronic.parse(raw_date + ' ' + time1.to_s,
525
560
  :endian_precedence => :little, now: @now)
526
-
561
+
527
562
  if time2 then
528
- end_date = Chronic.parse(raw_date + ' ' + time2.to_s,
563
+ end_date = Chronic.parse(raw_date + ' ' + time2.to_s,
529
564
  :endian_precedence => :little)
530
565
  end
531
-
566
+
532
567
  recurring = nil
533
-
568
+
534
569
  if annualar then
535
-
570
+
536
571
  recurring = 'yearly'
537
572
  if d < @now then
538
- d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
573
+ d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
539
574
  end
540
- end
541
-
575
+ end
576
+
542
577
  puts [10, title, raw_date, time1].inspect.debug if @debug
543
578
  { title: title, date: d, end_date: end_date, recurring: recurring }
544
- end
545
-
546
-
579
+ end
580
+
581
+
547
582
  end
548
-
583
+
549
584
  end
data.tar.gz.sig CHANGED
@@ -1 +1,2 @@
1
- .��)�?�ª܋� �5� ֌a���'�M
1
+ ot�+�a����B����g��!b��C��xD��R�ŀ���
2
+ ,Twq�-m�T�%GZ�.z�0<��f��Eϊ����ԫ�de��׈���y޶�i ur��@�~6�4��p�ӄ�O>j���UWA��.�^J,�F���|�9�HG�������#���T��3*]�r~d;2�Yk�,��=�,������L�v:(�S/�ܢ��n�ا+-�O%H�Wj���bf7�=�07v�H˸X��~�v*�pPw�<Mt���움�u�"&6�6+�p]=�A��.�T�E���~�Gy\�N�i�x�иWT�!Lʠ�����k� ��b���qo�P{eZ5�B��a��G��lN
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.5.3
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,48 +10,53 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDXjCCAkagAwIBAgIBATANBgkqhkiG9w0BAQUFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2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bW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEACwZ89nT9aFdxhWGboWw+R5rAnTRqDQS2U1/n7Vs0
29
+ uAMg5MVU/jIEFCnynXZMmJwzN3r972rkjxj9mn6DGnVu1YI1IAohMwls5BVPm4/V
30
+ HgOsV5YFOzfJpThCqVzo3HwkqZWoO7LEgIIHJ/3UYnCfWM6uHmDuyOTLnCHL+lVD
31
+ 1pi26mG34ViOfEQzgW6HwswixuUQ4LI2eYtzyKIS3qAYEVm7UwujdbKghEycFKdF
32
+ sBJVdzARYZGMbrKm8dWeBWrMhW+Fdy8HlN0D4XMYmCIYghZ5XiOICaTlv4rYOkr8
33
+ sThE7E1FNUonatzkBVmSDlJZ6K0nBZLy3RKC48BP8SnSM/LtQe9atiiJBPOAOck3
34
+ yjnIKndZd6EKQ2X55kjrO1J+/2tqfMOUjH8/pJLmeeR8xV5+oAz65qpFx8FZOFPC
35
+ w8lJ+I6Lqqr5GpsweOnEHW4w200sMRD40u8qmGHrqirihL2KrwTD6A9UObvA5AxZ
36
+ 4Z4EPvKg+3jsK9Gv3GGSLdrD
32
37
  -----END CERTIFICATE-----
33
- date: 2019-03-18 00:00:00.000000000 Z
38
+ date: 2022-04-01 00:00:00.000000000 Z
34
39
  dependencies:
35
40
  - !ruby/object:Gem::Dependency
36
41
  name: chronic_cron
37
42
  requirement: !ruby/object:Gem::Requirement
38
43
  requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: 0.5.0
42
44
  - - "~>"
43
45
  - !ruby/object:Gem::Version
44
- version: '0.5'
46
+ version: '0.7'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.7.1
45
50
  type: :runtime
46
51
  prerelease: false
47
52
  version_requirements: !ruby/object:Gem::Requirement
48
53
  requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: 0.5.0
52
54
  - - "~>"
53
55
  - !ruby/object:Gem::Version
54
- version: '0.5'
56
+ version: '0.7'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.7.1
55
60
  - !ruby/object:Gem::Dependency
56
61
  name: app-routes
57
62
  requirement: !ruby/object:Gem::Requirement
@@ -73,7 +78,7 @@ dependencies:
73
78
  - !ruby/object:Gem::Version
74
79
  version: 0.1.19
75
80
  description:
76
- email: james@jamesrobertson.eu
81
+ email: digital.robertson@gmail.com
77
82
  executables: []
78
83
  extensions: []
79
84
  extra_rdoc_files: []
@@ -98,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
103
  - !ruby/object:Gem::Version
99
104
  version: '0'
100
105
  requirements: []
101
- rubygems_version: 3.0.1
106
+ rubygems_version: 3.2.22
102
107
  signing_key:
103
108
  specification_version: 4
104
109
  summary: 'Parses a calendar event for date, time, and description e.g. hall 2 friday
metadata.gz.sig CHANGED
Binary file