event_nlp 0.2.7 → 0.2.8

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: 0b9b45e77e53d8fb10a418d7a49797ca09779286
4
- data.tar.gz: 64cc7e8b8aac9b1dad55cf0842b1b0058762bcc7
3
+ metadata.gz: e3cd4994fbaf38dc524a289a4d4bf77041d40770
4
+ data.tar.gz: 8ee5abd06c78d59c9c0a55162ade03d48483001a
5
5
  SHA512:
6
- metadata.gz: c25e6b6dd98e1dc4eba2255e21774cc4a91205e60decfac70d7232da1e4f39664b32d66fff8a687b82e61d3f301c97c42d70417e2cf2fde63f90c55393a060ef
7
- data.tar.gz: 542f480ab1ff23cf5c3642cfeb30a876e621ab72fe9797cd8dea2eadd143966f0df77cd559797a1e71d3eefb47991e82d25feefd63e9d9a27d0f6e436038ccba
6
+ metadata.gz: 93fcbafdc9a7667c642c7c093748f46b7fffb842e5442b3be6c4404f55faae8221f6eb6e6e9b63bed20b5e00fe72a2e90e65e29a0e12c2f8288ee799ead6f603
7
+ data.tar.gz: 62e4f05a211799d7e198909a6cb5ee8851b9d178ba1a42fdf79f5c0e420f60b4244d58699d5d4081982f4913e777d423ed0ceaaa75026fe7ac359932b62fe13f
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/event_nlp.rb CHANGED
@@ -59,13 +59,19 @@ class EventNlp
59
59
 
60
60
 
61
61
  starting = /(?:\(?\s*starting (\d+\w{2} \w+\s*\w*)(?: until (.*))?\s*\))?/
62
- weekday = Date::DAYNAMES.join('|').downcase
63
- months = (Date::MONTHNAMES[1..-1] + Date::ABBR_MONTHNAMES[1..-1])
64
- .join('|').downcase
65
- time = /(?: (?:at )?(\d+(?::\d+)?am) )?/
62
+ weekdays = Date::DAYNAMES.join('|').downcase
63
+ months = (Date::MONTHNAMES[1..-1] + Date::ABBR_MONTHNAMES[1..-1])\
64
+ .join('|').downcase
65
+ times = /(?: *(?:at )?(\d+(?::\d+)?[ap]m) *)/
66
+ days = /\d+(?:st|nd|rd|th)/
67
+
68
+ #weekdays = Date::DAYNAMES.join('|').downcase
69
+ #
70
+ #times = /(?: *at )?\d[ap]m/
71
+
66
72
 
67
73
 
