event_nlp 0.2.16 → 0.2.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9765f56a2cdca51484e63883fe5b1999074570b8
4
- data.tar.gz: d9c5b776cdeaa3aa6ad915b4de05366073f16572
3
+ metadata.gz: a0b3289870f21858812ccdaf45ab5ec26736eee9
4
+ data.tar.gz: 51f33ba988ee15567cf8bf28dfcfcd0ea200012e
5
5
  SHA512:
6
- metadata.gz: eb3dbed493d2946b933fa16d2bd8a94698bc4744ff6b094d01c5801d5aed720f391cb4f9b1fc4eb44e9df0a226035e515638e787eaed83b0941b9d0265ff84fc
7
- data.tar.gz: 208d2d5aee1a109e1e2e546b29ccd10aa7ab931e307ec30720c366e16b204d013daf84951cadf833771ac5145eab3c6d0a0a70caf5a078fa3a543353d6ee326e
6
+ metadata.gz: 6834d3422ac16b5af9552dcea6be8543fa5572a20520fc2629d25fa5eac80f48d3b2fc1dd2da7d38a32c872ab7a122d996098964e629b5a74fcd325f3fef6c9e
7
+ data.tar.gz: fa1cdf7c2cca71723979d82efc8576e2cc22d01c9f4e2b9be106eff0f707e444d40aaa7a5f8004924173c4c71d2729a3216ee5548b9019157b1f6ecf6a224517
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/event_nlp.rb CHANGED
@@ -49,16 +49,13 @@ class EventNlp
49
49
 
50
50
  private
51
51
 
52
- def expressions(params)
53
-
54
-
55
-
52
+ def expressions(params)
56
53
 
57
54
  starting = /(?:\(?\s*starting (\d+\w{2} \w+\s*\w*)(?: until (.*))?\s*\))?/
58
55
  weekdays = Date::DAYNAMES.join('|').downcase
59
56
  months = (Date::MONTHNAMES[1..-1] + Date::ABBR_MONTHNAMES[1..-1])\
60
57
  .join('|').downcase
61
- times = /(?: *(?:at |@ |from )?(\d+(?::\d+)?[ap]m) *)/
58
+ times = /(?: *(?:at |@ |from )?(\d+(?::\d+)?(?:[ap]m|\b)) *)/
62
59
  times2 = /\d+(?::\d+)?[ap]m-\d+(?::\d+)?[ap]m|\d+(?::\d+)?-\d+(?::\d+)?/
63
60
  days = /\d+(?:st|nd|rd|th)/
64
61
  periods = /day|week|month/
@@ -214,15 +211,51 @@ class EventNlp
214
211
  { title: title, date: d }
215
212
 
216
213
  end
214
+
215
+ # some event Wednesday
216
+ # some event Wednesday 11am
217
217
 
218
+ relative_day = '|today|tomorrow|tonight'
219
+ get /^(.*)\s+(#{weekdays+relative_day})(?: \(([^\)]+)\)) (at \d{1,2}(?::\d{2})?(?:[ap]m)?)/i \
220
+ do |title, raw_date, date2, time2|
221
+ puts 'time2: ' + time2.inspect if @debug
222
+ puts 'date2: ' + date2 if @debug
223
+ puts 'raw_date: ' + raw_date if @debug
224
+
225
+ d = if date2 then
226
+ Chronic.parse(date2 + ' '+ time2.to_s)
227
+ else
228
+ Chronic.parse(raw_date + ' '+ time2)
229
+ end
230
+
231
+ puts [4, title, raw_date, date2, time2].inspect if @debug
232
+ {title: title, date: d }
233
+
234
+ end
235
+
218
236
 
219
237
  # hall 2 friday at 11am
220
- get /(.*)\s+(#{weekdays})\s+at\s+(.*)/i do |title, raw_day, time|
238
+ get /^(.*)\s+(#{weekdays})(?: \(([^\)]+)\))?(#{times})?/i do |title, raw_day, actual_date, time|
221
239
 
222
- d = Chronic.parse(raw_day + ' ' + time)
240
+ puts 'actual_date: ' + actual_date.inspect if @debug
241
+ puts 'raw_day: ' + raw_day.inspect if @debug
242
+ puts 'time: ' + time.inspect if @debug
223
243
 
224
- puts [1.7, title, raw_day].inspect if @debug
225
- { title: title, date: d }
244
+ input = params[:input].clone
245
+
246
+ if actual_date then
247
+ d = Chronic.parse(raw_day + ' ' + time.to_s)
248
+ else
249
+ d = Chronic.parse(raw_day + ' ' + time.to_s)
250
+ input.sub!(/#{weekdays}/i,%Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
251
+ end
252
+
253
+ puts 'foo' + d.inspect
254
+
255
+
256
+ puts [1.7, input, title, raw_day].inspect if @debug
257
+
258
+ {input: input, title: title, date: d }
226
259
 
227
260
  end
228
261
 
@@ -278,26 +311,12 @@ class EventNlp
278
311
  d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
279
312
  end
280
313
  end
281
-
282
-
314
+
283
315
  puts [3, title, raw_date, time].inspect if @debug
284
316
  { title: title, date: d, recurring: recurring }
285
317
  end
286
318
 
287
- # some event Wednesday
288
- # some event Wednesday 11am
289
-
290
- relative_day = '|today|tomorrow|tonight'
291
- get /^(.*)\s+((?:#{weekdays+relative_day})(?: \d{1,2}(?::\d{2})?[ap]m)?)/i \
292
- do |title, raw_date|
293
-
294
- d = Chronic.parse(raw_date)
295
-
296
- puts [4, title, raw_date].inspect if @debug
297
- {title: title, date: d }
298
-
299
- end
300
-
319
+
301
320
 
302
321
  # Some event (10 Woodhouse Lane) 30th Nov from 9:15-17:00
303
322
 
@@ -323,6 +342,7 @@ class EventNlp
323
342
  nil, nil, nil, false
324
343
 
325
344
  s2 = s.sub(/#{times}/i) {|x| time1 = x; ''}
345
+ puts 's2: ' + s2.inspect if @debug
326
346
  s3 = s2.sub(/-(?=\d)/,'').sub(/#{times}/i) {|x| time2 = x; ''}
327
347
  s4 = s3.sub(/ *#{weekdays} */i) {|x| weekday = x; ''}
328
348
  s5 = s4.sub(/ *#{months} */i) {|x| month = x; ''}
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.2.16
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file