A
A
A1K02020-08-20 10:15:37
Python
A1K0, 2020-08-20 10:15:37

How to parse strings with Python?

How to parse strings with Python? For example, inf comes with the address "Kyiv region, Kyiv, Khreshchatyk st., 50, apt. 8" in fact, this address should be associated with the client's full name in the database. But since a different format was uploaded to the database, it does not search for it in the database, because the address can be written in a different order or without specifying the letters "kv", "house" and so on.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
ScriptKiddo, 2020-08-20
@A1K0

First you need to normalize the addresses in the database. This can be done, for example, using the Yandex
geocoder /geocoder
For example, we are looking for "Moscow, Tverskaya 6"
https://geocode-maps.yandex.ru/1.x/?apikey=%apikey...

Answer

{
  "response": {
    "GeoObjectCollection": {
      "metaDataProperty": {
        "GeocoderResponseMetaData": {
          "request": "Москва,Тверская 6",
          "results": "10",
          "found": "1"
        }
      },
      "featureMember": [
        {
          "GeoObject": {
            "metaDataProperty": {
              "GeocoderMetaData": {
                "precision": "exact",
                "text": "Россия, Москва, Тверская улица, 6с1",
                "kind": "house",
                "Address": {
                  "country_code": "RU",
                  "formatted": "Россия, Москва, Тверская улица, 6с1",
                  "postal_code": "125009",
                  "Components": [
                    {
                      "kind": "country",
                      "name": "Россия"
                    },
                    {
                      "kind": "province",
                      "name": "Центральный федеральный округ"
                    },
                    {
                      "kind": "province",
                      "name": "Москва"
                    },
                    {
                      "kind": "locality",
                      "name": "Москва"
                    },
                    {
                      "kind": "street",
                      "name": "Тверская улица"
                    },
                    {
                      "kind": "house",
                      "name": "6с1"
                    }
                  ]
                },
                "AddressDetails": {
                  "Country": {
                    "AddressLine": "Россия, Москва, Тверская улица, 6с1",
                    "CountryNameCode": "RU",
                    "CountryName": "Россия",
                    "AdministrativeArea": {
                      "AdministrativeAreaName": "Москва",
                      "Locality": {
                        "LocalityName": "Москва",
                        "Thoroughfare": {
                          "ThoroughfareName": "Тверская улица",
                          "Premise": {
                            "PremiseNumber": "6с1",
                            "PostalCode": {
                              "PostalCodeNumber": "125009"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            },
            "name": "Тверская улица, 6с1",
            "description": "Москва, Россия",
            "boundedBy": {
              "Envelope": {
                "lowerCorner": "37.607242 55.757926",
                "upperCorner": "37.615452 55.762556"
              }
            },
            "Point": {
              "pos": "37.611347 55.760241"
            }
          }
        }
      ]
    }
  }
}


Then upload to the database in the desired scheme and search for normalized data
Reply to the address in the question
{
  "response": {
    "GeoObjectCollection": {
      "metaDataProperty": {
        "GeocoderResponseMetaData": {
          "request": "Киевская обл. , г. Киев, ул. Крещатик, дом 50, кв. 8",
          "results": "10",
          "found": "2"
        }
      },
      "featureMember": [
        {
          "GeoObject": {
            "metaDataProperty": {
              "GeocoderMetaData": {
                "precision": "exact",
                "text": "Украина, Киев, улица Крещатик, 50",
                "kind": "house",
                "Address": {
                  "country_code": "UA",
                  "formatted": "Украина, Киев, улица Крещатик, 50",
                  "Components": [
                    {
                      "kind": "country",
                      "name": "Украина"
                    },
                    {
                      "kind": "province",
                      "name": "Киев"
                    },
                    {
                      "kind": "locality",
                      "name": "Киев"
                    },
                    {
                      "kind": "street",
                      "name": "улица Крещатик"
                    },
                    {
                      "kind": "house",
                      "name": "50"
                    }
                  ]
                },
                "AddressDetails": {
                  "Country": {
                    "AddressLine": "Украина, Киев, улица Крещатик, 50",
                    "CountryNameCode": "UA",
                    "CountryName": "Украина",
                    "AdministrativeArea": {
                      "AdministrativeAreaName": "Киев",
                      "Locality": {
                        "LocalityName": "Киев",
                        "Thoroughfare": {
                          "ThoroughfareName": "улица Крещатик",
                          "Premise": {
                            "PremiseNumber": "50"
                          }
                        }
                      }
                    }
                  }
                }
              }
            },
            "name": "улица Крещатик, 50",
            "description": "Киев, Украина",
            "boundedBy": {
              "Envelope": {
                "lowerCorner": "30.516022 50.440632",
                "upperCorner": "30.524232 50.445875"
              }
            },
            "Point": {
              "pos": "30.520127 50.443254"
            }
          }
        },
        {
          "GeoObject": {
            "metaDataProperty": {
              "GeocoderMetaData": {
                "precision": "other",
                "text": "Украина, Киевская область",
                "kind": "province",
                "Address": {
                  "country_code": "UA",
                  "formatted": "Украина, Киевская область",
                  "Components": [
                    {
                      "kind": "country",
                      "name": "Украина"
                    },
                    {
                      "kind": "province",
                      "name": "Киевская область"
                    }
                  ]
                },
                "AddressDetails": {
                  "Country": {
                    "AddressLine": "Украина, Киевская область",
                    "CountryNameCode": "UA",
                    "CountryName": "Украина",
                    "AdministrativeArea": {
                      "AdministrativeAreaName": "Киевская область"
                    }
                  }
                }
              }
            },
            "name": "Киевская область",
            "description": "Украина",
            "boundedBy": {
              "Envelope": {
                "lowerCorner": "29.266411 49.179114",
                "upperCorner": "32.161466 51.554013"
              }
            },
            "Point": {
              "pos": "30.456149 50.29807"
            }
          }
        }
      ]
    }
  }
}

UPD: added an answer to the address from the question.

D
Dimonchik, 2020-08-20
@dimonchik2013

it is possible,
but not by copy-pasting the function, but by understanding the source data and conversion methods
, who will need a tamita parser, and who will need a simple vector distance of the street name from the array of streets in the database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question