unclekryon 0.4.9.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +34 -0
  3. data/Gemfile.lock +43 -0
  4. data/LICENSE +674 -0
  5. data/README.md +55 -0
  6. data/Rakefile +59 -0
  7. data/bin/unclekryon +30 -0
  8. data/iso/can_provs_terrs.yaml +54 -0
  9. data/iso/countries.yaml +3050 -0
  10. data/iso/iso.yaml +8 -0
  11. data/iso/languages.yaml +5641 -0
  12. data/iso/regions.yaml +42 -0
  13. data/iso/subregions.yaml +6 -0
  14. data/iso/usa_states.yaml +230 -0
  15. data/lib/unclekryon.rb +384 -0
  16. data/lib/unclekryon/data/album_data.rb +147 -0
  17. data/lib/unclekryon/data/artist_data.rb +109 -0
  18. data/lib/unclekryon/data/artist_data_data.rb +146 -0
  19. data/lib/unclekryon/data/aum_data.rb +75 -0
  20. data/lib/unclekryon/data/base_data.rb +79 -0
  21. data/lib/unclekryon/data/pic_data.rb +76 -0
  22. data/lib/unclekryon/data/release_data.rb +57 -0
  23. data/lib/unclekryon/data/social_data.rb +39 -0
  24. data/lib/unclekryon/data/timespan_data.rb +70 -0
  25. data/lib/unclekryon/dev_opts.rb +41 -0
  26. data/lib/unclekryon/hacker.rb +327 -0
  27. data/lib/unclekryon/iso.rb +341 -0
  28. data/lib/unclekryon/iso/base_iso.rb +196 -0
  29. data/lib/unclekryon/iso/can_prov_terr.rb +113 -0
  30. data/lib/unclekryon/iso/country.rb +133 -0
  31. data/lib/unclekryon/iso/language.rb +241 -0
  32. data/lib/unclekryon/iso/region.rb +53 -0
  33. data/lib/unclekryon/iso/subregion.rb +53 -0
  34. data/lib/unclekryon/iso/usa_state.rb +106 -0
  35. data/lib/unclekryon/jsoner.rb +124 -0
  36. data/lib/unclekryon/log.rb +111 -0
  37. data/lib/unclekryon/parsers/kryon_aum_year_album_parser.rb +499 -0
  38. data/lib/unclekryon/parsers/kryon_aum_year_parser.rb +413 -0
  39. data/lib/unclekryon/server.rb +29 -0
  40. data/lib/unclekryon/trainer.rb +231 -0
  41. data/lib/unclekryon/uploader.rb +29 -0
  42. data/lib/unclekryon/util.rb +228 -0
  43. data/lib/unclekryon/version.rb +26 -0
  44. data/unclekryon.gemspec +67 -0
  45. metadata +189 -0