68
- get /^(.*)\s+(every \d\w+ \w+#{time})\s*#{starting}/ do \
74
+ get /^(.*)\s+(every \d\w+ \w+#{times})\s*#{starting}/ do \
69
75
  |title, recurring, time, raw_date, end_date|
70
76
 
71
77
  input = params[:input].clone
@@ -125,10 +131,21 @@ class EventNlp
125
131
 
126
132
  exp = ChronicCron.new(recurring).to_expression
127
133
 
128
- d = CronFormat.new(exp).to_time
134
+ raw_start_date = recurring[/(?<=starting )[^\)]+/]
135
+
136
+
137
+ if raw_start_date then
138
+ start_date = Chronic.parse(raw_start_date, now: @now - 1)
139
+
140
+ cf = CronFormat.new(exp, start_date - 1)
141
+ #cf.next until cf.to_time >= start_date
142
+ else
143
+ cf = CronFormat.new(exp, @now)
144
+ end
145
+ d = cf.to_time
129
146
 
130
147
  puts [0.5, title, recurring, d].inspect if @debug
131
- {title: title, recurring: recurring, date: d }
148
+ {title: title.rstrip, recurring: recurring, date: d }
132
149
 
133
150
  end
134
151
 
@@ -143,7 +160,7 @@ class EventNlp
143
160
  end
144
161
 
145
162
  # hall 2 friday at 11am
146
- get /(.*)\s+(#{weekday})\s+at\s+(.*)/i do |title, raw_day, time|
163
+ get /(.*)\s+(#{weekdays})\s+at\s+(.*)/i do |title, raw_day, time|
147
164
 
148
165
  d = Chronic.parse(raw_day + ' ' + time)
149
166
 
@@ -165,7 +182,7 @@ class EventNlp
165
182
  end
166
183
 
167
184
  # friday hall 2 11am
168
- get /^(#{weekday})\s+(.*)\s+(\d+(?::\d{2})?[ap]m)$/i do |raw_day, title, time|
185
+ get /^(#{weekdays})\s+(.*)\s+(\d+(?::\d{2})?[ap]m)$/i do |raw_day, title, time|
169
186
 
170
187
  d = Chronic.parse(raw_day + ' ' + time)
171
188
 
@@ -176,7 +193,7 @@ class EventNlp
176
193
 
177
194
 
178
195
  # hall 2 at 11am
179
- get /(.*)\s+at\s+(.*)/i do |title, time|
196
+ get /(.*)\s+at\s+(#{times})/i do |title, time|
180
197
 
181
198
  d = Chronic.parse(time)
182
199
 
@@ -185,34 +202,10 @@ class EventNlp
185
202
 
186
203
  end
187
204
 
188
- # hall 2 friday at 11am
189
- # some important day 24th Mar
190
-
191
- with_date = "(.*)\\s+(\\d\+\s*(?:st|nd|rd|th)?\\s+(?:#{months}))"
192
- alt_pattern = '([^\d]+)\s+(\d+[^\*]+)(\*)?'
193
-
194
- get /#{with_date}|#{alt_pattern}\s*(\*)$/i do |title, raw_date, annualar|
195
-
196
- d = Chronic.parse(raw_date)
197
-
198
- recurring = nil
199
-
200
- if annualar then
201
-
202
- recurring = 'yearly'
203
- if d < @now then
204
- d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
205
- end
206
- end
207
-
208
- puts [2, title, raw_date].inspect if @debug
209
- { title: title, date: d, recurring: recurring }
210
- end
211
-
212
205
  # 27-Mar@1436 some important day
213
206
  # 25/07/2017 11pm some important day
214
207
  #
215
- get /(\d[^\s]+)\s*(\d+(?:\:\d+)?[ap]m)?\s+([^\*]+)(\*)?/ do |raw_date,
208
+ get /^(\d[^\s]+)\s*(\d+(?:\:\d+)?[ap]m)?\s+([^\*]+)(\*)?/ do |raw_date,
216
209
  time, title, annualar|
217
210
 
218
211
  d = Chronic.parse(raw_date + ' ' + time.to_s,
@@ -236,7 +229,7 @@ class EventNlp
236
229
  # some event Wednesday 11am
237
230
 
238
231
  relative_day = '|today|tomorrow|tonight'
239
- get /^(.*)\s+((?:#{weekday+relative_day})(?: \d{1,2}(?::\d{2})?[ap]m)?)/i \
232
+ get /^(.*)\s+((?:#{weekdays+relative_day})(?: \d{1,2}(?::\d{2})?[ap]m)?)/i \
240
233
  do |title, raw_date|
241
234
 
242
235
  d = Chronic.parse(raw_date)
@@ -246,12 +239,49 @@ class EventNlp
246
239
 
247
240
  end
248
241
 
249
- # e.g. 04-Aug@12:34
250
- get '*' do |s|
251
- puts 's: ' + s.inspect if @debug
252
- 'pattern unrecognised'
253
- end
254
-
242
+ # Tuesday 3rd October gas service at Barbara's house morning 9am-1pm
243
+
244
+ get '*' do
245
+
246
+ s = params[:input]
247
+
248
+ time1, time2, month, weekday, day, end_date, annualar = nil, nil, nil,
249
+ nil, nil, nil, false
250
+
251
+ s2 = s.sub(/#{times}/i) {|x| time1 = x; ''}
252
+ s3 = s2.sub(/-(?=\d)/,'').sub(/#{times}/i) {|x| time2 = x; ''}
253
+ s4 = s3.sub(/ *#{weekdays} */i) {|x| weekday = x; ''}
254
+ s5 = s4.sub(/ *#{months} */i) {|x| month = x; ''}
255
+ s6 = s5.sub(/ *#{days} */i) {|x| day = x; ''}
256
+ s7 = s6.sub(/\*$/) {|x| annualar = true; ''}
257
+ title = s6
258
+
259
+ raw_date = [day, month].compact.join(' ')
260
+ raw_date = weekday if raw_date.empty?
261
+
262
+ d = Chronic.parse(raw_date + ' ' + time1.to_s,
263
+ :endian_precedence => :little, now: @now)
264
+
265
+ if time2 then
266
+ end_date = Chronic.parse(raw_date + ' ' + time2.to_s,
267
+ :endian_precedence => :little)
268
+ end
269
+
270
+ recurring = nil
271
+
272
+ if annualar then
273
+
274
+ recurring = 'yearly'
275
+ if d < @now then
276
+ d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
277
+ end
278
+ end
279
+
280
+ puts [5, title, raw_date, time1].inspect if @debug
281
+ { title: title, date: d, end_date: end_date, recurring: recurring }
282
+ end
283
+
284
+
255
285
  end
256
286
 
257
287
  end
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.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
@@ -1,3 +1,2 @@
1
- iݗ�_"
2
- ���*r'nأ���ɧ���� 
3
- �*d�s�FxOµ��\�c҆z$���Zs�ceX�Z���l�+сN��l*ѷDܚDz�����f�Z�+�b᡾xve���S�:�c�
1
+ ��ji���+oK��P���fJr۳D$�&1��O�7+ڧ��@'� B�p0F���@��� <�4��K M���TYW��)�y=H�}8��v� =<���ꉨgoH4Ag)����D5�y�k�HMy�6<��h �%;{*/�b5�����9h��WL"�p}c.��
2
+ ��GE��㴂�хn"