Beispiel #1
0
def concept_parser(concept_str):
    if utils.clean_field(concept_str) is not None:
        first_split = str(utils.clean_field(concept_str)).split("|")
        second_split = [i.split(":") for i in first_split]
        return second_split
    else:
        return None
Beispiel #2
0
def classifications_parser(class_str):
    if utils.clean_field(class_str) is not None:
        first_split = str(utils.clean_field(class_str)).split("|")
        second_split = [i.split("\\") for i in first_split]
        third_split = [i[0].split(" - ") for i in second_split]
        o = [[third_split[i][0],third_split[i][1],second_split[i][1]] for i in range(len(third_split))]
        return o
    else:
        return None
Beispiel #3
0
def answer_parser(ans_str):
    if utils.clean_field(ans_str) is not None:
        first_split = str(utils.clean_field(ans_str)).split("|")
        second_split = [i.split("\\") for i in first_split]
        second_split = [list(set(i)) for i in second_split]
        second_split = [[j for j in i if j != ''] for i in second_split]
        return second_split
    else:
        return None
Beispiel #4
0
def create_questiontext_str(qt_str,name=None):
    s = utils.clean_field(qt_str)
    if name is None:
        n = f"(:QuestionText {{name: '{s}'}})"
    else:
        n = f"({name}:QuestionText {{name: '{s}'}})"
    return n
Beispiel #5
0
def create_semantictype_str(st_str,name=None):
    s = utils.clean_field(st_str)
    if name is None:
        n = f"(:SemanticType {{name: '{s}'}})"
    else:
        n = f"({name}:SemanticType {{name: '{s}'}})"
    return n
Beispiel #6
0
def create_concept_str_from_row(row,name=None):
    row_index = int(row.name)
    code = row['CODE']
    concept_name = utils.clean_field(row['CONCEPT_NAME'])
    definition = utils.clean_field(row['DEFINITION'])
    l = [
        f"CODE: '{code}'",
        f"CONCEPT_NAME: '{concept_name}'",
        f"DEFINITION: '{definition}'",
        f"row_index: {row_index}"
    ]
    if name is None:
        n = "(:Concept {" + ", ".join(l) + "})"
    else:
        n = "({0:s}:Concept".format(name) + " {" + ", ".join(l) + "})"
    return n
Beispiel #7
0
def create_answer_text_str(ans_text,name=None):
    clean_txt = utils.clean_field(ans_text)
    if name is None:
        o = "(:AnswerText {name: '" + clean_txt + "', name_lower: '" + clean_txt.lower() + "'})"
    else:
        o = "(" + name + ":AnswerText {name: '" + clean_txt + "', name_lower: '" + clean_txt.lower() + "'})"
    return o
Beispiel #8
0
def create_synonym_str(syn_str,name=None):
    s = utils.clean_field(syn_str)
    s_lower = s.lower()
    if name is None:
        n = f"(:Synonym {{name: '{s}', name_lower: '{s_lower}'}})"
    else:
        n = f"({name}:Synonym {{name: '{s}', name_lower: '{s_lower}'}})"
    return n
Beispiel #9
0
def create_dec_str_from_row(row,name=None):
    if utils.clean_field(row['DEC_ID']) is not None:
        d = {
            "dec_id": {
                "name": "DEC_ID",
                "value": utils.clean_field(row['DEC_ID']),
                "type": "num"
            },
            "dec_long_name": {
                "name": "name",
                "value": utils.clean_field(row['DEC_LONG_NAME']),
                "type": "text"
            },
            "dec_long_lower": {
                "name": "name_lower",
                "value": utils.clean_field(row['DEC_LONG_NAME'],to_lower=True),
                "type": "text"
            }
        }
        l = []
        for prop in [
            "dec_id",
            "dec_long_name",
            "dec_long_lower"
        ]:
            if d[prop]['value'] is not None:
                if d[prop]['type'] == 'num':
                    l.append(
                        d[prop]["name"]+": " + str(d[prop]['value'])
                    )
                else:
                    l.append(
                        d[prop]["name"]+": '" + str(d[prop]['value']) + "'"
                    )
        if name is None:
            n = "(:DEC {" + ", ".join(l) + "})"
        else:
            n = "({0:s}:DEC".format(name) + " {" + ", ".join(l) + "})"
        return n
    else:
        return None
