atlas_engine 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -4
- data/app/countries/atlas_engine/cz/country_profile.yml +3 -0
- data/app/countries/atlas_engine/es/country_profile.yml +3 -0
- data/app/countries/atlas_engine/es/synonyms.yml +2 -0
- data/app/countries/atlas_engine/es/validation_transcriber/address_parser.rb +28 -0
- data/app/countries/atlas_engine/fo/address_importer/corrections/open_address/city_corrector.rb +27 -0
- data/app/countries/atlas_engine/fo/country_profile.yml +4 -0
- data/app/countries/atlas_engine/fr/country_profile.yml +2 -0
- data/app/countries/atlas_engine/it/address_validation/validators/full_address/exclusions/city.rb +31 -0
- data/app/countries/atlas_engine/it/country_profile.yml +4 -0
- data/app/countries/atlas_engine/kr/address_validation/validators/full_address/exclusions/city.rb +69 -0
- data/app/countries/atlas_engine/kr/country_profile.yml +7 -0
- data/app/countries/atlas_engine/kr/validation_transcriber/address_parser.rb +36 -0
- data/app/countries/atlas_engine/lu/address_importer/corrections/open_address/city_corrector.rb +45 -0
- data/app/countries/atlas_engine/lu/country_profile.yml +4 -1
- data/app/countries/atlas_engine/lu/validation_transcriber/address_parser.rb +23 -0
- data/app/countries/atlas_engine/pl/address_importer/corrections/open_address/city_corrector.rb +25 -0
- data/app/countries/atlas_engine/pl/address_importer/corrections/open_address/empty_street_corrector.rb +32 -0
- data/app/countries/atlas_engine/pl/address_validation/exclusions/placeholder_postal_code.rb +35 -0
- data/app/countries/atlas_engine/pl/address_validation/exclusions/rural_address.rb +42 -0
- data/app/countries/atlas_engine/pl/country_profile.yml +13 -0
- data/app/countries/atlas_engine/pl/synonyms.yml +13 -0
- data/app/countries/atlas_engine/pl/validation_transcriber/address_parser.rb +36 -1
- data/app/countries/atlas_engine/pt/address_validation/validators/full_address/exclusions/zip.rb +38 -0
- data/app/countries/atlas_engine/pt/country_profile.yml +4 -0
- data/app/countries/atlas_engine/pt/synonyms.yml +12 -0
- data/app/countries/atlas_engine/pt/validation_transcriber/address_parser.rb +75 -0
- data/app/countries/atlas_engine/si/address_importer/open_address/corrections/city_district_corrector.rb +25 -0
- data/app/countries/atlas_engine/si/address_importer/open_address/mapper.rb +19 -0
- data/app/countries/atlas_engine/si/address_validation/exclusions/unknown_city.rb +33 -0
- data/app/countries/atlas_engine/si/country_profile.yml +17 -0
- data/app/countries/atlas_engine/si/synonyms.yml +7 -0
- data/app/countries/atlas_engine/si/validation_transcriber/address_parser.rb +52 -0
- data/app/graphql/atlas_engine/schema.graphql +1 -1
- data/app/lib/atlas_engine/validation_transcriber/address_parser_base.rb +1 -1
- data/app/models/atlas_engine/address_validation/concern_record.rb +6 -1
- data/app/models/atlas_engine/address_validation/es/query_builder.rb +6 -1
- data/app/models/atlas_engine/address_validation/statsd_emitter.rb +6 -2
- data/app/models/atlas_engine/address_validation/token/sequence/comparator.rb +38 -4
- data/app/models/atlas_engine/address_validation/token/sequence/comparison.rb +4 -4
- data/app/models/atlas_engine/address_validation/token/sequence/comparison_policy.rb +33 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb +41 -15
- data/app/models/atlas_engine/address_validation/validators/full_address/building_comparison.rb +33 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/candidate_result.rb +3 -3
- data/app/models/atlas_engine/address_validation/validators/full_address/city_comparison.rb +25 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb +15 -6
- data/app/models/atlas_engine/address_validation/validators/full_address/exclusions/exclusion_base.rb +8 -2
- data/app/models/atlas_engine/address_validation/validators/full_address/field_comparison_base.rb +77 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/province_code_comparison.rb +34 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/relevant_components.rb +34 -12
- data/app/models/atlas_engine/address_validation/validators/full_address/street_comparison.rb +30 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/suggestion_builder.rb +1 -1
- data/app/models/atlas_engine/address_validation/validators/full_address/zip_comparison.rb +37 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/street/building_number_in_address1_or_address2.rb +2 -2
- data/app/models/atlas_engine/country_profile_validation_subset.rb +35 -2
- data/db/data/country_profiles/default.yml +12 -0
- data/lib/atlas_engine/version.rb +1 -1
- data/lib/tasks/atlas_engine/graphql.rake +13 -0
- metadata +35 -6
- data/app/models/atlas_engine/address_validation/validators/full_address/comparison_helper.rb +0 -135
data/app/models/atlas_engine/address_validation/validators/full_address/comparison_helper.rb
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
# typed: true
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module AtlasEngine
|
5
|
-
module AddressValidation
|
6
|
-
module Validators
|
7
|
-
module FullAddress
|
8
|
-
class ComparisonHelper
|
9
|
-
extend T::Sig
|
10
|
-
|
11
|
-
sig { params(address: AbstractAddress, candidate: Candidate, datastore: DatastoreBase).void }
|
12
|
-
def initialize(address:, candidate:, datastore:)
|
13
|
-
@address = address
|
14
|
-
@datastore = datastore
|
15
|
-
@candidate = candidate
|
16
|
-
end
|
17
|
-
|
18
|
-
sig { returns(T.nilable(Token::Sequence::Comparison)) }
|
19
|
-
def street_comparison
|
20
|
-
return @street_comparison if defined?(@street_comparison)
|
21
|
-
|
22
|
-
street_sequences = datastore.fetch_street_sequences
|
23
|
-
candidate_sequences = T.must(candidate.component(:street)).sequences
|
24
|
-
|
25
|
-
@street_comparison = street_sequences.map do |street_sequence|
|
26
|
-
best_comparison(
|
27
|
-
street_sequence,
|
28
|
-
candidate_sequences,
|
29
|
-
)
|
30
|
-
end.min
|
31
|
-
end
|
32
|
-
|
33
|
-
sig { returns(T.nilable(Token::Sequence::Comparison)) }
|
34
|
-
def city_comparison
|
35
|
-
return @city_comparison if defined?(@city_comparison)
|
36
|
-
|
37
|
-
@city_comparison = best_comparison(
|
38
|
-
datastore.fetch_city_sequence,
|
39
|
-
T.must(candidate.component(:city)).sequences,
|
40
|
-
)
|
41
|
-
end
|
42
|
-
|
43
|
-
sig { returns(T.nilable(Token::Sequence::Comparison)) }
|
44
|
-
def province_code_comparison
|
45
|
-
return @province_code_comparison if defined?(@province_code_comparison)
|
46
|
-
|
47
|
-
normalized_session_province_code = ValidationTranscriber::ProvinceCodeNormalizer.normalize(
|
48
|
-
country_code: address.country_code,
|
49
|
-
province_code: address.province_code,
|
50
|
-
)
|
51
|
-
normalized_candidate_province_code = ValidationTranscriber::ProvinceCodeNormalizer.normalize(
|
52
|
-
country_code: T.must(candidate.component(:country_code)).value,
|
53
|
-
province_code: T.must(candidate.component(:province_code)).value,
|
54
|
-
)
|
55
|
-
|
56
|
-
@province_code_comparison = best_comparison(
|
57
|
-
Token::Sequence.from_string(normalized_session_province_code),
|
58
|
-
[Token::Sequence.from_string(normalized_candidate_province_code)],
|
59
|
-
)
|
60
|
-
end
|
61
|
-
|
62
|
-
sig { returns(T.nilable(Token::Sequence::Comparison)) }
|
63
|
-
def zip_comparison
|
64
|
-
return @zip_comparison if defined?(@zip_comparison)
|
65
|
-
|
66
|
-
candidate.component(:zip)&.value = PostalCodeMatcher.new(
|
67
|
-
T.must(address.country_code),
|
68
|
-
T.must(address.zip),
|
69
|
-
candidate.component(:zip)&.value,
|
70
|
-
).truncate
|
71
|
-
|
72
|
-
normalized_zip = ValidationTranscriber::ZipNormalizer.normalize(
|
73
|
-
country_code: address.country_code, zip: address.zip,
|
74
|
-
)
|
75
|
-
zip_sequence = Token::Sequence.from_string(normalized_zip)
|
76
|
-
@zip_comparison = best_comparison(
|
77
|
-
zip_sequence,
|
78
|
-
T.must(candidate.component(:zip)).sequences,
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
sig { returns(NumberComparison) }
|
83
|
-
def building_comparison
|
84
|
-
@building_comparison ||= NumberComparison.new(
|
85
|
-
numbers: datastore.parsings.potential_building_numbers,
|
86
|
-
candidate_ranges: building_ranges_from_candidate(candidate),
|
87
|
-
)
|
88
|
-
end
|
89
|
-
|
90
|
-
private
|
91
|
-
|
92
|
-
sig { returns(AbstractAddress) }
|
93
|
-
attr_reader :address
|
94
|
-
|
95
|
-
sig { returns(DatastoreBase) }
|
96
|
-
attr_reader :datastore
|
97
|
-
|
98
|
-
sig { returns(Candidate) }
|
99
|
-
attr_reader :candidate
|
100
|
-
|
101
|
-
sig do
|
102
|
-
params(
|
103
|
-
sequence: Token::Sequence,
|
104
|
-
component_sequences: T::Array[Token::Sequence],
|
105
|
-
).returns(T.nilable(Token::Sequence::Comparison))
|
106
|
-
end
|
107
|
-
def best_comparison(
|
108
|
-
sequence,
|
109
|
-
component_sequences
|
110
|
-
)
|
111
|
-
component_sequences.map do |component_sequence|
|
112
|
-
Token::Sequence::Comparator.new(
|
113
|
-
left_sequence: sequence,
|
114
|
-
right_sequence: component_sequence,
|
115
|
-
).compare
|
116
|
-
end.min_by.with_index do |comparison, index|
|
117
|
-
# ruby's `min` and `sort` methods are not stable
|
118
|
-
# so we need to prefer the leftmost comparison when two comparisons are equivalent
|
119
|
-
[comparison, index]
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
sig { params(candidate: Candidate).returns(T::Array[AddressNumberRange]) }
|
124
|
-
def building_ranges_from_candidate(candidate)
|
125
|
-
building_and_unit_ranges = candidate.component(:building_and_unit_ranges)&.value
|
126
|
-
return [] if building_and_unit_ranges.blank?
|
127
|
-
|
128
|
-
building_ranges = JSON.parse(building_and_unit_ranges).keys
|
129
|
-
building_ranges.map { |building_range| AddressNumberRange.new(range_string: building_range) }
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|