forked from zerebubuth/openstreetmap-license-change
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abbreviations.rb
199 lines (193 loc) · 5.23 KB
/
abbreviations.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# mod for doing stuff w/ abbrevs
module Abbrev
# a list of abbreviations culled, at least in part, from the USPS
# official list https://www.usps.com/send/official-abbreviations.htm#2
# this might be too country-specific, but it's a start.
ABBREVIATIONS = {
"alley" => ["aly"],
"annex" => ["anx"],
"arcade" => ["arc"],
"avenue" => ["ave"],
"beach" => ["bch"],
"burg" => ["bg"],
"bluff" => ["blf"],
"boulevard" => ["blvd"],
"bend" => ["bnd"],
"branch" => ["br"],
"bridge" => ["brg"],
"brook" => ["brk"],
"bottom" => ["btm"],
"bayoo" => ["byu"],
"circle" => ["cir"],
"club" => ["clb"],
"cliff" => ["clf"],
"common" => ["cmn"],
"corner" => ["cor"],
"camp" => ["cp"],
"cape" => ["cpe"],
"crescent" => ["cr","cres"],
"creek" => ["crk"],
"course" => ["crse"],
"crest" => ["crst"],
"causeway" => ["cswy"],
"court" => ["ct"],
"center" => ["ctr"],
"curve" => ["curv"],
"cove" => ["cv"],
"canyon" => ["cyn"],
"dale" => ["dl"],
"dam" => ["dm"],
"drive" => ["dr"],
"divide" => ["dv"],
"east" => ["e"],
"estate" => ["est"],
"expressway" => ["expy"],
"extension" => ["ext"],
"field" => ["fld"],
"flat" => ["flt"],
"ford" => ["frd"],
"forge" => ["frg"],
"fork" => ["frk"],
"forest" => ["frst"],
"ferry" => ["fry"],
"fort" => ["ft"],
"freeway" => ["fwy"],
"garden" => ["gdn"],
"glen" => ["gln"],
"green" => ["grn"],
"grove" => ["grv"],
"gateway" => ["gtwy"],
"harbor" => ["hbr"],
"hill" => ["hl"],
"hollow" => ["holw"],
"haven" => ["hvn"],
"highway" => ["hwy"],
"inlet" => ["inlt"],
"island" => ["is"],
"junction" => ["jct"],
"knoll" => ["knl"],
"key" => ["ky"],
"lock" => ["lck"],
"lodge" => ["ldg"],
"loaf" => ["lf"],
"light" => ["lgt"],
"lake" => ["lk"],
"lane" => ["ln"],
"landing" => ["lndg"],
"meadow" => ["mdw"],
"mill" => ["ml"],
"manor" => ["mnr"],
"mission" => ["msn"],
"mount" => ["mt"],
"mountain" => ["mtn"],
"motorway" => ["mtwy"],
"neck" => ["nck"],
"north" => ["n"],
"orchard" => ["orch"],
"parkway" => ["pkwy"],
"place" => ["pl"],
"plain" => ["pln"],
"plaza" => ["plz"],
"pine" => ["pne"],
"prairie" => ["pr"],
"port" => ["prt"],
"passage" => ["psge"],
"point" => ["pt"],
"radial" => ["radl"],
"road" => ["rd"],
"ridge" => ["rdg"],
"river" => ["riv"],
"ranch" => ["rnch"],
"row" => ["row"],
"rapid" => ["rpd"],
"rest" => ["rst"],
"route" => ["rte"],
"shoal" => ["shl"],
"shore" => ["shr"],
"skyway" => ["skwy"],
"south" => ["s"],
"summit" => ["smt"],
"spring" => ["spg"],
"square" => ["sq"],
"street" => ["st"],
"station" => ["sta"],
"stravenue" => ["stra"],
"stream" => ["strm"],
"terrace" => ["ter"],
"turnpike" => ["tpke"],
"track" => ["trak"],
"trace" => ["trce"],
"trafficway" => ["trfy"],
"trail" => ["trl"],
"throughway" => ["trwy"],
"tunnel" => ["tunl"],
"union" => ["un"],
"viaduct" => ["via"],
"vista" => ["vis"],
"ville" => ["vl"],
"village" => ["vlg"],
"valley" => ["vly"],
"view" => ["vw"],
"way" => ["wy"],
"well" => ["wl"],
"west" => ["w"],
"crossing" => ["xing"],
"crossroad" => ["xrd"]
}
# of course, this is horribly english-specific...
# but how would one expand this in a sensible fashion to
# cover other languages?
COMPASS = {
"n" => ["north"],
"nne" => ["north","north","east"],
"ne" => ["north","east"],
"ene" => ["east","north","east"],
"e" => ["east"],
"ese" => ["east","south","east"],
"se" => ["south","east"],
"sse" => ["south","south","east"],
"s" => ["south"],
"ssw" => ["south","south","west"],
"sw" => ["south","west"],
"wsw" => ["west","south","west"],
"w" => ["west"],
"wnw" => ["west","north","west"],
"nw" => ["north","west"],
"nnw" => ["north","north","west"]
}
# function for expanding a string into a list of strings
# TODO: may need some work for internationalisation
def self.equal_expansions(a, b)
a = a.downcase.split(/[[:punct:][:space:]]+/)
b = b.downcase.split(/[[:punct:][:space:]]+/)
# expand compass directions in each - SPECIAL CASE... this is kinda
# nasty, but i really can't think of a better way to do it at the
# moment...
a = a.inject(Array.new) do |ary,el|
if COMPASS.has_key? el
ary + COMPASS[el]
else
ary + [el]
end
end
b = b.inject(Array.new) do |ary,el|
if COMPASS.has_key? el
ary + COMPASS[el]
else
ary + [el]
end
end
# no expansions which alter the number of words. (really? - check this)
return false if a.length != b.length
# check whether each is equal], or can be reached by expansion
# or abbreviation.
a.zip(b) do |a_el, b_el|
if a_el != b_el
match = ((ABBREVIATIONS.has_key?(a_el) && ABBREVIATIONS[a_el].any? {|a_ab| a_ab == b_el}) or
(ABBREVIATIONS.has_key?(b_el) && ABBREVIATIONS[b_el].any? {|b_ab| b_ab == a_el}))
return false if not match
end
end
return true
end
end