Data source/DNB.MASTER.DATA.EXTENDED/data model/organization/primaryAddress/addressRegion/abbreviatedName/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 DNB.MASTER.DATA.EXTENDED
Mapping source The source of a data model mapping. Data source/DNB.MASTER.DATA.EXTENDED/data model/organization/primaryAddress
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.

import re

def transform(raw_data):
    country_code = re.search(r"isoAlpha2Code=(\w+)", raw_data)
    region_code_iso = re.search(r"isoSubDivisionCode=(\w+-\w+)", raw_data)
    region_code_dnb = re.search(r"abbreviatedName=(\w+)", raw_data)
    region_code = None

    if country_code:
        country_code = country_code.group(1)
    else:
        country_code = ""

    if region_code_iso:
        region_code = region_code_iso.group(1)
        strings = region_code.split("-")
        region_code = strings[1]
    elif region_code_dnb:
        region_code = region_code_dnb.group(1)
    else:
        region_code = country_code

    return region_code