Class: Nickel::NLPQuery

Inherits:
Object
  • Object
show all
Includes:
NLPQueryConstants
Defined in:
lib/nickel/nlp_query.rb

Constant Summary

Constants included from NLPQueryConstants

Nickel::NLPQueryConstants::DATE_DD, Nickel::NLPQueryConstants::DATE_DD_NB, Nickel::NLPQueryConstants::DATE_DD_NB_ON_SUFFIX, Nickel::NLPQueryConstants::DATE_DD_WITHOUT_SUFFIX, Nickel::NLPQueryConstants::DATE_DD_WITHOUT_SUFFIX_NB, Nickel::NLPQueryConstants::DATE_DD_WITH_SUFFIX, Nickel::NLPQueryConstants::DATE_DD_WITH_SUFFIX_NB, Nickel::NLPQueryConstants::DATE_DD_WITH_SUFFIX_NB_ON_SUFFIX, Nickel::NLPQueryConstants::DATE_MM_SLASH_DD, Nickel::NLPQueryConstants::DAY_OF_WEEK, Nickel::NLPQueryConstants::DAY_OF_WEEK_NB, Nickel::NLPQueryConstants::MONTH_OF_YEAR, Nickel::NLPQueryConstants::MONTH_OF_YEAR_NB, Nickel::NLPQueryConstants::TIME, Nickel::NLPQueryConstants::TIME_12HR, Nickel::NLPQueryConstants::TIME_24HR, Nickel::NLPQueryConstants::WEEK_OF_MONTH, Nickel::NLPQueryConstants::YEAR

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_str) ⇒ NLPQuery

Returns a new instance of NLPQuery.



9
10
11
# File 'lib/nickel/nlp_query.rb', line 9

def initialize(query_str)
  @query_str = query_str.dup
end

Instance Attribute Details

#after_formattingObject (readonly)

Returns the value of attribute after_formatting.



13
14
15
# File 'lib/nickel/nlp_query.rb', line 13

def after_formatting
  @after_formatting
end

#changed_inObject (readonly)

Returns the value of attribute changed_in.



13
14
15
# File 'lib/nickel/nlp_query.rb', line 13

def changed_in
  @changed_in
end

Instance Method Details

#insert_repeats_before_words_indicating_recurrence_lameObject



392
393
394
395
396
397
398
399
400
# File 'lib/nickel/nlp_query.rb', line 392

def insert_repeats_before_words_indicating_recurrence_lame
  comps = query_str.split
  (daily_index = comps.index('daily')) && comps[daily_index - 1] != 'repeats' && comps[daily_index] = 'repeats daily'
  (weekly_index = comps.index('weekly')) && comps[weekly_index - 1] != 'repeats' && comps[weekly_index] = 'repeats weekly'
  (monthly_index = comps.index('monthly')) && comps[monthly_index - 1] != 'repeats' && comps[monthly_index] = 'repeats monthly'
  if (rejoin = comps.join(' ')) != query_str
    nsub!(/.+/, rejoin)
  end
end

#insert_space_at_end_of_string_lameObject



402
403
404
405
# File 'lib/nickel/nlp_query.rb', line 402

def insert_space_at_end_of_string_lame
  #      nsub!(/(.+)/,'\1 ')  # I don't really want to be notified about this
  query_str.gsub!(/(.+)/, '\1 ')
end

#nsub!(*args) ⇒ Object

Usage: self.nsub!(/foo/, 'bar')

nsub! is like gsub! except it logs the calling method in @changed_in. There is another difference: When using blocks, matched strings are available as block params, e.g.: # nsub!(/(match1)(match2)/) {|m1,m2|}

I wrote this because I was having problems overriding gsub and passing a block from the new gsub to super.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/nickel/nlp_query.rb', line 48

def nsub!(*args)
  if m = query_str.match(args[0])    # m will now hold the FIRST set of backreferenced matches
    # there is at least one match
    @changed_in ||= []
    @changed_in << caller[1][/(\w+)\W*$/, 1]
    if block_given?
      # query_str.gsub!(args[0]) {yield(*m.to_a[1..-1])}    # There is a bug here: If gsub matches more than once,
                                                  # then the first set of referenced matches will be passed to the block
      ret_str = m.pre_match + m[0].sub(args[0]) { yield(*m.to_a[1..-1]) }   # this will take care of the first set of matches
      while (m_old = m.dup) && (m = m.post_match.match(args[0]))
        ret_str << m.pre_match + m[0].sub(args[0]) { yield(*m.to_a[1..-1]) }
      end
      ret_str << m_old.post_match
      query_str.sub!(/.*/, ret_str)
    else
      query_str.gsub!(args[0], args[1])
    end
  end
