Data source/LT.CR/data model/record/adresas/mapping/CDQ/transformation

From CDQ
Jump to navigation Jump to search


Part of Hierarchical relation between two concepts of the CDQ Data Model. Data source LT.CR
Mapping source The source of a data model mapping. LT.CR adresasLOCALITY_VALUE, LOCALITY_TYPE, THOROUGHFARE_VALUE, THOROUGHFARE_TYPE, POST_CODE_VALUE, POST_CODE_TYPE, ADMINISTRATIVE_AREA_VALUE, ADMINISTRATIVE_AREA_TYPE
Transformation type A type of a transformation applied to a data model mapping. CUSTOM_TRANSFORMATION"CUSTOM_TRANSFORMATION" is not in the list (UPPER_CASE, LOWER_CASE, CUSTOM) of allowed values for the "Has transformation type" property.
Transformation parameter A transformation parameter is an action proccessed by a data model transformation. n/a
Description Informal and comprehensive human-readable definition of a concept. n/a

Transformation code Any code (in Python, JAVA or other) that will transform values for a given data source attributes.

LOCALITY_VALUE = 'addresses[0].localities[0].value'
LOCALITY_TYPE = 'addresses[0].localities[0].type.technicalKey'
THOROUGHFARE_VALUE = 'addresses[0].thoroughfares[0].value'
THOROUGHFARE_TYPE = "addresses[0].thoroughfares[0].type.technicalKey"
POSTCODE_VALUE = 'addresses[0].postCodes[0].value'
POSTCODE_TYPE = 'addresses[0].postCodes[0].type.technicalKey'
ADMINISTRATIVE_AREA_0_VALUE = 'addresses[0].administrativeAreas[0].value'
ADMINISTRATIVE_AREA_0_TYPE = 'addresses[0].administrativeAreas[0].type.technicalKey'
ADMINISTRATIVE_AREA_1_VALUE = 'addresses[0].administrativeAreas[1].value'

def transform(raw_data):
    result = {}
    splitted_address = raw_data.split(",")

    locality = None
    thoroughfare = None
    postcode = None
    administrative_area_0 = None
    administrative_area_1 = None

    for part in splitted_address:
        part = part.strip()
        if ' sav.' in part:
            administrative_area_0 = part
        elif ' sen.' in part:
            administrative_area_1 = part
        elif any(indicator in part for indicator in [' k.', ' m.', ' mstl.', ' vs.']):
            locality = part
        elif any(indicator in part for indicator in [' g.', ' kel.', ' pr.', ' skv.', ' skg.', ' tak.', ' k.', ' al.', ' pl.', ' a.', ' krant.']):
            thoroughfare = part
        elif part.startswith('LT-'):
            postcode = part
        else:
            locality = part


    if not locality:
        locality = splitted_address[0].strip()
    if not thoroughfare:
        thoroughfare = splitted_address[1].strip()
    if not postcode:
        postcode = splitted_address[-1].strip()

    result[LOCALITY_VALUE] = locality
    result[LOCALITY_TYPE] = "CITY"
    result[THOROUGHFARE_VALUE] = thoroughfare
    result[THOROUGHFARE_TYPE] = "STREET"
    result[POSTCODE_VALUE] = postcode
    result[POSTCODE_TYPE] = "REGULAR"

    if administrative_area_0:
        result[ADMINISTRATIVE_AREA_0_VALUE] = administrative_area_0
        result[ADMINISTRATIVE_AREA_0_TYPE] = "COUNTY"
    if administrative_area_1:
        result[ADMINISTRATIVE_AREA_1_VALUE] = administrative_area_1

    return result