atlas_engine 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +123 -0
- data/Rakefile +20 -0
- data/app/assets/config/atlas_engine_manifest.js +3 -0
- data/app/assets/stylesheets/atlas_engine/application.css +15 -0
- data/app/concerns/atlas_engine/handles_blob.rb +26 -0
- data/app/concerns/atlas_engine/handles_interruption.rb +22 -0
- data/app/controllers/atlas_engine/application_controller.rb +7 -0
- data/app/controllers/atlas_engine/connectivity_controller.rb +21 -0
- data/app/controllers/atlas_engine/country_imports_controller.rb +73 -0
- data/app/controllers/atlas_engine/graphql_controller.rb +59 -0
- data/app/countries/atlas_engine/ar/country_profile.yml +9 -0
- data/app/countries/atlas_engine/at/address_importer/corrections/open_address/city_corrector.rb +23 -0
- data/app/countries/atlas_engine/at/country_profile.yml +24 -0
- data/app/countries/atlas_engine/at/index_configuration.yml +63 -0
- data/app/countries/atlas_engine/at/synonyms.yml +6 -0
- data/app/countries/atlas_engine/at/validation_transcriber/address_parser.rb +58 -0
- data/app/countries/atlas_engine/au/address_importer/open_address/filter.rb +26 -0
- data/app/countries/atlas_engine/au/address_importer/open_address/mapper.rb +41 -0
- data/app/countries/atlas_engine/au/country_profile.yml +13 -0
- data/app/countries/atlas_engine/au/synonyms.yml +209 -0
- data/app/countries/atlas_engine/au/validation_transcriber/address_parser.rb +121 -0
- data/app/countries/atlas_engine/be/country_profile.yml +12 -0
- data/app/countries/atlas_engine/bm/address_importer/corrections/open_address/city_alias_corrector.rb +38 -0
- data/app/countries/atlas_engine/bm/address_importer/open_address/mapper.rb +40 -0
- data/app/countries/atlas_engine/bm/country_profile.yml +12 -0
- data/app/countries/atlas_engine/br/country_profile.yml +4 -0
- data/app/countries/atlas_engine/ca/country_profile.yml +7 -0
- data/app/countries/atlas_engine/ca/synonyms.yml +1615 -0
- data/app/countries/atlas_engine/ch/address_importer/corrections/open_address/city_corrector.rb +29 -0
- data/app/countries/atlas_engine/ch/address_importer/corrections/open_address/locale_corrector.rb +74 -0
- data/app/countries/atlas_engine/ch/address_importer/open_address/mapper.rb +40 -0
- data/app/countries/atlas_engine/ch/country_profile.yml +15 -0
- data/app/countries/atlas_engine/ch/locales/de/country_profile.yml +15 -0
- data/app/countries/atlas_engine/ch/locales/de/index_configuration.yml +63 -0
- data/app/countries/atlas_engine/ch/locales/de/synonyms.yml +7 -0
- data/app/countries/atlas_engine/ch/locales/fr/synonyms.yml +21 -0
- data/app/countries/atlas_engine/cz/country_profile.yml +6 -0
- data/app/countries/atlas_engine/de/country_profile.yml +19 -0
- data/app/countries/atlas_engine/de/index_configuration.yml +64 -0
- data/app/countries/atlas_engine/de/synonyms.yml +2 -0
- data/app/countries/atlas_engine/de/validation_transcriber/address_parser.rb +19 -0
- data/app/countries/atlas_engine/dk/country_profile.yml +6 -0
- data/app/countries/atlas_engine/dk/synonyms.yml +3 -0
- data/app/countries/atlas_engine/dk/validation_transcriber/address_parser.rb +21 -0
- data/app/countries/atlas_engine/fo/country_profile.yml +5 -0
- data/app/countries/atlas_engine/fr/address_importer/corrections/open_address/city_corrector.rb +28 -0
- data/app/countries/atlas_engine/fr/country_profile.yml +13 -0
- data/app/countries/atlas_engine/fr/synonyms.yml +21 -0
- data/app/countries/atlas_engine/fr/validation_transcriber/address_parser.rb +34 -0
- data/app/countries/atlas_engine/gb/address_validation/es/query_builder.rb +98 -0
- data/app/countries/atlas_engine/gb/country_profile.yml +10 -0
- data/app/countries/atlas_engine/gb/validation_transcriber/full_address_parser.rb +164 -0
- data/app/countries/atlas_engine/gb/validation_transcriber/parsed_address.rb +120 -0
- data/app/countries/atlas_engine/gg/address_validation/validators/full_address/restrictions/unsupported_city.rb +39 -0
- data/app/countries/atlas_engine/gg/country_profile.yml +7 -0
- data/app/countries/atlas_engine/ie/country_profile.yml +3 -0
- data/app/countries/atlas_engine/it/address_importer/corrections/open_address/city_corrector.rb +27 -0
- data/app/countries/atlas_engine/it/address_importer/corrections/open_address/province_corrector.rb +29 -0
- data/app/countries/atlas_engine/it/address_importer/open_address/mapper.rb +42 -0
- data/app/countries/atlas_engine/it/country_profile.yml +11 -0
- data/app/countries/atlas_engine/jp/address_validation/es/data_mapper.rb +63 -0
- data/app/countries/atlas_engine/jp/country_profile.yml +6 -0
- data/app/countries/atlas_engine/kr/address_importer/open_address/mapper.rb +41 -0
- data/app/countries/atlas_engine/kr/country_profile.yml +11 -0
- data/app/countries/atlas_engine/li/address_importer/corrections/open_address/city_corrector.rb +25 -0
- data/app/countries/atlas_engine/li/country_profile.yml +21 -0
- data/app/countries/atlas_engine/li/index_configuration.yml +63 -0
- data/app/countries/atlas_engine/li/synonyms.yml +6 -0
- data/app/countries/atlas_engine/lt/country_profile.yml +6 -0
- data/app/countries/atlas_engine/lt/synonyms.yml +7 -0
- data/app/countries/atlas_engine/lt/validation_transcriber/address_parser.rb +24 -0
- data/app/countries/atlas_engine/lu/address_importer/corrections/open_address/locale_corrector.rb +54 -0
- data/app/countries/atlas_engine/lu/country_profile.yml +12 -0
- data/app/countries/atlas_engine/nl/address_importer/corrections/open_address/city_corrector.rb +25 -0
- data/app/countries/atlas_engine/nl/country_profile.yml +18 -0
- data/app/countries/atlas_engine/nl/index_configuration.yml +52 -0
- data/app/countries/atlas_engine/nl/synonyms.yml +92 -0
- data/app/countries/atlas_engine/nl/validation_transcriber/address_parser.rb +85 -0
- data/app/countries/atlas_engine/no/country_profile.yml +5 -0
- data/app/countries/atlas_engine/nz/country_profile.yml +3 -0
- data/app/countries/atlas_engine/pl/country_profile.yml +5 -0
- data/app/countries/atlas_engine/pl/validation_transcriber/address_parser.rb +19 -0
- data/app/countries/atlas_engine/pt/address_importer/corrections/open_address/city_corrector.rb +32 -0
- data/app/countries/atlas_engine/pt/address_importer/open_address/mapper.rb +39 -0
- data/app/countries/atlas_engine/pt/country_profile.yml +10 -0
- data/app/countries/atlas_engine/pt/synonyms.yml +7 -0
- data/app/countries/atlas_engine/sa/country_profile.yml +10 -0
- data/app/countries/atlas_engine/se/country_profile.yml +5 -0
- data/app/countries/atlas_engine/tt/address_importer/open_address/mapper.rb +38 -0
- data/app/countries/atlas_engine/tt/country_profile.yml +7 -0
- data/app/countries/atlas_engine/us/country_profile.yml +12 -0
- data/app/countries/atlas_engine/us/synonyms.yml +350 -0
- data/app/graphql/atlas_engine/errors/locale_unsupported_error.rb +17 -0
- data/app/graphql/atlas_engine/schema.graphql +1293 -0
- data/app/graphql/atlas_engine/schema.rb +23 -0
- data/app/graphql/atlas_engine/types/address_validation/address_input.rb +51 -0
- data/app/graphql/atlas_engine/types/address_validation/concern_type.rb +20 -0
- data/app/graphql/atlas_engine/types/address_validation/enums/concern_enum.rb +15 -0
- data/app/graphql/atlas_engine/types/address_validation/field_type.rb +15 -0
- data/app/graphql/atlas_engine/types/address_validation/suggestion_type.rb +21 -0
- data/app/graphql/atlas_engine/types/base_argument.rb +9 -0
- data/app/graphql/atlas_engine/types/base_enum.rb +9 -0
- data/app/graphql/atlas_engine/types/base_field.rb +10 -0
- data/app/graphql/atlas_engine/types/base_input_object.rb +9 -0
- data/app/graphql/atlas_engine/types/base_interface.rb +10 -0
- data/app/graphql/atlas_engine/types/base_object.rb +9 -0
- data/app/graphql/atlas_engine/types/base_scalar.rb +9 -0
- data/app/graphql/atlas_engine/types/base_union.rb +9 -0
- data/app/graphql/atlas_engine/types/matching_strategy_type.rb +12 -0
- data/app/graphql/atlas_engine/types/mutation_type.rb +9 -0
- data/app/graphql/atlas_engine/types/query_type.rb +61 -0
- data/app/graphql/atlas_engine/types/validation_supported_country.rb +12 -0
- data/app/graphql/atlas_engine/types/validation_type.rb +22 -0
- data/app/helpers/atlas_engine/address_importer/import_log_helper.rb +66 -0
- data/app/helpers/atlas_engine/application_helper.rb +7 -0
- data/app/helpers/atlas_engine/locale_format_helper.rb +40 -0
- data/app/helpers/atlas_engine/log_base.rb +32 -0
- data/app/helpers/atlas_engine/log_helper.rb +24 -0
- data/app/helpers/atlas_engine/metrics_helper.rb +25 -0
- data/app/jobs/atlas_engine/address_importer/clear_records_job.rb +39 -0
- data/app/jobs/atlas_engine/address_importer/open_address/geo_json_import_job.rb +212 -0
- data/app/jobs/atlas_engine/address_importer/open_address/geo_json_import_launcher_job.rb +67 -0
- data/app/jobs/atlas_engine/address_importer/open_address/prepares_geo_json_file.rb +41 -0
- data/app/jobs/atlas_engine/address_importer/resumable_import_job.rb +49 -0
- data/app/jobs/atlas_engine/address_importer/street_backfill_job.rb +63 -0
- data/app/jobs/atlas_engine/application_job.rb +10 -0
- data/app/jobs/atlas_engine/concerns/address_importer/handles_errors.rb +43 -0
- data/app/lib/atlas_engine/concern_formatter.rb +40 -0
- data/app/lib/atlas_engine/restrictions/base.rb +20 -0
- data/app/lib/atlas_engine/restrictions/unsupported_script.rb +31 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parser_base.rb +201 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parser_factory.rb +27 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parser_north_america.rb +39 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parser_oceanic.rb +17 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parser_preprocessor.rb +132 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parsing_helper.rb +38 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parsings.rb +54 -0
- data/app/lib/atlas_engine/validation_transcriber/constants.rb +50 -0
- data/app/lib/atlas_engine/validation_transcriber/english_street_parser.rb +59 -0
- data/app/lib/atlas_engine/validation_transcriber/formatter.rb +46 -0
- data/app/lib/atlas_engine/validation_transcriber/french_street_parser.rb +50 -0
- data/app/lib/atlas_engine/validation_transcriber/province_code_normalizer.rb +45 -0
- data/app/lib/atlas_engine/validation_transcriber/street_parser.rb +18 -0
- data/app/lib/atlas_engine/validation_transcriber/zip_normalizer.rb +23 -0
- data/app/mailers/atlas_engine/application_mailer.rb +9 -0
- data/app/models/atlas_engine/address_importer/corrections/corrector.rb +33 -0
- data/app/models/atlas_engine/address_importer/import_events_notifier/base.rb +35 -0
- data/app/models/atlas_engine/address_importer/import_events_notifier/notifier.rb +26 -0
- data/app/models/atlas_engine/address_importer/open_address/default_mapper.rb +46 -0
- data/app/models/atlas_engine/address_importer/open_address/feature_helper.rb +110 -0
- data/app/models/atlas_engine/address_importer/open_address/filter.rb +17 -0
- data/app/models/atlas_engine/address_importer/open_address/loader.rb +27 -0
- data/app/models/atlas_engine/address_importer/open_address/transformer.rb +39 -0
- data/app/models/atlas_engine/address_importer/open_address.rb +10 -0
- data/app/models/atlas_engine/address_importer/validation/base_validator.rb +86 -0
- data/app/models/atlas_engine/address_importer/validation/default_validator.rb +27 -0
- data/app/models/atlas_engine/address_importer/validation/field_validations/city.rb +47 -0
- data/app/models/atlas_engine/address_importer/validation/field_validations/interface.rb +29 -0
- data/app/models/atlas_engine/address_importer/validation/field_validations/province.rb +73 -0
- data/app/models/atlas_engine/address_importer/validation/field_validations/zip.rb +84 -0
- data/app/models/atlas_engine/address_importer/validation/validator.rb +17 -0
- data/app/models/atlas_engine/address_importer/validation/wrapper.rb +70 -0
- data/app/models/atlas_engine/address_number.rb +36 -0
- data/app/models/atlas_engine/address_number_range.rb +200 -0
- data/app/models/atlas_engine/address_validation/abstract_address.rb +49 -0
- data/app/models/atlas_engine/address_validation/address.rb +47 -0
- data/app/models/atlas_engine/address_validation/candidate.rb +109 -0
- data/app/models/atlas_engine/address_validation/candidate_tuple.rb +15 -0
- data/app/models/atlas_engine/address_validation/concern.rb +74 -0
- data/app/models/atlas_engine/address_validation/concern_producer.rb +19 -0
- data/app/models/atlas_engine/address_validation/concern_queue.rb +20 -0
- data/app/models/atlas_engine/address_validation/concern_record.rb +122 -0
- data/app/models/atlas_engine/address_validation/datastore_base.rb +27 -0
- data/app/models/atlas_engine/address_validation/errors.rb +13 -0
- data/app/models/atlas_engine/address_validation/es/candidate_selector.rb +70 -0
- data/app/models/atlas_engine/address_validation/es/data_mappers/decompounding_data_mapper.rb +39 -0
- data/app/models/atlas_engine/address_validation/es/data_mappers/default_data_mapper.rb +110 -0
- data/app/models/atlas_engine/address_validation/es/datastore.rb +229 -0
- data/app/models/atlas_engine/address_validation/es/default_query_builder.rb +30 -0
- data/app/models/atlas_engine/address_validation/es/query_builder.rb +160 -0
- data/app/models/atlas_engine/address_validation/es/term_vectors.rb +78 -0
- data/app/models/atlas_engine/address_validation/es/validators/full_address.rb +123 -0
- data/app/models/atlas_engine/address_validation/es/validators/full_address_street.rb +18 -0
- data/app/models/atlas_engine/address_validation/es/validators/restriction_evaluator.rb +37 -0
- data/app/models/atlas_engine/address_validation/field.rb +30 -0
- data/app/models/atlas_engine/address_validation/full_address_validator_base.rb +27 -0
- data/app/models/atlas_engine/address_validation/log_emitter.rb +66 -0
- data/app/models/atlas_engine/address_validation/matching_strategies.rb +16 -0
- data/app/models/atlas_engine/address_validation/normalizer.rb +38 -0
- data/app/models/atlas_engine/address_validation/predicate_pipeline.rb +80 -0
- data/app/models/atlas_engine/address_validation/request.rb +12 -0
- data/app/models/atlas_engine/address_validation/result.rb +154 -0
- data/app/models/atlas_engine/address_validation/runs_validation.rb +16 -0
- data/app/models/atlas_engine/address_validation/session.rb +47 -0
- data/app/models/atlas_engine/address_validation/statsd_emitter.rb +72 -0
- data/app/models/atlas_engine/address_validation/strategies.rb +10 -0
- data/app/models/atlas_engine/address_validation/suggestion.rb +97 -0
- data/app/models/atlas_engine/address_validation/token/comparator.rb +44 -0
- data/app/models/atlas_engine/address_validation/token/comparison.rb +76 -0
- data/app/models/atlas_engine/address_validation/token/sequence/comparator.rb +158 -0
- data/app/models/atlas_engine/address_validation/token/sequence/comparison.rb +166 -0
- data/app/models/atlas_engine/address_validation/token/sequence.rb +147 -0
- data/app/models/atlas_engine/address_validation/token/synonyms.rb +77 -0
- data/app/models/atlas_engine/address_validation/token.rb +113 -0
- data/app/models/atlas_engine/address_validation/validator.rb +147 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb +97 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/candidate_result.rb +164 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/candidate_result_base.rb +46 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/comparison_helper.rb +135 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/components_to_validate.rb +88 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb +127 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/exclusions/exclusion_base.rb +23 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/invalid_zip_concern_builder.rb +42 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/invalid_zip_for_country_concern.rb +37 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/invalid_zip_for_province_concern.rb +37 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/no_candidate_result.rb +26 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/number_comparison.rb +31 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/postal_code_matcher.rb +60 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/result_updater.rb +42 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/suggestion_builder.rb +140 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/unknown_address_concern.rb +30 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/unknown_province_concern.rb +38 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/unknown_zip_for_address_concern.rb +32 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/unmatched_field_concern.rb +84 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/unsupported_script_result.rb +22 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/cache.rb +38 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/city/present.rb +36 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/country/exists.rb +34 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/country/valid_for_zip.rb +60 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/no_emojis.rb +38 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/no_html_tags.rb +39 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/no_url.rb +38 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/not_exceed_max_length.rb +34 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/not_exceed_max_token_count.rb +63 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/phone/valid.rb +41 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/predicate.rb +37 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/province/exists.rb +43 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/province/valid_for_country.rb +48 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/street/building_number_in_address1.rb +45 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/street/building_number_in_address1_or_address2.rb +43 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/street/present.rb +35 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/zip/present.rb +58 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/zip/valid_for_country.rb +45 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/zip/valid_for_province.rb +55 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/zip/zip_base.rb +25 -0
- data/app/models/atlas_engine/address_validation/zip_truncator.rb +32 -0
- data/app/models/atlas_engine/application_record.rb +8 -0
- data/app/models/atlas_engine/coded_error.rb +18 -0
- data/app/models/atlas_engine/coded_errors.rb +17 -0
- data/app/models/atlas_engine/country_import.rb +44 -0
- data/app/models/atlas_engine/country_profile.rb +270 -0
- data/app/models/atlas_engine/country_profile_ingestion_subset.rb +42 -0
- data/app/models/atlas_engine/country_profile_subset_base.rb +22 -0
- data/app/models/atlas_engine/country_profile_validation_subset.rb +48 -0
- data/app/models/atlas_engine/country_repository.rb +110 -0
- data/app/models/atlas_engine/elasticsearch/client.rb +116 -0
- data/app/models/atlas_engine/elasticsearch/client_interface.rb +89 -0
- data/app/models/atlas_engine/elasticsearch/repository.rb +246 -0
- data/app/models/atlas_engine/elasticsearch/repository_interface.rb +82 -0
- data/app/models/atlas_engine/elasticsearch/response.rb +20 -0
- data/app/models/atlas_engine/event.rb +12 -0
- data/app/models/atlas_engine/field_decompounder.rb +36 -0
- data/app/models/atlas_engine/index_configuration_factory.rb +188 -0
- data/app/models/atlas_engine/post_address.rb +114 -0
- data/app/models/atlas_engine/post_address_importer.rb +34 -0
- data/app/models/atlas_engine/services/service_helper.rb +21 -0
- data/app/models/atlas_engine/services/validation.rb +65 -0
- data/app/models/atlas_engine/services/validation_eligibility.rb +18 -0
- data/app/models/atlas_engine/street.rb +34 -0
- data/app/tasks/maintenance/atlas_engine/elasticsearch_index_create_task.rb +106 -0
- data/app/tasks/maintenance/atlas_engine/geo_json_import_task.rb +29 -0
- data/app/views/atlas_engine/connectivity/index.html.erb +50 -0
- data/app/views/atlas_engine/country_imports/index.html.erb +49 -0
- data/app/views/atlas_engine/country_imports/show.html.erb +73 -0
- data/app/views/layouts/atlas_engine/application.html.erb +15 -0
- data/config/initializers/1.ruby_patches.rb +18 -0
- data/config/initializers/sorbet.rb +5 -0
- data/config/initializers/worldwide.rb +5 -0
- data/config/locales/internal/en.yml +14 -0
- data/config/routes.rb +17 -0
- data/db/data/address_synonyms/index_configurations/default.yml +141 -0
- data/db/data/country_profiles/default.yml +23 -0
- data/db/data/transcriber.yml +760 -0
- data/db/data/validation_pipelines/es.yml +58 -0
- data/db/data/validation_pipelines/es_street.yml +58 -0
- data/db/data/validation_pipelines/local.yml +60 -0
- data/db/migrate/20230919173037_create_atlas_engine_post_addresses.rb +25 -0
- data/db/migrate/20231117142735_add_building_and_unit_ranges_column.rb +7 -0
- data/db/migrate/20231117143536_create_atlas_engine_country_imports.rb +11 -0
- data/db/migrate/20231117145844_create_atlas_engine_events_table.rb +13 -0
- data/db/migrate/20231123153554_add_unique_index_to_atlas_engine_post_addresses.rb +14 -0
- data/db/migrate/20231123154658_add_index_to_post_addresses_on_source_id_locale_country_code.rb +12 -0
- data/lib/atlas_engine/engine.rb +10 -0
- data/lib/atlas_engine/version.rb +6 -0
- data/lib/atlas_engine.rb +66 -0
- data/lib/tasks/atlas_engine/address_importer.rake +20 -0
- metadata +553 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module AddressValidation
|
6
|
+
class Concern
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
TYPES = T.let(
|
10
|
+
{
|
11
|
+
warning: "warning",
|
12
|
+
error: "error",
|
13
|
+
}.freeze,
|
14
|
+
T::Hash[Symbol, String],
|
15
|
+
)
|
16
|
+
|
17
|
+
sig { returns(Symbol) }
|
18
|
+
attr_reader :code
|
19
|
+
|
20
|
+
sig { returns(String) }
|
21
|
+
attr_reader :message
|
22
|
+
|
23
|
+
sig { returns(String) }
|
24
|
+
attr_reader :type
|
25
|
+
|
26
|
+
sig { returns(Integer) }
|
27
|
+
attr_reader :type_level
|
28
|
+
|
29
|
+
sig { returns(T::Array[String]) }
|
30
|
+
attr_reader :suggestion_ids
|
31
|
+
|
32
|
+
sig { returns(T::Array[Symbol]) }
|
33
|
+
attr_reader :field_names
|
34
|
+
|
35
|
+
sig { returns(T.nilable(Suggestion)) }
|
36
|
+
attr_reader :suggestion
|
37
|
+
|
38
|
+
alias_attribute :component_names, :field_names
|
39
|
+
|
40
|
+
sig do
|
41
|
+
params(
|
42
|
+
code: Symbol,
|
43
|
+
message: String,
|
44
|
+
type: String,
|
45
|
+
type_level: Integer,
|
46
|
+
suggestion_ids: T::Array[String],
|
47
|
+
field_names: T::Array[Symbol],
|
48
|
+
suggestion: T.nilable(Suggestion),
|
49
|
+
).void
|
50
|
+
end
|
51
|
+
def initialize(code:, message:, type:, type_level:, suggestion_ids:, field_names:, suggestion: nil)
|
52
|
+
@code = code
|
53
|
+
@type = type
|
54
|
+
@type_level = type_level
|
55
|
+
@suggestion_ids = suggestion_ids
|
56
|
+
@field_names = field_names
|
57
|
+
@message = message
|
58
|
+
@suggestion = T.let(suggestion, T.nilable(Suggestion))
|
59
|
+
end
|
60
|
+
|
61
|
+
sig { returns(T::Hash[Symbol, T.untyped]) }
|
62
|
+
def attributes
|
63
|
+
{
|
64
|
+
field_names: field_names,
|
65
|
+
message: message,
|
66
|
+
code: code,
|
67
|
+
type: type,
|
68
|
+
type_level: type_level,
|
69
|
+
suggestion_ids: suggestion_ids,
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module AddressValidation
|
6
|
+
class ConcernProducer
|
7
|
+
class << self
|
8
|
+
extend T::Sig
|
9
|
+
|
10
|
+
sig { params(result: Result, context: Hash).void }
|
11
|
+
def add(result, context = {})
|
12
|
+
return if result.concerns.empty?
|
13
|
+
|
14
|
+
ConcernQueue.instance.queue.push(ConcernRecord.from_result(result, context))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module AddressValidation
|
6
|
+
class ConcernQueue
|
7
|
+
extend T::Sig
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
sig { returns(Queue) }
|
11
|
+
attr_reader :queue
|
12
|
+
|
13
|
+
sig { void }
|
14
|
+
def initialize
|
15
|
+
super
|
16
|
+
@queue = T.let(Queue.new, Queue)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module AddressValidation
|
6
|
+
class ConcernRecord
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
sig { returns(String) }
|
10
|
+
attr_reader :address1
|
11
|
+
|
12
|
+
sig { returns(String) }
|
13
|
+
attr_reader :address2
|
14
|
+
|
15
|
+
sig { returns(String) }
|
16
|
+
attr_reader :city
|
17
|
+
|
18
|
+
sig { returns(String) }
|
19
|
+
attr_reader :country_code
|
20
|
+
|
21
|
+
sig { returns(String) }
|
22
|
+
attr_reader :province_code
|
23
|
+
|
24
|
+
sig { returns(String) }
|
25
|
+
attr_reader :zip
|
26
|
+
|
27
|
+
sig { returns(String) }
|
28
|
+
attr_reader :phone
|
29
|
+
|
30
|
+
sig { returns(Result) }
|
31
|
+
attr_reader :result
|
32
|
+
|
33
|
+
sig { returns(T.nilable(String)) }
|
34
|
+
attr_reader :version
|
35
|
+
|
36
|
+
sig { returns(T.nilable(String)) }
|
37
|
+
attr_reader :request_id
|
38
|
+
|
39
|
+
sig { returns(T.nilable(String)) }
|
40
|
+
attr_reader :client_request_id
|
41
|
+
|
42
|
+
sig { returns(Time) }
|
43
|
+
attr_reader :timestamp
|
44
|
+
|
45
|
+
sig { returns(String) }
|
46
|
+
attr_reader :origin
|
47
|
+
|
48
|
+
class << self
|
49
|
+
extend T::Sig
|
50
|
+
|
51
|
+
sig { params(result: Result, context: T::Hash[T.untyped, T.untyped]).returns(ConcernRecord) }
|
52
|
+
def from_result(result, context = {})
|
53
|
+
new(
|
54
|
+
**T.unsafe(
|
55
|
+
{
|
56
|
+
result: result,
|
57
|
+
**result.address,
|
58
|
+
**context.except(:client_request_id),
|
59
|
+
},
|
60
|
+
),
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
sig do
|
66
|
+
params(
|
67
|
+
request_id: T.nilable(String),
|
68
|
+
timestamp: Time,
|
69
|
+
origin: String,
|
70
|
+
address1: String,
|
71
|
+
address2: String,
|
72
|
+
city: String,
|
73
|
+
province_code: String,
|
74
|
+
country_code: String,
|
75
|
+
zip: String,
|
76
|
+
phone: String,
|
77
|
+
result: Result,
|
78
|
+
).void
|
79
|
+
end
|
80
|
+
def initialize(
|
81
|
+
request_id: nil,
|
82
|
+
timestamp: Time.zone.now,
|
83
|
+
origin: "",
|
84
|
+
address1: "",
|
85
|
+
address2: "",
|
86
|
+
city: "",
|
87
|
+
province_code: "",
|
88
|
+
country_code: "",
|
89
|
+
zip: "",
|
90
|
+
phone: "",
|
91
|
+
result: Result.new
|
92
|
+
)
|
93
|
+
@request_id = request_id
|
94
|
+
@client_request_id = T.let(result.client_request_id, T.nilable(String))
|
95
|
+
@timestamp = timestamp
|
96
|
+
@origin = origin
|
97
|
+
@address1 = address1
|
98
|
+
@address2 = address2
|
99
|
+
@city = city
|
100
|
+
@province_code = province_code
|
101
|
+
@country_code = country_code
|
102
|
+
@zip = zip
|
103
|
+
@phone = phone
|
104
|
+
@result = result
|
105
|
+
@version = T.let(Rails.configuration.version, T.nilable(String))
|
106
|
+
end
|
107
|
+
|
108
|
+
sig { returns(T::Hash[Symbol, String]) }
|
109
|
+
def address_attributes
|
110
|
+
{
|
111
|
+
address1: address1,
|
112
|
+
address2: address2,
|
113
|
+
city: city,
|
114
|
+
province_code: province_code,
|
115
|
+
zip: zip,
|
116
|
+
country_code: country_code,
|
117
|
+
phone: phone,
|
118
|
+
}
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module AddressValidation
|
6
|
+
module DatastoreBase
|
7
|
+
extend T::Sig
|
8
|
+
extend T::Helpers
|
9
|
+
interface!
|
10
|
+
|
11
|
+
sig { abstract.returns(Token::Sequence) }
|
12
|
+
def fetch_city_sequence; end
|
13
|
+
|
14
|
+
sig { abstract.returns(T::Array[Token::Sequence]) }
|
15
|
+
def fetch_street_sequences; end
|
16
|
+
|
17
|
+
sig { abstract.returns(T::Array[Candidate]) }
|
18
|
+
def fetch_full_address_candidates; end
|
19
|
+
|
20
|
+
sig { abstract.returns(T::Hash[T.untyped, T.untyped]) }
|
21
|
+
def validation_response; end
|
22
|
+
|
23
|
+
sig { abstract.returns(ValidationTranscriber::AddressParsings) }
|
24
|
+
def parsings; end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module AddressValidation
|
6
|
+
class Errors < AtlasEngine::CodedErrors
|
7
|
+
HTTP_ISSUE = T.let(error(:http_issue, "There was an issue processing the request."), CodedError)
|
8
|
+
REQUEST_ISSUE = T.let(error(:request_issue, "There is an error with the given request."), CodedError)
|
9
|
+
MISSING_PARAMETER =
|
10
|
+
T.let(error(:missing_parameter, "The given request is missing a required parameter."), CodedError)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module AddressValidation
|
6
|
+
module Es
|
7
|
+
class CandidateSelector
|
8
|
+
include LogHelper
|
9
|
+
extend T::Sig
|
10
|
+
|
11
|
+
sig { params(datastore: DatastoreBase, address: AbstractAddress).void }
|
12
|
+
def initialize(datastore:, address:)
|
13
|
+
@datastore = T.let(datastore, DatastoreBase)
|
14
|
+
@address = T.let(address, AbstractAddress)
|
15
|
+
end
|
16
|
+
|
17
|
+
sig { returns(Concurrent::Promises::Future) }
|
18
|
+
def best_candidate_async
|
19
|
+
Concurrent::Promises.future do
|
20
|
+
best_candidate
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
sig { returns(T.nilable(CandidateTuple)) }
|
25
|
+
def best_candidate
|
26
|
+
street_sequences_future = datastore.fetch_street_sequences_async
|
27
|
+
city_sequences_future = datastore.fetch_city_sequence_async
|
28
|
+
sorted_candidates.first
|
29
|
+
ensure
|
30
|
+
# We want our futures to complete even when we do not consume their value.
|
31
|
+
street_sequences_future&.wait!
|
32
|
+
city_sequences_future&.wait!
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :datastore, :address
|
38
|
+
|
39
|
+
sig { returns(T::Array[CandidateTuple]) }
|
40
|
+
def sorted_candidates
|
41
|
+
sorted_candidate_tuples = datastore.fetch_full_address_candidates
|
42
|
+
.filter_map.with_index(1) do |candidate, position|
|
43
|
+
address_comparison = AtlasEngine::AddressValidation::Validators::FullAddress::AddressComparison.new(
|
44
|
+
address: address,
|
45
|
+
candidate: candidate,
|
46
|
+
datastore: datastore,
|
47
|
+
)
|
48
|
+
tuple = CandidateTuple.new(address_comparison, position, candidate)
|
49
|
+
tuple if tuple.address_comparison.potential_match?
|
50
|
+
end.sort
|
51
|
+
|
52
|
+
emit_sorted_candidates(sorted_candidate_tuples)
|
53
|
+
sorted_candidate_tuples
|
54
|
+
end
|
55
|
+
|
56
|
+
sig { params(sorted_candidate_tuples: T::Array[CandidateTuple]).void }
|
57
|
+
def emit_sorted_candidates(sorted_candidate_tuples)
|
58
|
+
log_info("Sorted candidates:\n #{sorted_candidate_tuples.map { |tuple| tuple.candidate.serialize }}")
|
59
|
+
|
60
|
+
initial_position_top_candidate = sorted_candidate_tuples.first&.position || 0
|
61
|
+
StatsD.distribution(
|
62
|
+
"AddressValidation.query.initial_position_top_candidate",
|
63
|
+
initial_position_top_candidate,
|
64
|
+
tags: { position: initial_position_top_candidate },
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module AddressValidation
|
6
|
+
module Es
|
7
|
+
module DataMappers
|
8
|
+
class DecompoundingDataMapper < DefaultDataMapper
|
9
|
+
sig do
|
10
|
+
override.returns(T::Hash[Symbol, T.untyped])
|
11
|
+
end
|
12
|
+
def map_data
|
13
|
+
super.tap do |data|
|
14
|
+
decompounded_fields.each do |field|
|
15
|
+
data["#{field}_decompounded".to_sym] = decompound(field: field, value: data[field])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
sig { returns(T::Array[Symbol]) }
|
23
|
+
def decompounded_fields
|
24
|
+
country_profile.attributes.dig("decompounding_patterns").keys.map(&:to_sym)
|
25
|
+
end
|
26
|
+
|
27
|
+
sig { params(field: Symbol, value: T.nilable(String)).returns(T.nilable(String)) }
|
28
|
+
def decompound(field:, value:)
|
29
|
+
FieldDecompounder.new(
|
30
|
+
field: field,
|
31
|
+
value: value,
|
32
|
+
country_profile: country_profile,
|
33
|
+
).call
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module AddressValidation
|
6
|
+
module Es
|
7
|
+
module DataMappers
|
8
|
+
class DefaultDataMapper
|
9
|
+
extend T::Sig
|
10
|
+
include LogHelper
|
11
|
+
|
12
|
+
sig { returns(CountryRepository::PostAddressData) }
|
13
|
+
attr_reader :post_address
|
14
|
+
|
15
|
+
sig { returns(String) }
|
16
|
+
attr_reader :locale
|
17
|
+
|
18
|
+
sig do
|
19
|
+
params(
|
20
|
+
post_address: CountryRepository::PostAddressData,
|
21
|
+
country_profile: CountryProfile,
|
22
|
+
locale: String,
|
23
|
+
).void
|
24
|
+
end
|
25
|
+
def initialize(post_address:, country_profile:, locale: "")
|
26
|
+
@post_address = post_address
|
27
|
+
@country_profile = country_profile
|
28
|
+
@locale = T.let((locale.empty? ? post_address[:locale] : locale), String)
|
29
|
+
end
|
30
|
+
|
31
|
+
sig do
|
32
|
+
returns(T::Hash[Symbol, T.untyped])
|
33
|
+
end
|
34
|
+
def map_data
|
35
|
+
{}.tap do |data|
|
36
|
+
data.update(
|
37
|
+
post_address
|
38
|
+
.slice(:id, :locale, :country_code, :province_code, :region1, :region2, :region3, :region4)
|
39
|
+
.deep_symbolize_keys,
|
40
|
+
)
|
41
|
+
data[:city_aliases] = city_aliases(post_address[:city])
|
42
|
+
data[:suburb] = post_address[:suburb]
|
43
|
+
data[:zip] = Worldwide::Zip.normalize(
|
44
|
+
country_code: post_address[:country_code],
|
45
|
+
zip: post_address[:zip],
|
46
|
+
)
|
47
|
+
data[:street] = post_address[:street]
|
48
|
+
data[:street_stripped] = street_stripped(post_address[:street])
|
49
|
+
data[:street_decompounded] = nil
|
50
|
+
data[:building_and_unit_ranges] = JSON.generate(post_address[:building_and_unit_ranges])
|
51
|
+
data[:approx_building_ranges] = approx_building_ranges(post_address[:building_and_unit_ranges]&.keys)
|
52
|
+
data.update(
|
53
|
+
post_address.slice(:building_name, :latitude, :longitude).deep_symbolize_keys,
|
54
|
+
)
|
55
|
+
data[:location] = {
|
56
|
+
lat: post_address[:latitude],
|
57
|
+
lon: post_address[:longitude],
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
sig { returns(CountryProfile) }
|
65
|
+
attr_reader :country_profile
|
66
|
+
|
67
|
+
sig { params(cities: T::Array[String]).returns(T::Array[T::Hash[Symbol, String]]) }
|
68
|
+
def city_aliases(cities)
|
69
|
+
cities.map do |city|
|
70
|
+
{
|
71
|
+
alias: city,
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
sig { params(street: T.nilable(String)).returns(T.nilable(String)) }
|
77
|
+
def street_stripped(street)
|
78
|
+
return if street.blank?
|
79
|
+
|
80
|
+
Street.new(street: street).with_stripped_name
|
81
|
+
end
|
82
|
+
|
83
|
+
sig { params(ranges: T.nilable(T::Array[String])).returns(T.nilable(T::Array[T::Hash[String, Integer]])) }
|
84
|
+
def approx_building_ranges(ranges)
|
85
|
+
return unless ranges
|
86
|
+
|
87
|
+
numeric_ranges = ranges.filter_map do |range_str|
|
88
|
+
AddressNumberRange.new(range_string: range_str).approx_numeric_range
|
89
|
+
end
|
90
|
+
merged_ranges = AddressNumberRange.merge_overlapping_ranges(numeric_ranges)
|
91
|
+
merged_ranges.map { |range| es_integer_range(min: range.min, max: range.max) }
|
92
|
+
rescue AddressNumberRange::RangeError => e
|
93
|
+
log_warn("[#{e.class}]: #{e.message}")
|
94
|
+
nil
|
95
|
+
end
|
96
|
+
|
97
|
+
sig { params(min: Integer, max: Integer).returns(T::Hash[String, Integer]) }
|
98
|
+
def es_integer_range(min:, max:)
|
99
|
+
{ "gte" => min, "lte" => max }
|
100
|
+
end
|
101
|
+
|
102
|
+
sig { returns(String) }
|
103
|
+
def locale_language_code
|
104
|
+
Worldwide.locale(code: locale).language_subtag
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|