end

#query_formattingObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/nickel/nlp_query.rb', line 22

def query_formatting
  query_str.gsub!(/\n/, '')
  query_str.downcase!
  remove_unused_punctuation
  replace_backslashes
  run_spell_check
  remove_unnecessary_words
  standardize_days
  standardize_months
  standardize_numbers
  standardize_am_pm
  replace_hyphens
  insert_repeats_before_words_indicating_recurrence_lame
  insert_space_at_end_of_string_lame
  @after_formatting = query_str.dup    # save current state
end

#query_pre_processingObject



68
69
70
# File 'lib/nickel/nlp_query.rb', line 68

def query_pre_processing
  standardize_input
end

#remove_unnecessary_wordsObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/nickel/nlp_query.rb', line 108

def remove_unnecessary_words
  nsub!(/coming/, '')
  nsub!(/o'?clock/, '')
  nsub!(/\btom\b/, 'tomorrow')
  nsub!(/\s*in\s+(the\s+)?(morning|am)/, ' am')
  nsub!(/\s*in\s+(the\s+)?(afternoon|pm|evenn?ing)/, ' pm')
  nsub!(/\s*at\s+night/, 'pm')
  nsub!(/(after\s*)?noon(ish)?/, '12:00pm')
  nsub!(/\bmi(dn|nd)ight\b/, '12:00am')
  nsub!(/final/, 'last')
  nsub!(/recur(s|r?ing)?/, 'repeats')
  nsub!(/\beach\b/, 'every')
  nsub!(/running\s+(until|through)/, 'through')
  nsub!(/runn?(s|ing)|go(ing|e?s)/, 'for')
  nsub!(/next\s+occ?urr?[ae]nce(\s+is)?/, 'start')
  nsub!(/next\s+date(\s+it)?(\s+occ?urr?s)?(\s+is)?/, 'start')
  nsub!(/forever/, 'repeats daily')
  nsub!(/\bany(?:\s*)day\b/, 'every day')
  nsub!(/^anytime$/, 'every day')  # user entered anytime by itself, not 'dayname anytime', caught next
  nsub!(/any(\s)?time|whenever/, 'all day')
end

#remove_unused_punctuationObject



72
73
74
75
76
77
# File 'lib/nickel/nlp_query.rb', line 72

def remove_unused_punctuation
  nsub!(/,/, ' ')
  nsub!(/\./, '')
  nsub!(/;/, '')
  nsub!(/['`]/, '')
end

#replace_backslashesObject



79
80
81
# File 'lib/nickel/nlp_query.rb', line 79

def replace_backslashes
  nsub!(/\\/, '/')
end

#replace_hyphensObject



388
389
390
# File 'lib/nickel/nlp_query.rb', line 388

def replace_hyphens
  nsub!(/--?/, ' through ')
end

#run_spell_checkObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/nickel/nlp_query.rb', line 83

def run_spell_check
  nsub!(/tomm?orr?ow|romorrow/, 'tomorrow')
  nsub!(/weeknd/, 'weekend')
  nsub!(/weekends/, 'every sat sun')
  nsub!(/everyother/, 'every other')
  nsub!(/weak/, 'week')
  nsub!(/everyweek/, 'every week')
  nsub!(/everymonth/, 'every month')
  nsub!(/c?h[oa]nn?[aui][ck][ck]?[ua]h?/, 'hannukkah')
  nsub!(/frist/, '1st')
  nsub!(/eveyr|evrey/, 'every')
  nsub!(/fridya|friady|fridy/, 'friday')
  nsub!(/thurdsday/, 'thursday')
  nsub!(/x-?mas/, 'christmas')
  nsub!(/st\s+(patrick|patty|pat)s?(\s+day)?/, 'st patricks day')
  nsub!(/frouth/, 'fourth')
  nsub!(/\btill\b/, 'through')
  nsub!(/\bthru\b|\bthrouh\b|\bthough\b|\bthrew\b|\bthrow\b|\bthroug\b|\bthuogh\b/, 'through')
  nsub!(/weekdays|every\s+weekday/, 'every monday through friday')
  nsub!(/\bevery?day\b/, 'every day')
  nsub!(/eigth/, 'eighth')
  nsub!(/bi[-\s]monthly/, 'bimonthly')
  nsub!(/tri[-\s]monthly/, 'trimonthly')
end

#standardizeObject



15
16
17
18
19
20
# File 'lib/nickel/nlp_query.rb', line 15

def standardize
  @query = query_str.dup # needed for case correcting after extract_message has been called
  query_formatting  # easy text manipulation, no regex involved here
  query_pre_processing  # puts query in the form that construct_finder understands, lots of manipulation here
  query_str.dup
end

#standardize_am_pmObject



381
382
383
384
385
386
# File 'lib/nickel/nlp_query.rb', line 381

def standardize_am_pm
  nsub!(/([0-9])(?:\s*)a\b/, '\1am')  # allows 5a as 5am
  nsub!(/([0-9])(?:\s*)p\b/, '\1pm')  # allows 5p as 5pm
  nsub!(/\s+am\b/, 'am')  # removes any spaces before am, shouldn't I check for preceeding digits?
  nsub!(/\s+pm\b/, 'pm')  # removes any spaces before pm, shouldn't I check for preceeding digits?
end

#standardize_daysObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/nickel/nlp_query.rb', line 130

def standardize_days
  nsub!(/mondays/, 'every mon')
  nsub!(/monday/, 'mon')
  nsub!(/tuesdays/, 'every tue')
  nsub!(/tuesadys/, 'every tue')
  nsub!(/tuesday/, 'tue')
  nsub!(/tuesady/, 'tue')
  nsub!(/wednesdays/, 'every wed')
  nsub!(/wednesday/, 'wed')
  nsub!(/thursdays/, 'every thu')
  nsub!(/thurdsays/, 'every thu')
  nsub!(/thursadys/, 'every thu')
  nsub!(/thursday/, 'thu')
  nsub!(/thurdsay/, 'thu')
  nsub!(/thursady/, 'thu')
  nsub!(/\bthurd?\b/, 'thu')
  nsub!(/\bthurs?d?\b/, 'thu')
  nsub!(/fridays/, 'every fri')
  nsub!(/firdays/, 'every fri')
  nsub!(/friday/, 'fri')
  nsub!(/firday/, 'fri')
  nsub!(/saturdays/, 'every sat')
  nsub!(/saturday/, 'sat')
  nsub!(/sundays/, 'every sun')
  nsub!(/sunday/, 'sun')
end

#standardize_monthsObject



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/nickel/nlp_query.rb', line 157

def standardize_months
  nsub!(/january/, 'jan')
  nsub!(/february/, 'feb')
  nsub!(/febr/, 'feb')
  nsub!(/march/, 'mar')
  nsub!(/april/, 'apr')
  nsub!(/may/, 'may')
  nsub!(/june/, 'jun')
  nsub!(/july/, 'jul')
  nsub!(/august/, 'aug')
  nsub!(/september/, 'sep')
  nsub!(/sept/, 'sep')
  nsub!(/october/, 'oct')
  nsub!(/november/, 'nov')
  nsub!(/novermber/, 'nov')
  nsub!(/novem/, 'nov')
  nsub!(/decemb?e?r?/, 'dec')
end

#standardize_numbersObject



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/nickel/nlp_query.rb', line 176

def standardize_numbers
  nsub!(/\bone\s*-?\s*hundred\b/, '100')
  nsub!(/\bone\s*-?\s*hundredth\b/, '100th')
  nsub!(/\bninety\s*-?\s*nine\b/, '99')
  nsub!(/\bninety\s*-?\s*ninth\b/, '99th')
  nsub!(/\bninety\s*-?\s*eight\b/, '98')
  nsub!(/\bninety\s*-?\s*eighth\b/, '98th')
  nsub!(/\bninety\s*-?\s*seven\b/, '97')
  nsub!(/\bninety\s*-?\s*seventh\b/, '97th')
  nsub!(/\bninety\s*-?\s*six\b/, '96')
  nsub!(/\bninety\s*-?\s*sixth\b/, '96th')
  nsub!(/\bninety\s*-?\s*five\b/, '95')
  nsub!(/\bninety\s*-?\s*fifth\b/, '95th')
  nsub!(/\bninety\s*-?\s*four\b/, '94')
  nsub!(/\bninety\s*-?\s*fourth\b/, '94th')
  nsub!(/\bninety\s*-?\s*three\b/, '93')
  nsub!(/\bninety\s*-?\s*third\b/, '93rd')
  nsub!(/\bninety\s*-?\s*two\b/, '92')
  nsub!(/\bninety\s*-?\s*second\b/, '92nd')
  nsub!(/\bninety\s*-?\s*one\b/, '91')
  nsub!(/\bninety\s*-?\s*first\b/, '91st')
  nsub!(/\bninety\b/, '90')
  nsub!(/\bninetieth\b/, '90th')
  nsub!(/\beighty\s*-?\s*nine\b/, '89')
  nsub!(/\beighty\s*-?\s*ninth\b/, '89th')
  nsub!(/\beighty\s*-?\s*eight\b/, '88')
  nsub!(/\beighty\s*-?\s*eighth\b/, '88th')
  nsub!(/\beighty\s*-?\s*seven\b/, '87')
  nsub!(/\beighty\s*-?\s*seventh\b/, '87th')
  nsub!(/\beighty\s*-?\s*six\b/, '86')
  nsub!(/\beighty\s*-?\s*sixth\b/, '86th')
  nsub!(/\beighty\s*-?\s*five\b/, '85')
  nsub!(/\beighty\s*-?\s*fifth\b/, '85th')
  nsub!(/\beighty\s*-?\s*four\b/, '84')
  nsub!(/\beighty\s*-?\s*fourth\b/, '84th')
  nsub!(/\beighty\s*-?\s*three\b/, '83')
  nsub!(/\beighty\s*-?\s*third\b/, '83rd')
  nsub!(/\beighty\s*-?\s*two\b/, '82')
  nsub!(/\beighty\s*-?\s*second\b/, '82nd')
  nsub!(/\beighty\s*-?\s*one\b/, '81')
  nsub!(/\beighty\s*-?\s*first\b/, '81st')
  nsub!(/\beighty\b/, '80')
  nsub!(/\beightieth\b/, '80th')
  nsub!(/\bseventy\s*-?\s*nine\b/, '79')
  nsub!(/\bseventy\s*-?\s*ninth\b/, '79th')
  nsub!(/\bseventy\s*-?\s*eight\b/, '78')
  nsub!(/\bseventy\s*-?\s*eighth\b/, '78th')
  nsub!(/\bseventy\s*-?\s*seven\b/, '77')
  nsub!(/\bseventy\s*-?\s*seventh\b/, '77th')
  nsub!(/\bseventy\s*-?\s*six\b/, '76')
  nsub!(/\bseventy\s*-?\s*sixth\b/, '76th')
  nsub!(/\bseventy\s*-?\s*five\b/, '75')
  nsub!(/\bseventy\s*-?\s*fifth\b/, '75th')
  nsub!(/\bseventy\s*-?\s*four\b/, '74')
  nsub!(/\bseventy\s*-?\s*fourth\b/, '74th')
  nsub!(/\bseventy\s*-?\s*three\b/, '73')
  nsub!(/\bseventy\s*-?\s*third\b/, '73rd')
  nsub!(/\bseventy\s*-?\s*two\b/, '72')
  nsub!(/\bseventy\s*-?\s*second\b/, '72nd')
  nsub!(/\bseventy\s*-?\s*one\b/, '71')
  nsub!(/\bseventy\s*-?\s*first\b/, '71st')
  nsub!(/\bseventy\b/, '70')
  nsub!(/\bseventieth\b/, '70th')
  nsub!(/\bsixty\s*-?\s*nine\b/, '69')
  nsub!(/\bsixty\s*-?\s*ninth\b/, '69th')
  nsub!(/\bsixty\s*-?\s*eight\b/, '68')
  nsub!(/\bsixty\s*-?\s*eighth\b/, '68th')
  nsub!(/\bsixty\s*-?\s*seven\b/, '67')
  nsub!(/\bsixty\s*-?\s*seventh\b/, '67th')
  nsub!(/\bsixty\s*-?\s*six\b/, '66')
  nsub!(/\bsixty\s*-?\s*sixth\b/, '66th')
  nsub!(/\bsixty\s*-?\s*five\b/, '65')
  nsub!(/\bsixty\s*-?\s*fifth\b/, '65th')
  nsub!(/\bsixty\s*-?\s*four\b/, '64')
  nsub!(/\bsixty\s*-?\s*fourth\b/, '64th')
  nsub!(/\bsixty\s*-?\s*three\b/, '63')
  nsub!(/\bsixty\s*-?\s*third\b/, '63rd')
  nsub!(/\bsixty\s*-?\s*two\b/, '62')
  nsub!(/\bsixty\s*-?\s*second\b/, '62nd')
  nsub!(/\bsixty\s*-?\s*one\b/, '61')
  nsub!(/\bsixty\s*-?\s*first\b/, '61st')
  nsub!(/\bsixty\b/, '60')
  nsub!(/\bsixtieth\b/, '60th')
  nsub!(/\bfifty\s*-?\s*nine\b/, '59')
  nsub!(/\bfifty\s*-?\s*ninth\b/, '59th')
  nsub!(/\bfifty\s*-?\s*eight\b/, '58')
  nsub!(/\bfifty\s*-?\s*eighth\b/, '58th')
  nsub!(/\bfifty\s*-?\s*seven\b/, '57')
  nsub!(/\bfifty\s*-?\s*seventh\b/, '57th')
  nsub!(/\bfifty\s*-?\s*six\b/, '56')
  nsub!(/\bfifty\s*-?\s*sixth\b/, '56th')
  nsub!(/\bfifty\s*-?\s*five\b/, '55')
  nsub!(/\bfifty\s*-?\s*fifth\b/, '55th')
  nsub!(/\bfifty\s*-?\s*four\b/, '54')
  nsub!(/\bfifty\s*-?\s*fourth\b/, '54th')
  nsub!(/\bfifty\s*-?\s*three\b/, '53')
  nsub!(/\bfifty\s*-?\s*third\b/, '53rd')
  nsub!(/\bfifty\s*-?\s*two\b/, '52')
  nsub!(/\bfifty\s*-?\s*second\b/, '52nd')
  nsub!(/\bfifty\s*-?\s*one\b/, '51')
  nsub!(/\bfifty\s*-?\s*first\b/, '51st')
  nsub!(/\bfifty\b/, '50')
  nsub!(/\bfiftieth\b/, '50th')
  nsub!(/\bfourty\s*-?\s*nine\b/, '49')
  nsub!(/\bfourty\s*-?\s*ninth\b/, '49th')
  nsub!(/\bfourty\s*-?\s*eight\b/, '48')
  nsub!(/\bfourty\s*-?\s*eighth\b/, '48th')
  nsub!(/\bfourty\s*-?\s*seven\b/, '47')
  nsub!(/\bfourty\s*-?\s*seventh\b/, '47th')
  nsub!(/\bfourty\s*-?\s*six\b/, '46')
  nsub!(/\bfourty\s*-?\s*sixth\b/, '46th')
  nsub!(/\bfourty\s*-?\s*five\b/, '45')
  nsub!(/\bfourty\s*-?\s*fifth\b/, '45th')
  nsub!(/\bfourty\s*-?\s*four\b/, '44')
  nsub!(/\bfourty\s*-?\s*fourth\b/, '44th')
  nsub!(/\bfourty\s*-?\s*three\b/, '43')
  nsub!(/\bfourty\s*-?\s*third\b/, '43rd')
  nsub!(/\bfourty\s*-?\s*two\b/, '42')
  nsub!(/\bfourty\s*-?\s*second\b/, '42nd')
  nsub!(/\bfourty\s*-?\s*one\b/, '41')
  nsub!(/\bfourty\s*-?\s*first\b/, '41st')
  nsub!(/\bfourty\b/, '40')
  nsub!(/\bfourtieth\b/, '40th')
  nsub!(/\bthirty\s*-?\s*nine\b/, '39')
  nsub!(/\bthirty\s*-?\s*ninth\b/, '39th')
  nsub!(/\bthirty\s*-?\s*eight\b/, '38')
  nsub!(/\bthirty\s*-?\s*eighth\b/, '38th')
  nsub!(/\bthirty\s*-?\s*seven\b/, '37')
  nsub!(/\bthirty\s*-?\s*seventh\b/, '37th')
  nsub!(/\bthirty\s*-?\s*six\b/, '36')
  nsub!(/\bthirty\s*-?\s*sixth\b/, '36th')
  nsub!(/\bthirty\s*-?\s*five\b/, '35')
  nsub!(/\bthirty\s*-?\s*fifth\b/, '35th')
  nsub!(/\bthirty\s*-?\s*four\b/, '34')
  nsub!(/\bthirty\s*-?\s*fourth\b/, '34th')
  nsub!(/\bthirty\s*-?\s*three\b/, '33')
  nsub!(/\bthirty\s*-?\s*third\b/, '33rd')
  nsub!(/\bthirty\s*-?\s*two\b/, '32')
  nsub!(/\bthirty\s*-?\s*second\b/, '32nd')
  nsub!(/\bthirty\s*-?\s*one\b/, '31')
  nsub!(/\bthirty\s*-?\s*first\b/, '31st')
  nsub!(/\bthirty\b/, '30')
  nsub!(/\bthirtieth\b/, '30th')
  nsub!(/\btwenty\s*-?\s*nine\b/, '29')
  nsub!(/\btwenty\s*-?\s*ninth\b/, '29th')
  nsub!(/\btwenty\s*-?\s*eight\b/, '28')
  nsub!(/\btwenty\s*-?\s*eighth\b/, '28th')
  nsub!(/\btwenty\s*-?\s*seven\b/, '27')
  nsub!(/\btwenty\s*-?\s*seventh\b/, '27th')
  nsub!(/\btwenty\s*-?\s*six\b/, '26')
  nsub!(/\btwenty\s*-?\s*sixth\b/, '26th')
  nsub!(/\btwenty\s*-?\s*five\b/, '25')
  nsub!(/\btwenty\s*-?\s*fifth\b/, '25th')
  nsub!(/\btwenty\s*-?\s*four\b/, '24')
  nsub!(/\btwenty\s*-?\s*fourth\b/, '24th')
  nsub!(/\btwenty\s*-?\s*three\b/, '23')
  nsub!(/\btwenty\s*-?\s*third\b/, '23rd')
  nsub!(/\btwenty\s*-?\s*two\b/, '22')
  nsub!(/\btwenty\s*-?\s*second\b/, '22nd')
  nsub!(/\btwenty\s*-?\s*one\b/, '21')
  nsub!(/\btwenty\s*-?\s*first\b/, '21st')
  nsub!(/\btwenty\b/, '20')
  nsub!(/\btwentieth\b/, '20th')
  nsub!(/\bnineteen\b/, '19')
  nsub!(/\bnineteenth\b/, '19th')
  nsub!(/\beighteen\b/, '18')
  nsub!(/\beighteenth\b/, '18th')
  nsub!(/\bseventeen\b/, '17')
  nsub!(/\bseventeenth\b/, '17th')
  nsub!(/\bsixteen\b/, '16')
  nsub!(/\bsixteenth\b/, '16th')
  nsub!(/\bfifteen\b/, '15')
  nsub!(/\bfifteenth\b/, '15th')
  nsub!(/\bfourteen\b/, '14')
  nsub!(/\bfourteenth\b/, '14th')
  nsub!(/\bthirteen/, '13')
  nsub!(/\bthirteenth/, '13th')
  nsub!(/\btwelve\b/, '12')
  nsub!(/\btwelfth\b/, '12th')
  nsub!(/\beleven\b/, '11')
  nsub!(/\beleventh\b/, '11th')
  nsub!(/\bten\b/, '10')
  nsub!(/\btenth\b/, '10th')
  nsub!(/\bnine\b/, '9')
  nsub!(/\bninth\b/, '9th')
  nsub!(/\beight\b/, '8')
  nsub!(/\beighth\b/, '8th')
  nsub!(/\bseven\b/, '7')
  nsub!(/\bseventh\b/, '7th')
  nsub!(/\bsix\b/, '6')
  nsub!(/\bsixth\b/, '6th')
  nsub!(/\bfive\b/, '5')
  nsub!(/\bfifth\b/, '5th')
  nsub!(/\bfour\b/, '4')
  nsub!(/\bfourth\b/, '4th')
  nsub!(/\bthree\b/, '3')
  nsub!(/\bthird\b/, '3rd')
  nsub!(/\btwo\b/, '2')
  nsub!(/\bsecond\b/, '2nd')
  nsub!(/\bone\b/, '1')
  nsub!(/\bfirst\b/, '1st')
  nsub!(/\bzero\b/, '0')
  nsub!(/\bzeroth\b/, '0th')
end

#to_sObject



407
408
409
# File 'lib/nickel/nlp_query.rb', line 407

def to_s
  query_str
end