fias 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -22
- data/.rubocop.yml +7 -0
- data/.travis.yml +10 -0
- data/Gemfile +1 -1
- data/LICENSE.txt +2 -2
- data/README.md +259 -155
- data/Rakefile +6 -1
- data/config/names.txt +0 -0
- data/config/synonyms.yml +50 -0
- data/examples/create.rb +106 -0
- data/examples/generate_index.rb +63 -0
- data/fias.gemspec +33 -21
- data/lib/fias.rb +197 -10
- data/lib/fias/config.rb +74 -0
- data/lib/fias/import/copy.rb +62 -0
- data/lib/fias/import/dbf.rb +81 -0
- data/lib/fias/import/download_service.rb +37 -0
- data/lib/fias/import/restore_parent_id.rb +51 -0
- data/lib/fias/import/tables.rb +74 -0
- data/lib/fias/name/append.rb +30 -0
- data/lib/fias/name/canonical.rb +42 -0
- data/lib/fias/name/extract.rb +85 -0
- data/lib/fias/name/house_number.rb +71 -0
- data/lib/fias/name/split.rb +60 -0
- data/lib/fias/name/synonyms.rb +93 -0
- data/lib/fias/query.rb +43 -0
- data/lib/fias/query/estimate.rb +67 -0
- data/lib/fias/query/finder.rb +75 -0
- data/lib/fias/query/params.rb +101 -0
- data/lib/fias/railtie.rb +3 -17
- data/lib/fias/version.rb +1 -1
- data/spec/fixtures/ACTSTAT.DBF +0 -0
- data/spec/fixtures/NORDOC99.DBF +0 -0
- data/spec/fixtures/STRSTAT.DBF +0 -0
- data/spec/fixtures/addressing.yml +93 -0
- data/spec/fixtures/query.yml +79 -0
- data/spec/fixtures/query_sanitization.yml +75 -0
- data/spec/fixtures/status_append.yml +60 -0
- data/spec/lib/import/copy_spec.rb +44 -0
- data/spec/lib/import/dbf_spec.rb +28 -0
- data/spec/lib/import/download_service_spec.rb +15 -0
- data/spec/lib/import/restore_parent_id_spec.rb +34 -0
- data/spec/lib/import/tables_spec.rb +26 -0
- data/spec/lib/name/append_spec.rb +14 -0
- data/spec/lib/name/canonical_spec.rb +20 -0
- data/spec/lib/name/extract_spec.rb +67 -0
- data/spec/lib/name/house_number_spec.rb +45 -0
- data/spec/lib/name/query_spec.rb +21 -0
- data/spec/lib/name/split_spec.rb +15 -0
- data/spec/lib/name/synonyms_spec.rb +51 -0
- data/spec/lib/query/params_spec.rb +15 -0
- data/spec/lib/query_spec.rb +27 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/support/db.rb +30 -0
- data/spec/support/query.rb +13 -0
- data/tasks/db.rake +52 -0
- data/tasks/download.rake +15 -0
- metadata +246 -64
- data/lib/fias/active_record/address_object.rb +0 -231
- data/lib/fias/active_record/address_object_type.rb +0 -15
- data/lib/fias/dbf_wrapper.rb +0 -90
- data/lib/fias/importer.rb +0 -30
- data/lib/fias/importer/base.rb +0 -59
- data/lib/fias/importer/pg.rb +0 -81
- data/lib/fias/importer/sqlite.rb +0 -38
- data/lib/generators/fias/migration.rb +0 -34
- data/lib/generators/fias/templates/create_fias_tables.rb +0 -5
- data/tasks/fias.rake +0 -68
@@ -0,0 +1,101 @@
|
|
1
|
+
module Fias
|
2
|
+
module Query
|
3
|
+
class Params
|
4
|
+
KEYS = %i(street subcity city district region)
|
5
|
+
|
6
|
+
def initialize(params)
|
7
|
+
@params = params
|
8
|
+
@params.assert_valid_keys(*KEYS)
|
9
|
+
|
10
|
+
extract_names
|
11
|
+
remove_duplicates
|
12
|
+
move_federal_city_to_correct_place
|
13
|
+
strip_house_number
|
14
|
+
sort
|
15
|
+
extract_synonyms
|
16
|
+
split_sanitized
|
17
|
+
fill_forms
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :params, :sanitized, :synonyms, :split, :forms
|
21
|
+
|
22
|
+
KEYS.each { |key| define_method(key) { @sanitized[key] } }
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def extract_names
|
27
|
+
extracted = @params.map do |name, value|
|
28
|
+
if value.is_a?(Array)
|
29
|
+
[name, value]
|
30
|
+
else
|
31
|
+
next if value.blank? || !value.is_a?(String)
|
32
|
+
[name, Fias::Name::Extract.extract(value)]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
@sanitized = Hash[*extracted.compact.flatten(1)]
|
37
|
+
end
|
38
|
+
|
39
|
+
def remove_duplicates
|
40
|
+
@sanitized.delete(:region) if region == city
|
41
|
+
@sanitized.delete(:district) if [region, city].include?(district)
|
42
|
+
@sanitized.delete(:street) if street == district
|
43
|
+
end
|
44
|
+
|
45
|
+
def move_federal_city_to_correct_place
|
46
|
+
federal_city = find_federal_city
|
47
|
+
return unless federal_city
|
48
|
+
|
49
|
+
@sanitized[:subcity] = city if city && city[0] != federal_city[0]
|
50
|
+
|
51
|
+
if federal_city[1].blank?
|
52
|
+
federal_city += Fias::Name::Canonical.canonical('г.')
|
53
|
+
end
|
54
|
+
|
55
|
+
@sanitized[:city] = federal_city
|
56
|
+
@sanitized.delete(:district)
|
57
|
+
@sanitized.delete(:region)
|
58
|
+
end
|
59
|
+
|
60
|
+
def find_federal_city
|
61
|
+
@sanitized.values.find do |value|
|
62
|
+
value.is_a?(Array) && Fias::FEDERAL_CITIES.include?(value.first)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def strip_house_number
|
67
|
+
return if street.blank?
|
68
|
+
@sanitized[:street] = Fias::Name::HouseNumber.extract(street).first
|
69
|
+
end
|
70
|
+
|
71
|
+
def sort
|
72
|
+
sanitized = KEYS.map do |key|
|
73
|
+
value = @sanitized[key]
|
74
|
+
[key, value] if value.present?
|
75
|
+
end
|
76
|
+
@sanitized = Hash[sanitized.compact]
|
77
|
+
end
|
78
|
+
|
79
|
+
def extract_synonyms
|
80
|
+
@synonyms = @sanitized.map do |key, value|
|
81
|
+
[key, Fias::Name::Synonyms.expand(value.first)]
|
82
|
+
end
|
83
|
+
@synonyms = Hash[@synonyms]
|
84
|
+
end
|
85
|
+
|
86
|
+
def split_sanitized
|
87
|
+
@split = @sanitized.map do |key, value|
|
88
|
+
[key, Fias::Name::Split.split(value.first)]
|
89
|
+
end
|
90
|
+
@split = Hash[@split]
|
91
|
+
end
|
92
|
+
|
93
|
+
def fill_forms
|
94
|
+
@forms = @sanitized.map do |key, value|
|
95
|
+
[key, Fias::Name::Synonyms.forms(value.first)]
|
96
|
+
end
|
97
|
+
@forms = Hash[@forms]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/fias/railtie.rb
CHANGED
@@ -1,22 +1,8 @@
|
|
1
1
|
module Fias
|
2
2
|
class Railtie < Rails::Railtie
|
3
|
-
config.fias = ActiveSupport::OrderedOptions.new
|
4
|
-
config.fias.prefix = 'fias'
|
5
|
-
config.app_generators.orm :active_record
|
6
|
-
|
7
|
-
generators do
|
8
|
-
require 'generators/fias/migration'
|
9
|
-
end
|
10
|
-
|
11
3
|
rake_tasks do
|
12
|
-
load File.join(File.dirname(__FILE__), '../../tasks/
|
13
|
-
|
14
|
-
|
15
|
-
initializer 'fias.load_models' do
|
16
|
-
ActiveSupport.on_load(:active_record) do
|
17
|
-
require 'fias/active_record/address_object'
|
18
|
-
require 'fias/active_record/address_object_type'
|
19
|
-
end
|
4
|
+
load File.join(File.dirname(__FILE__), '../../tasks/db.rake')
|
5
|
+
load File.join(File.dirname(__FILE__), '../../tasks/download.rake')
|
20
6
|
end
|
21
7
|
end
|
22
|
-
end
|
8
|
+
end
|
data/lib/fias/version.rb
CHANGED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,93 @@
|
|
1
|
+
- # 0
|
2
|
+
- [region, 'Оренбургская область']
|
3
|
+
- [district, 'Майкопский район']
|
4
|
+
- [city, 'город Майкоп']
|
5
|
+
- [street, 'ул. Декабристов']
|
6
|
+
- # 1
|
7
|
+
- [region, 'Оренбургская область']
|
8
|
+
- [district, 'Майкопский район']
|
9
|
+
- [city, 'город Майкоп']
|
10
|
+
- [street, 'переулок Декабристов']
|
11
|
+
- # 2
|
12
|
+
- [region, 'Оренбургская область']
|
13
|
+
- [district, 'Майкопский район']
|
14
|
+
- [city, 'город Жужу']
|
15
|
+
- [street, 'ул. Декабристов']
|
16
|
+
- # 3
|
17
|
+
- [region, 'Оренбургская область']
|
18
|
+
- [district, 'Майкопский район']
|
19
|
+
- [city, 'д Майкоп']
|
20
|
+
- [street, 'ул Декабристов']
|
21
|
+
- # 4
|
22
|
+
- [region, 'Ленинградская область']
|
23
|
+
- [city, 'г Ленинград']
|
24
|
+
- [street, 'ул Декабристов']
|
25
|
+
- # 5
|
26
|
+
- [region, 'Оренбургская область']
|
27
|
+
- [district, 'Майкопский район']
|
28
|
+
- [city, 'д Майкоп']
|
29
|
+
- [street, 'ул Евангелистов']
|
30
|
+
- # 6
|
31
|
+
- [city, 'г Москва']
|
32
|
+
- [city, 'д Бутово']
|
33
|
+
- [street, 'ул Вережева']
|
34
|
+
- # 7
|
35
|
+
- [region, 'Московская область']
|
36
|
+
- [city, 'г Балашиха']
|
37
|
+
- [street, 'ул Солнечная']
|
38
|
+
- # 8
|
39
|
+
- [region, 'Московская область']
|
40
|
+
- [city, 'г Балашиха']
|
41
|
+
- [street, 'мкр Салтыковка']
|
42
|
+
- [street, 'ул Солнечная']
|
43
|
+
- # 9
|
44
|
+
- [city, 'г Москва']
|
45
|
+
- [street, 'ул Солнечная']
|
46
|
+
- # 10
|
47
|
+
- [region, 'Балашихинская область']
|
48
|
+
- [city, 'пос Ленина']
|
49
|
+
- [street, 'ул Ленина']
|
50
|
+
- # 11
|
51
|
+
- [region, 'Балашихинская область']
|
52
|
+
- [city, 'пос Мусай']
|
53
|
+
- [street, 'ул Ленина']
|
54
|
+
- # 12
|
55
|
+
- [city, 'г Москва']
|
56
|
+
- [street, 'ул Новая']
|
57
|
+
- # 13
|
58
|
+
- [city, 'г Москва']
|
59
|
+
- [city, 'пгт Горелово']
|
60
|
+
- [street, 'ул Новая']
|
61
|
+
- # 14
|
62
|
+
- [city, 'г Москва']
|
63
|
+
- [city, 'пгт Горелово']
|
64
|
+
- [street, 'ул Неизвестная']
|
65
|
+
- # 15
|
66
|
+
- [region, 'Липецкая область']
|
67
|
+
- [city, 'г Липецк']
|
68
|
+
- [street, 'ул Неизвестная']
|
69
|
+
- # 16
|
70
|
+
- [city, 'г Москва']
|
71
|
+
- [street, 'улица 14-ая Текстильщиков']
|
72
|
+
- # 17
|
73
|
+
- [region, 'Кубанская АО']
|
74
|
+
- [district, 'Сочинский район']
|
75
|
+
- [city, 'г Сочи']
|
76
|
+
- [street, 'Виноградная улица']
|
77
|
+
- # 18
|
78
|
+
- [city, 'г Санкт-Петербург']
|
79
|
+
- [street, '14-я В.О. линия']
|
80
|
+
- # 19
|
81
|
+
- [city, 'г Санкт-Петербург']
|
82
|
+
- [street, '14-я Краснармейская ул']
|
83
|
+
- # 20
|
84
|
+
- [city, 'г Санкт-Петербург']
|
85
|
+
- [street, 'пр. Большой В.О.']
|
86
|
+
- # 21
|
87
|
+
- [city, 'г Санкт-Петербург']
|
88
|
+
- [street, 'пр. Большой П.С.']
|
89
|
+
- # 22
|
90
|
+
- [city, 'г Лебяжье']
|
91
|
+
- # 23
|
92
|
+
- [city, 'г Москва']
|
93
|
+
- [city, 'д Кокошкино']
|
@@ -0,0 +1,79 @@
|
|
1
|
+
- # exact mapping
|
2
|
+
-
|
3
|
+
region: Оренбургская область
|
4
|
+
district: Майкопский район
|
5
|
+
city: город Майкоп
|
6
|
+
street: ул. Декабристов
|
7
|
+
- [0]
|
8
|
+
|
9
|
+
- # lot of equal variants
|
10
|
+
-
|
11
|
+
region: Оренбургская область
|
12
|
+
district: Майкопский район
|
13
|
+
street: Декабристов
|
14
|
+
- [0, 1, 2, 3]
|
15
|
+
|
16
|
+
- # must look up most superficial address
|
17
|
+
-
|
18
|
+
street: Солнечная
|
19
|
+
city: Балашиха
|
20
|
+
district: Балашихинский район
|
21
|
+
region: Московская область
|
22
|
+
|
23
|
+
- [7]
|
24
|
+
|
25
|
+
- # must lookup most conforming street even if it present in subcity
|
26
|
+
-
|
27
|
+
street: Новая
|
28
|
+
city: Москва
|
29
|
+
- [12]
|
30
|
+
|
31
|
+
- # must lookup street even it present in multiple cities
|
32
|
+
-
|
33
|
+
street: Неизвестная
|
34
|
+
city: Липецк
|
35
|
+
- [15]
|
36
|
+
|
37
|
+
- # must lookup street by alias
|
38
|
+
-
|
39
|
+
city: Москва
|
40
|
+
street: ул. Текстильщиков 14-я
|
41
|
+
|
42
|
+
- [16]
|
43
|
+
|
44
|
+
- # must lookup vasilievsky lines
|
45
|
+
-
|
46
|
+
city: Санкт-Петербург
|
47
|
+
street: 14 линия
|
48
|
+
- [18]
|
49
|
+
|
50
|
+
- # must lookup v.o
|
51
|
+
-
|
52
|
+
city: Санкт-Петербург
|
53
|
+
street: Большой В.О. пр.
|
54
|
+
- [20]
|
55
|
+
|
56
|
+
- # must lookup bolshoy
|
57
|
+
-
|
58
|
+
city: Санкт-Петербург
|
59
|
+
street: Большой пр
|
60
|
+
- [20, 21]
|
61
|
+
|
62
|
+
- # must look up single city in Russia
|
63
|
+
-
|
64
|
+
city: Лебяжье
|
65
|
+
- [22]
|
66
|
+
|
67
|
+
- # must look up subcity
|
68
|
+
-
|
69
|
+
city: Москва
|
70
|
+
subcity: Кокошкино
|
71
|
+
-
|
72
|
+
[23]
|
73
|
+
|
74
|
+
- # must look up subcity even federal city given as region
|
75
|
+
-
|
76
|
+
region: Москва
|
77
|
+
city: Кокошкино
|
78
|
+
-
|
79
|
+
[23]
|
@@ -0,0 +1,75 @@
|
|
1
|
+
-
|
2
|
+
-
|
3
|
+
city: г. Биробиджан
|
4
|
+
region: Еврейская АОбл
|
5
|
+
street: Шолом-Алейхема
|
6
|
+
-
|
7
|
+
region: [Еврейская, автономная область, Аобл, Аобл]
|
8
|
+
city: [Биробиджан, город, г, г.]
|
9
|
+
street: [Шолом-Алейхема]
|
10
|
+
-
|
11
|
+
-
|
12
|
+
street: Ленина
|
13
|
+
city: Москва
|
14
|
+
district: Московская область
|
15
|
+
region: Московская область
|
16
|
+
-
|
17
|
+
city: [Москва, город, г, г.]
|
18
|
+
street: [Ленина]
|
19
|
+
-
|
20
|
+
-
|
21
|
+
city: Санкт-Петербург
|
22
|
+
district: г Санкт-Петербург
|
23
|
+
region: Санкт-Петербург
|
24
|
+
street: Ленинский
|
25
|
+
-
|
26
|
+
city: [Санкт-Петербург, город, г, г.]
|
27
|
+
street: [Ленинский]
|
28
|
+
-
|
29
|
+
-
|
30
|
+
city: Санкт-Петербург
|
31
|
+
district: Санкт-Петербург
|
32
|
+
region: Санкт-Петербург
|
33
|
+
street: Ленинский
|
34
|
+
-
|
35
|
+
city: [Санкт-Петербург, город, г, г.]
|
36
|
+
street: [Ленинский]
|
37
|
+
-
|
38
|
+
-
|
39
|
+
region: Санкт-Петербург
|
40
|
+
street: Ленинский
|
41
|
+
-
|
42
|
+
city: [Санкт-Петербург, город, г, г.]
|
43
|
+
street: [Ленинский]
|
44
|
+
-
|
45
|
+
-
|
46
|
+
region: Алтай
|
47
|
+
district: Алтай
|
48
|
+
city: Ростов
|
49
|
+
street: Ленинский
|
50
|
+
-
|
51
|
+
region: [Алтай]
|
52
|
+
city: [Ростов]
|
53
|
+
street: [Ленинский]
|
54
|
+
|
55
|
+
-
|
56
|
+
-
|
57
|
+
region: Москва
|
58
|
+
city: Москва
|
59
|
+
-
|
60
|
+
city: [Москва, город, г, г.]
|
61
|
+
|
62
|
+
-
|
63
|
+
-
|
64
|
+
region: Москва
|
65
|
+
district:
|
66
|
+
city: г Москва
|
67
|
+
-
|
68
|
+
city: [Москва, город, г, г.]
|
69
|
+
-
|
70
|
+
-
|
71
|
+
region: Москва
|
72
|
+
city: Кокошкино
|
73
|
+
-
|
74
|
+
city: [Москва, город, г, г.]
|
75
|
+
subcity: [Кокошкино]
|
@@ -0,0 +1,60 @@
|
|
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
|
+
- [2-я Советская, улица]
|
29
|
+
- 2-я Советская ул.
|
30
|
+
- 2-я Советская улица
|
31
|
+
|
32
|
+
-
|
33
|
+
- [Дальневосточный, округ]
|
34
|
+
- Дальневосточный округ
|
35
|
+
- Дальневосточный округ
|
36
|
+
|
37
|
+
-
|
38
|
+
- ['1', линия]
|
39
|
+
- 1 линия
|
40
|
+
- 1 линия
|
41
|
+
|
42
|
+
-
|
43
|
+
- [1-я, линия]
|
44
|
+
- 1-я линия
|
45
|
+
- 1-я линия
|
46
|
+
|
47
|
+
-
|
48
|
+
- [2-й Советской диктатуры, линия]
|
49
|
+
- линия 2-й Советской диктатуры
|
50
|
+
- линия 2-й Советской диктатуры
|
51
|
+
|
52
|
+
-
|
53
|
+
- [Поперечная, линия]
|
54
|
+
- Поперечная линия
|
55
|
+
- Поперечная линия
|
56
|
+
|
57
|
+
-
|
58
|
+
- [Косая, аллея]
|
59
|
+
- Косая аллея
|
60
|
+
- Косая аллея
|