@@ -0,0 +1,341 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # frozen_string_literal: true
4
+
5
+ #--
6
+ # This file is part of UncleKryon-server.
7
+ # Copyright (c) 2018-2019 Jonathan Bradley Whited (@esotericpig)
8
+ #
9
+ # UncleKryon-server is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # UncleKryon-server is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
21
+ #++
22
+
23
+
24
+ require 'bundler/setup'
25
+
26
+ require 'yaml'
27
+
28
+ require 'unclekryon/dev_opts'
29
+ require 'unclekryon/log'
30
+ require 'unclekryon/util'
31
+
32
+ require 'unclekryon/data/base_data'
33
+
34
+ require 'unclekryon/iso/base_iso'
35
+ require 'unclekryon/iso/can_prov_terr'
36
+ require 'unclekryon/iso/country'
37
+ require 'unclekryon/iso/language'
38
+ require 'unclekryon/iso/region'
39
+ require 'unclekryon/iso/subregion'
40
+ require 'unclekryon/iso/usa_state'
41
+
42
+ module UncleKryon
43
+ class Iso
44
+ DEFAULT_FILEPATH = "#{BaseIsos::DEFAULT_DIR}/iso.yaml"
45
+ ID = 'ISO'
46
+
47
+ @@can_provs_terrs = nil
48
+ @@countries = nil
49
+ @@iso = nil
50
+ @@languages = nil
51
+ @@regions = nil
52
+ @@subregions = nil
53
+ @@usa_states = nil
54
+
55
+ attr_accessor :updated_can_provs_terrs_on
56
+ attr_accessor :updated_countries_on
57
+ attr_accessor :updated_languages_on
58
+ attr_accessor :updated_regions_on
59
+ attr_accessor :updated_subregions_on
60
+ attr_accessor :updated_usa_states_on
61
+
62
+ def initialize()
63
+ super()
64
+
65
+ update_all()
66
+ end
67
+
68
+ def self.can_provs_terrs()
69
+ if !@@can_provs_terrs
70
+ @@can_provs_terrs = CanProvsTerrs.load_file()
71
+ end
72
+ return @@can_provs_terrs
73
+ end
74
+
75
+ def self.countries()
76
+ if !@@countries
77
+ @@countries = Countries.load_file()
78
+ end
79
+ return @@countries
80
+ end
81
+
82
+ def self.find_kryon_locations(text)
83
+ locs = []
84
+
85
+ # Fix bad data
86
+ text = text.gsub(/\A[[:space:]]*SASKATOON\-CALGARY[[:space:]]*\z/,'SASKATOON, SASKATCHEWAN, CANADA / CALGARY, ALBERTA, CANADA')
87
+
88
+ # Multiple countries are separated by '/' or '&'
89
+ text.split(/[[:space:]]*[\/\&][[:space:]]*/).each() do |t|
90
+ # Fix misspellings and/or weird shortenings
91
+ t = t.gsub(/Kansas[[:space:]]*\,[[:space:]]*City/i,'Kansas City')
92
+ t = t.gsub(/[\+\*]+/,'') # Means more countries, but won't worry about it (since not listed)
93
+ t = t.gsub(/Berkeley[[:space:]]+Spings/i,'Berkeley Springs, WV')
94
+ t = t.gsub(/SWITZ[[:space:]]*\z/i,'Switzerland')
95
+ t = t.gsub(/\A[[:space:]]*NEWPORT[[:space:]]+BEACH[[:space:]]*\z/,'Newport Beach, California')
96
+ t = t.gsub(/\A[[:space:]]*SAN[[:space:]]+RAFAEL[[:space:]]*\z/,'San Rafael, California')
97
+ t = t.gsub(/\A[[:space:]]*MILANO\,[[:space:]]*MARITTIMA[[:space:]]*\z/,'MILANO MARITTIMA, ITALY')
98
+ t = t.gsub(/\A[[:space:]]*MAR[[:space:]]+DEL[[:space:]]+PLATA[[:space:]]*\z/,'MAR DEL PLATA, ARGENTINA')
99
+ t = t.gsub(/\A[[:space:]]*PATAGONIA[[:space:]]+CRUISE[[:space:]]+2012[[:space:]]*\z/,'Patagonia, South America')
100
+ t = t.gsub(/\A[[:space:]]*PHILADELPHIA,[[:space:]]+PENNSYLVANNIA[[:space:]]*\z/,'Philadelphia, Pennsylvania')
101
+ t = t.gsub(/\ATHE[[:space:]]+AWAKENING[[:space:]]+ZONE.COM\z/,'World')
102
+ t = t.gsub(/\ASEDONA, AZ - Summer Light Conference\z/,'Sedona, AZ')
103
+ t = t.gsub(/\AHAWAII CRUISE 11\z/,'Hawaii')
104
+ t = t.gsub(/\A28 AUDIO FILES - 6 COUNTRIES\z/,'World')
105
+ t = t.gsub(/\ABLOGTALKRADIO\.COM\z/,'World')
106
+ t = t.gsub(/\AAWAKENINGZONE\.COM\z/,'World')
107
+ t = t.gsub(/\AGEMATRIA\s+SEMINAR\z/,'Sedona, Arizona')
108
+ t = t.gsub(/\AKONA\,\s+HAWAI\'I\z/,'Kona, Hawaii')
109
+ t = t.gsub(/\ATALKSHOE\.COM\z/,'World')
110
+ t = t.gsub(/\AConnor\'s\s+Corner\z/,'World')
111
+ t = t.gsub(/\AUNITED\s+NATIONS,\s+NEW\s+YORK\s+CITY\z/i,'United Nations, New York City, NY')
112
+ t = t.gsub(/\AMEDITERRANEAN\s+CRUISE\s+[[:digit:]]+\z/i,'Western Mediterranean')
113
+ t = t.gsub(/\AHAWAI\'I\s+CRUISE\s+[[:digit:]]+\z/i,'Hawaii')
114
+ t = t.gsub(/\AALASKA\s+CRUISE\s+[[:digit:]]+\z/i,'Alaska')
115
+ t = t.gsub(/\AGLASS\s+HOUSE\s+MT\.\s+\(AU\)\z/i,'Glass House Mountains, Australia')
116
+
117
+ parts = t.split(/[[:space:]\,\-]+/)
118
+ last = parts.last
119
+ last2 = (parts.length() >= 2) ? (parts[-2] + last) : nil
120
+
121
+ city = nil
122
+ state = nil
123
+ country = countries().find_by_name(last) # By name because e.g. code CO is Colorado and Colombia
124
+ subregion = nil
125
+ region = nil
126
+
127
+ parse_state = true
128
+ state_i = parts.length() - 1
129
+
130
+ # USA state?
131
+ if country.nil?()
132
+ parse_state = false
133
+ state = usa_states().find(last)
134
+
135
+ if state.nil?() && !last2.nil?()
136
+ state = usa_states().find_by_name(last2)
137
+ state_i = parts.length() - 2 unless state.nil?()
138
+ end
139
+
140
+ if state.nil?()
141
+ # CAN prov/terr? (use state var)
142
+ state = can_provs_terrs().find(last)
143
+
144
+ if state.nil?() && !last2.nil?()
145
+ state = can_provs_terrs().find_by_name(last2)
146
+ state_i = parts.length() - 2 unless state.nil?()
147
+ end
148
+
149
+ if state.nil?()
150
+ # Try country code
151
+ country = countries().find_by_code(last) # Try by code; e.g., CAN for Canada
152
+
153
+ if country.nil?()
154
+ country = countries().find_by_name(t)
155
+ state_i = 0 unless country.nil?()
156
+ end
157
+ if country.nil?() && !last2.nil?()
158
+ country = countries().find_by_name(last2)
159
+ state_i = 0 unless country.nil?()
160
+ end
161
+
162
+ if country.nil?()
163
+ # Subregion?
164
+ subregion = subregions().find_by_name(t)
165
+
166
+ if subregion.nil?() && !last2.nil?()
167
+ subregion = subregions().find_by_name(last2)
168
+ end
169
+
170
+ if subregion.nil?()
171
+ # Region?
172
+ region = regions().find_by_name(t)
173
+
174
+ if region.nil?() && !last2.nil?()
175
+ region = regions().find_by_name(last2)
176
+ end
177
+
178
+ if region.nil?()
179
+ msg = %Q(No state/country/region: "#{text}","#{t}","#{last}")
180
+
181
+ if DevOpts.instance.dev?()
182
+ raise msg
183
+ else
184
+ log.warn(msg)
185
+ end
186
+ else
187
+ region = region.code
188
+ state_i = 0
189
+ end
190
+ else
191
+ subregion = subregion.code
192
+ state_i = 0
193
+ end
194
+ else
195
+ country = country.code
196
+ parse_state = true unless state_i == 0
197
+ end
198
+ else
199
+ state = state.code
200
+ country = countries().find_by_code('CAN').code
201
+ end
202
+ else
203
+ state = state.code
204
+ country = countries().find_by_code('USA').code
205
+ end
206
+ else
207
+ country = country.code
208
+ end
209
+
210
+ if region.nil?() || subregion.nil?()
211
+ # Not USA
212
+ if parse_state
213
+ if parts.length() >= 2
214
+ state = parts[-2].gsub(/[[:space:]]+/,' ').strip()
215
+
216
+ # CAN prov/terr? (use state var)
217
+ if country == countries().find_by_code('CAN').code
218
+ state = can_provs_terrs().find(state)
219
+
220
+ if state.nil?()
221
+ if parts.length() >= 3
222
+ state = can_provs_terrs().find_by_name(parts[-3] + parts[-2])
223
+ state_i = parts.length() - 3 unless state.nil?()
224
+ end
225
+ else
226
+ state = state.code
227
+ state_i = parts.length() - 2
228
+ end
229
+ else
230
+ if state.length() == 2
231
+ state = state.upcase()
232
+ state_i = parts.length() - 2
233
+ else
234
+ state = nil
235
+ end
236
+ end
237
+ end
238
+ end
239
+
240
+ # City
241
+ city = []
242
+ for i in 0...state_i
243
+ c = parts[i].gsub(/[[:space:]]+/,' ').strip()
244
+ city.push(c) unless c.empty?()
245
+ end
246
+ city = city.compact()
247
+ city = city.empty?() ? nil : city.map(&:capitalize).join(' ')
248
+
249
+ # Region
250
+ if !country.nil?()
251
+ region = countries().find_by_code(country).region
252
+ end
253
+ end
254
+
255
+ # Location
256
+ loc = [city,state,country,subregion,region] # Don't do compact(); we want all 4 ','
257
+ locs.push(loc.join(',')) unless loc.compact().empty?()
258
+ end
259
+
260
+ return locs.empty?() ? nil : locs
261
+ end
262
+
263
+ def self.iso()
264
+ if !@@iso
265
+ @@iso = Iso.load_file()
266
+ end
267
+ return @@iso
268
+ end
269
+
270
+ def self.languages()
271
+ if !@@languages
272
+ @@languages = Languages.load_file()
273
+ end
274
+ return @@languages
275
+ end
276
+
277
+ def self.load_file(filepath=DEFAULT_FILEPATH)
278
+ y = YAML.load_file(filepath)
279
+ iso = y[ID]
280
+ return iso
281
+ end
282
+
283
+ def self.regions()
284
+ if !@@regions
285
+ @@regions = Regions.load_file()
286
+ end
287
+ return @@regions
288
+ end
289
+
290
+ def save_to_file(filepath=DEFAULT_FILEPATH)
291
+ File.open(filepath,'w') do |f|
292
+ iso = {ID=>self}
293
+ YAML.dump(iso,f)
294
+ end
295
+ end
296
+
297
+ def self.subregions()
298
+ if !@@subregions
299
+ @@subregions = Subregions.load_file()
300
+ end
301
+ return @@subregions
302
+ end
303
+
304
+ def update_all()
305
+ @updated_can_provs_terrs_on = BaseData.max_updated_on_s(self.class.can_provs_terrs.values)
306
+ @updated_countries_on = BaseData.max_updated_on_s(self.class.countries.values)
307
+ @updated_languages_on = BaseData.max_updated_on_s(self.class.languages.values)
308
+ @updated_regions_on = BaseData.max_updated_on_s(self.class.regions.values)
309
+ @updated_subregions_on = BaseData.max_updated_on_s(self.class.subregions.values)
310
+ @updated_usa_states_on = BaseData.max_updated_on_s(self.class.usa_states.values)
311
+ end
312
+
313
+ def self.usa_states()
314
+ if !@@usa_states
315
+ @@usa_states = UsaStates.load_file()
316
+ end
317
+ return @@usa_states
318
+ end
319
+
320
+ def to_s()
321
+ s = 'Updated On:'.dup()
322
+ s << "\n- CAN Provs/Terrs: #{@updated_can_provs_terrs_on}"
323
+ s << "\n- Countries: #{@updated_countries_on}"
324
+ s << "\n- Languages: #{@updated_languages_on}"
325
+ s << "\n- Regions: #{@updated_regions_on}"
326
+ s << "\n- Subregions: #{@updated_subregions_on}"
327
+ s << "\n- USA States: #{@updated_usa_states_on}"
328
+ return s
329
+ end
330
+ end
331
+ end
332
+
333
+ if $0 == __FILE__
334
+ puts UncleKryon::Iso.can_provs_terrs['ON']
335
+ puts UncleKryon::Iso.countries['USA']
336
+ puts UncleKryon::Iso.languages['eng']
337
+ puts UncleKryon::Iso.regions['South America']
338
+ puts UncleKryon::Iso.subregions['Pantagonia']
339
+ puts UncleKryon::Iso.usa_states['AL']
340
+ puts UncleKryon::Iso.iso
341
+ end
@@ -0,0 +1,196 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # frozen_string_literal: true
4
+
5
+ #--
6
+ # This file is part of UncleKryon-server.
7
+ # Copyright (c) 2018-2019 Jonathan Bradley Whited (@esotericpig)
8
+ #
9
+ # UncleKryon-server is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # UncleKryon-server is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
21
+ #++
22
+
23
+
24
+ require 'yaml'
25
+
26
+ require 'unclekryon/log'
27
+ require 'unclekryon/util'
28
+
29
+ require 'unclekryon/data/base_data'
30
+
31
+ module UncleKryon
32
+ class BaseIso < BaseData
33
+ attr_reader :name
34
+ attr_reader :code
35
+
36
+ def initialize()
37
+ super()
38
+
39
+ @name = nil
40
+ @code = nil
41
+ end
42
+
43
+ def self.fix_name(name)
44
+ return self.flip_word_order(self.simplify_name(name))
45
+ end
46
+
47
+ def self.flip_word_order(word)
48
+ # e.g., change 'English, Old' to 'Old English'
49
+ return word.gsub(/([^\,\;]+)[[:space:]]*[\,\;]+[[:space:]]*([^\,\;]+)/,'\\2 \\1').strip()
50
+ end
51
+
52
+ def self.simplify_code(code)
53
+ # e.g., remove 'US-' from 'US-AL'
54
+ return code.gsub(/[[:alnum:][:space:]]+\-[[:space:]]*/,'').strip()
55
+ end
56
+
57
+ def self.simplify_name(name)
58
+ # e.g., remove '(the)' from 'United States of America (the)'
59
+ return name.gsub(/[[:space:]]*\([^\)]*\)[[:space:]]*/,'').strip()
60
+ end
61
+
62
+ def ==(y)
63
+ return @name == y.name && @code == y.code
64
+ end
65
+
66
+ def to_s()
67
+ return %Q(["#{@name}",#{@code}])
68
+ end
69
+ end
70
+
71
+ class BaseIsos
72
+ include Logging
73
+
74
+ DEFAULT_DIR = 'iso'
75
+
76
+ attr_reader :id
77
+ attr_reader :values
78
+
79
+ def initialize()
80
+ super()
81
+
82
+ @id = self.class.get_class_name(self)
83
+ @values = {}
84
+ end
85
+
86
+ def find(text)
87
+ lang = find_by_name(text)
88
+ return lang unless lang.nil?()
89
+
90
+ lang = find_by_code(text)
91
+ return lang
92
+ end
93
+
94
+ def find_by_code(code)
95
+ code = code.gsub(/[[:space:]]+/,'').downcase()
96
+
97
+ @values.each() do |k,v|
98
+ codes = nil
99
+
100
+ if v.respond_to?(:codes)
101
+ codes = v.codes()
102
+ elsif v.respond_to?(:code)
103
+ codes = [v.code()]
104
+ else
105
+ raise "No codes()/code() method for class #{v.class.name}"
106
+ end
107
+
108
+ codes.each() do |c|
109
+ next if c.nil?()
110
+ c = c.gsub(/[[:space:]]+/,'').downcase()
111
+ return v if c == code
112
+ end
113
+ end
114
+
115
+ return nil
116
+ end
117
+
118
+ def find_by_name(name)
119
+ name = name.gsub(/[[:space:]]+/,'').downcase()
120
+
121
+ @values.each() do |k,v|
122
+ names = nil
123
+
124
+ if v.respond_to?(:names)
125
+ names = v.names()
126
+ elsif v.respond_to?(:name)
127
+ names = [v.name()]
128
+ else
129
+ raise "No names()/name() method for class #{v.class.name}"
130
+ end
131
+
132
+ names.each() do |n|
133
+ next if n.nil?()
134
+ n = n.gsub(/[[:space:]]+/,'').downcase()
135
+ return v if n == name
136
+ end
137
+ end
138
+
139
+ return nil
140
+ end
141
+
142
+ def load_file(filepath)
143
+ y = YAML.load_file(filepath)
144
+ @values.merge!(y[@id])
145
+
146
+ return self
147
+ end
148
+
149
+ def save_to_file(filepath)
150
+ File.open(filepath,'w') do |f|
151
+ v = {}
152
+ v[@id] = @values
153
+ YAML.dump(v,f)
154
+ end
155
+ end
156
+
157
+ def sort_keys!()
158
+ # Old way: @values = @values.sort().to_h()
159
+
160
+ new_values = {}
161
+
162
+ @values.keys().sort().each() do |code|
163
+ new_values[code] = @values[code]
164
+ end
165
+
166
+ @values = new_values
167
+ return self
168
+ end
169
+
170
+ def [](code)
171
+ @values[code]
172
+ end
173
+
174
+ def []=(code,value)
175
+ @values[code] = value
176
+ end
177
+
178
+ def self.get_class_name(class_var)
179
+ return class_var.class.name.split('::').last
180
+ end
181
+
182
+ def key?(code)
183
+ @values.key?(code)
184
+ end
185
+
186
+ def to_s()
187
+ s = ''.dup()
188
+
189
+ @values.each() do |code,value|
190
+ s << "#{code}: #{value}\n"
191
+ end
192
+
193
+ return s
194
+ end
195
+ end
196
+ end