Beispiel #10
0
def create_classification_str_from_list(class_list,name=None):
    if name is None:
        o = "(:Classification {TYPE: '" + utils.clean_field(class_list[0]) + "', "
        o += "VALUE: '" + utils.clean_field(class_list[1]) + "', "
        o += "CONTEXT: '" + utils.clean_field(class_list[2]) + "'})"
    else:
        o = "(" + name + ":Classification {TYPE: '" + utils.clean_field(class_list[0]) + "', "
        o += "VALUE: '" + utils.clean_field(class_list[1]) + "', "
        o += "CONTEXT: '" + utils.clean_field(class_list[2]) + "'})"
    return o
Beispiel #11
0
def create_cde_str_from_row(row,name=None):
    d = {
        "row_index": {
            "name": "row_index",
            "value": int(row.name),
            "type": "num"
        },
        "cde_id": {
            "name": "CDE_ID",
            "value": int(row['CDE_ID']),
            "type": "num"
        },
        "cde_long_name": {
            "name": "CDE_LONG_NAME",
            "value": utils.clean_field(row['CDE_LONG_NAME']),
            "type": "text"
        },
        "cde_long_name_lower": {
            "name": "CDE_LONG_NAME_LOWER",
            "value": utils.clean_field(row['CDE_LONG_NAME'],to_lower=True),
            "type": "text"
        },
        "cde_short_name": {
            "name": "name",
            "value": utils.clean_field(row['CDE_SHORT_NAME']),
            "type": "text"
        },
        "cde_short_name_lower":{
            "name": "name_lower",
            "value": utils.clean_field(row['CDE_SHORT_NAME'],to_lower=True),
            "type": "text"
        },
        "definition": {
            "name": "DEFINITION",
            "value": utils.clean_field(row['DEFINITION']),
            "type": "text"
        },
        "context_name": {
            "name": "CONTEXT_NAME",
            "value": utils.clean_field(row['CONTEXT_NAME']),
            "type": "text"
        },
        "workflow_status": {
            "name": "WORKFLOW_STATUS",
            "value": utils.clean_field(row['WORKFLOW_STATUS']),
            "type": "text"
        },
        "registration_status": {
            "name": "REGISTRATION_STATUS",
            "value": utils.clean_field(row['REGISTRATION_STATUS']),
            "type": "text"
        },
        "value_domain_type": {
            "name": "VALUE_DOMAIN_TYPE",
            "value": utils.clean_field(row['VALUE_DOMAIN_TYPE']),
            "type": "text"
        },
        "datatype": {
            "name": "DATATYPE",
            "value": utils.clean_field(row['DATATYPE']),
            "type": "text"
        },
        "unit_of_measure": {
            "name": "UNIT_OF_MEASURE",
            "value": utils.clean_field(row['UNIT_OF_MEASURE']),
            "type": "text"
        },
        "display_format": {
            "name": "DISPLAY_FORMAT",
            "value": utils.clean_field(row['DISPLAY_FORMAT']),
            "type": "text"
        },
        "max_value": {
            "name": "MAX_VALUE",
            "value": utils.clean_field(row['MAX_VALUE']),
            "type": "num"
        },
        "min_value": {
            "name": "MIN_VALUE",
            "value": utils.clean_field(row['MIN_VALUE']),
            "type": "num"
        },
        "decimal_place": {
            "name": "DECIMAL_PLACE",
            "value": utils.clean_field(row['DECIMAL_PLACE']),
            "type": "num"
        }
    }
    l = []
    for prop in [
        "cde_id",
        "cde_long_name",
        "cde_long_name_lower",
        "cde_short_name",
        "cde_short_name_lower",
        "definition",
        "context_name",
        "workflow_status",
        "registration_status",
        "value_domain_type",
        "datatype",
        "unit_of_measure",
        "display_format",
        "max_value",
        "min_value",
        "decimal_place",
        "row_index"
    ]:
        if d[prop]['value'] is not None:
            if d[prop]['type'] == 'num':
                l.append(
                    d[prop]["name"]+": " + str(d[prop]['value'])
                )
            else:
                l.append(
                    d[prop]["name"]+": '" + str(d[prop]['value']) + "'"
                )
    if name is None:
        n = "(:CDE {" + ", ".join(l) + "})"
    else:
        n = "({0:s}:CDE".format(name) + " {" + ", ".join(l) + "})"
    return n
Beispiel #12
0
def create_answer_str_from_list(ans_list,name=None):
    if name is None:
        o = "(:Answer {name: '" + utils.clean_field("|".join(ans_list)) + "'})"
    else:
        o = "(" + name + ":Answer {name: '" + utils.clean_field("|".join(ans_list)) + "'})"
    return o
Beispiel #13
0
def pipe_parser(pipe_str):
    if utils.clean_field(pipe_str) is not None:
        first_split = str(utils.clean_field(pipe_str)).split("|")
        return first_split
    else:
        return None