day 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/LICENSE +20 -0
- data/README.md +86 -0
- data/data/month_vocabulary.yml +40 -0
- data/data/short_week_days.yml +23 -0
- data/data/simple_numerics.yml +37 -0
- data/data/week_days.yml +23 -0
- data/lib/day.rb +252 -0
- data/lib/levenshtein.rb +83 -0
- metadata +76 -0
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Sergey Gerasimov (http://grsmv.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
Gem for date parsing (in the scale of the day, hours is not very important in my projects now). It support Russian and Ukrainian (in future) languages.
|
2
|
+
|
3
|
+
Table of possible phrase types to parse:
|
4
|
+
|
5
|
+
----------------------------------------------------------------------------------
|
6
|
+
по-русски | по-украински | is implemented?
|
7
|
+
----------------------------------------------------------------------------------
|
8
|
+
вчера | | +
|
9
|
+
сегодня | | +
|
10
|
+
завтра | | +
|
11
|
+
два дня назад | | +
|
12
|
+
три дня назад | | +
|
13
|
+
(...) дней назад | | +
|
14
|
+
2 дня назад | | +
|
15
|
+
3 дня назад | | +
|
16
|
+
5 дней назад | | +
|
17
|
+
через два дня | | +
|
18
|
+
через три дня | | +
|
19
|
+
через (...) дней | | +
|
20
|
+
через 2 дня | | +
|
21
|
+
через 3 дня | | +
|
22
|
+
через 25 дней | | +
|
23
|
+
в понедельник | | +
|
24
|
+
во вторник и т.д. | | +
|
25
|
+
в этот понедельник | | +
|
26
|
+
в этот вторник и т.д. | | +
|
27
|
+
пн (вт, ср, чт, пт, чб, вс) | | +
|
28
|
+
в пн (во вт, в ср ...) | |
|
29
|
+
в следующий понедельник | | +
|
30
|
+
в следующий вторник и т.д. | | +
|
31
|
+
в след пн (в след.? вт) | |
|
32
|
+
в прошлый понедельник | | +
|
33
|
+
в прошлый вторник и т.д. | | +
|
34
|
+
в прошлый пн (вт, ср) | |
|
35
|
+
----------------------------------------------------------------------------------
|
36
|
+
через неделю | | +
|
37
|
+
через две недели и т.д. | | +
|
38
|
+
через 2 недели | | +
|
39
|
+
неделю назад | | +
|
40
|
+
две недели назад | | +
|
41
|
+
2 недели назад | | +
|
42
|
+
----------------------------------------------------------------------------------
|
43
|
+
через месяц | | +
|
44
|
+
через два месяца | | +
|
45
|
+
через 2 месяца | | +
|
46
|
+
через мес | |
|
47
|
+
через 2 мес | |
|
48
|
+
месяц назад | | +
|
49
|
+
два месяца назад | | +
|
50
|
+
пять месяцев назад | | +
|
51
|
+
2 месяца назад | | +
|
52
|
+
5 месяцев назад | | +
|
53
|
+
----------------------------------------------------------------------------------
|
54
|
+
2 октября | | +
|
55
|
+
2 октября 2011 | | +
|
56
|
+
2 окт | | +
|
57
|
+
2 окт 2011 | | +
|
58
|
+
17 июн, 2011 | | +
|
59
|
+
----------------------------------------------------------------------------------
|
60
|
+
Date.parse (?):
|
61
|
+
----------------------------------------------------------------------------------
|
62
|
+
1.05.2011 | | +
|
63
|
+
01.05.2011 | | +
|
64
|
+
1-5-2011 | | +
|
65
|
+
2011-5-1 | | +
|
66
|
+
2011.5.1 | | +
|
67
|
+
2011.1 | | error raised
|
68
|
+
|
69
|
+
TODO:
|
70
|
+
-----
|
71
|
+
|
72
|
+
1. Move Unicode gem (unicode-0.4.0) in dependencies
|
73
|
+
2. Write tests for sure in equality of numerical and literal days values and for sure in right date recognition
|
74
|
+
3. Write YARD documentation
|
75
|
+
4. Pack as gem
|
76
|
+
5. Type error recognition ('черз' instead 'через') and fixing. (?!: vocabulary + Levenshtein distance).
|
77
|
+
(and look at the http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance)
|
78
|
+
6. Set start date + Timezone
|
79
|
+
|
80
|
+
|
81
|
+
USAGE:
|
82
|
+
-----
|
83
|
+
puts Day::Ru 'через 2 месяца' #=> Wed Sep 14 00:00:00 +0300 2011
|
84
|
+
puts Day::Ru 'завтра' #=> Wed Jul 15 00:00:00 +0300 2011
|
85
|
+
|
86
|
+
# (For other examples see table at the top)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
? !binary "0L7QutGC\n"
|
3
|
+
: oct
|
4
|
+
|
5
|
+
? !binary "0LjRjtC9\n"
|
6
|
+
: jun
|
7
|
+
|
8
|
+
? !binary "0LTQtdC6\n"
|
9
|
+
: dec
|
10
|
+
|
11
|
+
? !binary "0LDQv9GA\n"
|
12
|
+
: apr
|
13
|
+
|
14
|
+
? !binary "0Y/QvdCy\n"
|
15
|
+
: jan
|
16
|
+
|
17
|
+
? !binary "0LzQsNGP\n"
|
18
|
+
: may
|
19
|
+
|
20
|
+
? !binary "0LzQsNC5\n"
|
21
|
+
: may
|
22
|
+
|
23
|
+
? !binary "0YHQtdC9\n"
|
24
|
+
: sep
|
25
|
+
|
26
|
+
? !binary "0YTQtdCy\n"
|
27
|
+
: feb
|
28
|
+
|
29
|
+
? !binary "0LDQstCz\n"
|
30
|
+
: aug
|
31
|
+
|
32
|
+
? !binary "0L3QvtGP0LE=\n"
|
33
|
+
: nov
|
34
|
+
|
35
|
+
? !binary "0LjRjtC7\n"
|
36
|
+
: jul
|
37
|
+
|
38
|
+
? !binary "0LzQsNGA\n"
|
39
|
+
: march
|
40
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
? !binary "0LTQtdCy0Y/RgtGM\n"
|
3
|
+
: 9
|
4
|
+
|
5
|
+
? !binary "0L/Rj9GC0Yw=\n"
|
6
|
+
: 5
|
7
|
+
|
8
|
+
? !binary "0YjQtdGB0YLRjA==\n"
|
9
|
+
: 6
|
10
|
+
|
11
|
+
? !binary "0LTQstC1\n"
|
12
|
+
: 2
|
13
|
+
|
14
|
+
? !binary "0YfQtdGC0YvRgNC1\n"
|
15
|
+
: 4
|
16
|
+
|
17
|
+
? !binary "0L7QtNC90YM=\n"
|
18
|
+
: 1
|
19
|
+
|
20
|
+
? !binary "0LTQtdGB0Y/RgtGM\n"
|
21
|
+
: 10
|
22
|
+
|
23
|
+
? !binary "0LLQvtGB0LXQvNGM\n"
|
24
|
+
: 8
|
25
|
+
|
26
|
+
? !binary "0L7QtNC40L0=\n"
|
27
|
+
: 1
|
28
|
+
|
29
|
+
? !binary "0YHQtdC80Yw=\n"
|
30
|
+
: 7
|
31
|
+
|
32
|
+
? !binary "0YLRgNC4\n"
|
33
|
+
: 3
|
34
|
+
|
35
|
+
? !binary "0LTQstCw\n"
|
36
|
+
: 2
|
37
|
+
|
data/data/week_days.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
- nil
|
3
|
+
- !binary |
|
4
|
+
0L/QvtC90LXQtNC10LvRjNC90LjQug==
|
5
|
+
|
6
|
+
- !binary |
|
7
|
+
0LLRgtC+0YDQvdC40Lo=
|
8
|
+
|
9
|
+
- !binary |
|
10
|
+
0YHRgNC10LTRgw==
|
11
|
+
|
12
|
+
- !binary |
|
13
|
+
0YfQtdGA0LLQtdGA0LM=
|
14
|
+
|
15
|
+
- !binary |
|
16
|
+
0L/Rj9GC0L3QuNGG0YM=
|
17
|
+
|
18
|
+
- !binary |
|
19
|
+
0YHRg9Cx0LHQvtGC0YM=
|
20
|
+
|
21
|
+
- !binary |
|
22
|
+
0LLQvtGB0LrRgNC10YHQtdC90YzQtQ==
|
23
|
+
|
data/lib/day.rb
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
$KCODE = 'u'
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'iconv'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
class Numeric
|
8
|
+
def days
|
9
|
+
self * 60 * 60 * 24
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Day
|
14
|
+
|
15
|
+
class Ru
|
16
|
+
|
17
|
+
# getting class variables from 'data' folder contents
|
18
|
+
Dir.chdir(File.join(File.dirname(__FILE__), '..', 'data'))
|
19
|
+
Dir.glob('*.yml') do |yml|
|
20
|
+
class_variable_set "@@#{yml.gsub('.yml', '')}".to_sym, YAML::load(File.read(yml))
|
21
|
+
end
|
22
|
+
|
23
|
+
# TODO: - string to utf8 if Ruby version > 1.9
|
24
|
+
# - convert to lowercase with Unicode gem
|
25
|
+
# - set date
|
26
|
+
def initialize string
|
27
|
+
@string = string.strip
|
28
|
+
@now = Time.now
|
29
|
+
@week_start = @now - @now.wday.days
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_accessor :date
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
|
37
|
+
def yesterday_today_tomorrow
|
38
|
+
@date = case @string
|
39
|
+
when /^(позавчера)$/ then @now - 2.days
|
40
|
+
when /^(вчера)$/ then @now - 1.days
|
41
|
+
when /^(завтра)$/ then @now + 1.days
|
42
|
+
when /^(послезавтра)$/ then @now + 2.days
|
43
|
+
else @now
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def future_days days_num
|
49
|
+
@date = @now + days_num.to_i.days
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def previous_days days_num
|
54
|
+
@date = @now - days_num.to_i.days
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def in_week_day day
|
59
|
+
@date = @week_start + @@week_days.index(day).days
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def in_week_day_short_notation day
|
64
|
+
@date = @week_start + @@short_week_days.index(day).days
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def in_past_week_day day
|
69
|
+
@date = in_week_day(day) - 7.days
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def in_next_week_day day
|
74
|
+
@date = in_week_day(day) + 7.days
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def next_weeks weeks_num
|
79
|
+
weeks = weeks_num.nil? ? 1 : weeks_num.to_i
|
80
|
+
@date = @now + (weeks * 7).days
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def previous_weeks weeks_num
|
85
|
+
weeks = weeks_num.nil? ? 1 : weeks_num.to_i
|
86
|
+
@date = @now - (weeks * 7).days
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def month_proto num
|
91
|
+
month = num.nil? ? 1 : num.to_i
|
92
|
+
year, mon = yield(month)
|
93
|
+
@date = Time.mktime(year, mon, @now.day)
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def next_month num
|
98
|
+
month_proto(num) { |month|
|
99
|
+
@now.mon + month > 12 ?
|
100
|
+
[(@now.year + (@now.mon + month) / 12), ((@now.mon + month) % 12)] :
|
101
|
+
[@now.year, (@now.mon + month)]
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def previous_month num
|
107
|
+
month_proto(num) { |month|
|
108
|
+
@now.mon - month < 1 ?
|
109
|
+
[(@now.year - (@now.mon - month) / 12 * -1), (12 - ((month - @now.mon) % 12))] :
|
110
|
+
[@now.year, (@now.mon - month)]
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
public
|
115
|
+
|
116
|
+
def parse
|
117
|
+
case @string
|
118
|
+
|
119
|
+
# вчера
|
120
|
+
# сегодня
|
121
|
+
# завтра
|
122
|
+
when /^(позавчера|вчера|сегодня|завтра|послезавтра)$/i
|
123
|
+
yesterday_today_tomorrow
|
124
|
+
|
125
|
+
# через 1 день
|
126
|
+
# через 2 дня
|
127
|
+
# через 5 дней
|
128
|
+
when /^через\s(\d{1,})\sд(н(|я|ей)|ень)$/i
|
129
|
+
future_days $1
|
130
|
+
|
131
|
+
# через один день
|
132
|
+
# через два дня
|
133
|
+
# через пять дней
|
134
|
+
when /^через\s(#{@@simple_numerics.keys.join('|')})\sд(н(|я|ей)|ень)$/
|
135
|
+
future_days @@simple_numerics[$1]
|
136
|
+
|
137
|
+
# 1 день назад
|
138
|
+
# 2 дня назад
|
139
|
+
# 5 дней назад
|
140
|
+
when /^(\d{1,})\sд(н(|я|ей)|ень)\sназад/i
|
141
|
+
previous_days $1
|
142
|
+
|
143
|
+
# два дня назад
|
144
|
+
# пять дней назад
|
145
|
+
when /^(#{@@simple_numerics.keys.join('|')})\sд(н(|я|ей)|ень)\sназад$/
|
146
|
+
previous_days @@simple_numerics[$1]
|
147
|
+
|
148
|
+
# в понедельник
|
149
|
+
# во вторник
|
150
|
+
# в воскресенье
|
151
|
+
# в эту среду
|
152
|
+
when /^во?\s(эт(о|от|у)\s)?(#{@@week_days.join('|')})$/i
|
153
|
+
in_week_day $3
|
154
|
+
|
155
|
+
# пн (вт ... вс)
|
156
|
+
when /^(#{@@short_week_days.join('|')})$/i
|
157
|
+
in_week_day_short_notation $1
|
158
|
+
|
159
|
+
# в прошлый понедельник
|
160
|
+
# в прошлую среду
|
161
|
+
# в прошлое воскресенье
|
162
|
+
when /^в\sпрошл(ый|ую|ое)\s(#{@@week_days.join('|')})/i
|
163
|
+
in_past_week_day $2
|
164
|
+
|
165
|
+
# в следующий понедельник
|
166
|
+
# в следующую пятницу
|
167
|
+
# в следующее воскресенье
|
168
|
+
when /^в\sследующ(ий|ую|ее)\s(#{@@week_days.join('|')})/i
|
169
|
+
in_next_week_day $2
|
170
|
+
|
171
|
+
# через неделю
|
172
|
+
# через 1 неделю
|
173
|
+
# через 2 недели
|
174
|
+
# через 5 недель
|
175
|
+
when /^через\s(\d{1,})?\s?недел(и|ю|ь)$/i
|
176
|
+
next_weeks $1
|
177
|
+
|
178
|
+
# через две недели
|
179
|
+
# через десять недель
|
180
|
+
when /^через\s(#{@@simple_numerics.keys.join('|')})\sнедел(и|ю|ь)$/
|
181
|
+
next_weeks @@simple_numerics[$1]
|
182
|
+
|
183
|
+
# неделю назад
|
184
|
+
# 1 неделю назад
|
185
|
+
# 2 недели назад
|
186
|
+
# 5 недель назад
|
187
|
+
when /^(\d{1,})?\s?недел(и|ю|ь)\sназад$/i
|
188
|
+
previous_weeks $1
|
189
|
+
|
190
|
+
# две недели назад
|
191
|
+
# десять недель назад
|
192
|
+
when /^(#{@@simple_numerics.keys.join('|')})\sнедел(и|ю|ь)\sназад$/
|
193
|
+
previous_weeks @@simple_numerics[$1]
|
194
|
+
|
195
|
+
# через месяц
|
196
|
+
# через 1 месяц
|
197
|
+
# через 2 месяца
|
198
|
+
# через 5 месяцев
|
199
|
+
when /^через\s(\d{1,})?\s?месяц(|а|ев)$/i
|
200
|
+
next_month $1
|
201
|
+
|
202
|
+
# через два месяца
|
203
|
+
# через десять месяцев
|
204
|
+
when /^через\s(#{@@simple_numerics.keys.join('|')})\sмесяц(|а|ев)$/i
|
205
|
+
next_month @@simple_numerics[$1]
|
206
|
+
|
207
|
+
# месяц назад
|
208
|
+
# 1 месяц назад
|
209
|
+
# 2 месяца назад
|
210
|
+
# 5 месяцев назад
|
211
|
+
when /^(\d{1,})?\s?месяц(|а|ев)\sназад$/i
|
212
|
+
previous_month $1
|
213
|
+
|
214
|
+
# два месяца назад
|
215
|
+
# десять месяцев назад
|
216
|
+
when /^(#{@@simple_numerics.keys.join('|')})\sмесяц(|а|ев)\sназад$/i
|
217
|
+
previous_month @@simple_numerics[$1]
|
218
|
+
|
219
|
+
# 2 октября, 2 окт, 2 окт 2011
|
220
|
+
else
|
221
|
+
if @string =~ /\s?(#{@@month_vocabulary.keys.join('|')})/
|
222
|
+
@string.gsub!($1, @@month_vocabulary[$1])
|
223
|
+
end
|
224
|
+
|
225
|
+
begin
|
226
|
+
tmp_date = Date.parse @string
|
227
|
+
@date = Time.mktime(tmp_date.year, tmp_date.mon, tmp_date.day)
|
228
|
+
|
229
|
+
# TODO: raise an error: Date not recognized
|
230
|
+
rescue => err
|
231
|
+
puts err
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
@date
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
# API simplifier
|
242
|
+
def Day::Ru string
|
243
|
+
Day::Ru.new(string).parse
|
244
|
+
end
|
245
|
+
|
246
|
+
# 1.05.2011
|
247
|
+
# 01.05.2011
|
248
|
+
# 1-5-2011
|
249
|
+
# 2011-5-1
|
250
|
+
# 2011.5.1
|
251
|
+
# 2011.1 (!!!)
|
252
|
+
#p Day::Ru 'через 2 месяца'
|
data/lib/levenshtein.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#
|
2
|
+
# Levenshtein distance algorithm implementation for Ruby, with UTF-8 support
|
3
|
+
#
|
4
|
+
# Author:: Paul BATTLEY (pbattley @ gmail.com)
|
5
|
+
# Version:: 1.3
|
6
|
+
# Date:: 2005-04-19
|
7
|
+
#
|
8
|
+
# == About
|
9
|
+
#
|
10
|
+
# The Levenshtein distance is a measure of how similar two strings s and t are,
|
11
|
+
# calculated as the number of deletions/insertions/substitutions needed to
|
12
|
+
# transform s into t. The greater the distance, the more the strings differ.
|
13
|
+
#
|
14
|
+
# The Levenshtein distance is also sometimes referred to as the
|
15
|
+
# easier-to-pronounce-and-spell 'edit distance'.
|
16
|
+
#
|
17
|
+
# == Revision history
|
18
|
+
#
|
19
|
+
# * 2005-05-19 1.3 Repairing an oversight, distance can now be called via
|
20
|
+
# Levenshtein.distance(s, t)
|
21
|
+
# * 2005-05-04 1.2 Now uses just one 1-dimensional array. I think this is as
|
22
|
+
# far as optimisation can go.
|
23
|
+
# * 2005-05-04 1.1 Now storing only the current and previous rows of the matrix
|
24
|
+
# instead of the whole lot.
|
25
|
+
#
|
26
|
+
# == Licence
|
27
|
+
#
|
28
|
+
# Copyright (c) 2005 Paul Battley
|
29
|
+
#
|
30
|
+
# Usage of the works is permitted provided that this instrument is retained
|
31
|
+
# with the works, so that any entity that uses the works is notified of this
|
32
|
+
# instrument.
|
33
|
+
#
|
34
|
+
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
|
35
|
+
#
|
36
|
+
|
37
|
+
class Levenshtein
|
38
|
+
|
39
|
+
#
|
40
|
+
# Calculate the Levenshtein distance between two strings +str1+ and +str2+.
|
41
|
+
# +str1+ and +str2+ should be ASCII or UTF-8.
|
42
|
+
#
|
43
|
+
class << self
|
44
|
+
|
45
|
+
def distance(str1, str2)
|
46
|
+
s, t = str1.unpack('U*'), str2.unpack('U*')
|
47
|
+
n, m = s.length, t.length
|
48
|
+
return m if (0 == n)
|
49
|
+
return n if (0 == m)
|
50
|
+
|
51
|
+
d = (0..m).to_a
|
52
|
+
x = nil
|
53
|
+
|
54
|
+
(0...n).each do |i|
|
55
|
+
e = i+1
|
56
|
+
(0...m).each do |j|
|
57
|
+
cost = (s[i] == t[j]) ? 0 : 1
|
58
|
+
x = [
|
59
|
+
d[j+1] + 1, # insertion
|
60
|
+
e + 1, # deletion
|
61
|
+
d[j] + cost # substitution
|
62
|
+
].min
|
63
|
+
d[j] = e
|
64
|
+
e = x
|
65
|
+
end
|
66
|
+
d[m] = x
|
67
|
+
end
|
68
|
+
|
69
|
+
return x
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
@needle = 'сиводня'
|
75
|
+
|
76
|
+
@haystack = %w( завтра сегодня вчера позавчера послезавтра январь февраль март апрель май июнь июль август сентябрь октябрь ноябрь декабрь апр)
|
77
|
+
|
78
|
+
words = {}
|
79
|
+
for word in @haystack
|
80
|
+
words[Levenshtein.distance(@needle, word).to_i] = word
|
81
|
+
end
|
82
|
+
|
83
|
+
puts "Closest to #{@needle} word is #{words.sort.flatten[1]}"
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: day
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Sergey Gerasimov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-14 00:00:00 +03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Gem for date parsing (in the scale of the day, hours is not very important in my projects now). It support Russian and Ukrainian (in future) languages.
|
23
|
+
email:
|
24
|
+
- mail@grsmv.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- README.md
|
33
|
+
- CHANGELOG.md
|
34
|
+
- LICENSE
|
35
|
+
- lib/day.rb
|
36
|
+
- lib/levenshtein.rb
|
37
|
+
- data/month_vocabulary.yml
|
38
|
+
- data/short_week_days.yml
|
39
|
+
- data/simple_numerics.yml
|
40
|
+
- data/week_days.yml
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/grsmv/day
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: day
|
71
|
+
rubygems_version: 1.4.2
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Gem for date parsing (in the scale of the day, hours is not very important in my projects now). It support Russian and Ukrainian (in future) languages.
|
75
|
+
test_files: []
|
76
|
+
|