def read_csv()

in dataset-construction/src/ndb_data/util/build_json.py [0:0]


def read_csv(f):
    next(f)
    reader = csv.DictReader(f)

    templates = defaultdict(set)

    for template in reader:

        if len(template["fact"]):
            templates["fact"].add(template["fact"])

        if len(template["bool"]):
            if template["bool_answer"].lower() in ["true", "t", "1", "yes", "y"]:
                templates["bool"].add((template["bool"], template["bool_answer"]))

        if len(template["set"]):
            templates["set"].add((template["set"], template["set_projection"]))

        if len(template["count"]):
            templates["count"].add((template["count"], template["count_projection"]))

        if len(template["min"]):
            templates["min"].add((template["min"], template["min_projection"]))

        if len(template["max"]):
            templates["max"].add((template["max"], template["max_projection"]))

        if len(template["argmin"]):
            templates["argmin"].add((template["argmin"], template["argmin_projection"]))

        if len(template["argmax"]):
            templates["argmax"].add((template["argmax"], template["argmax_projection"]))

        templates["_subject"] = "$s"
        templates["_object"] = "$o"

    return {k: list(v) if isinstance(v, set) else v for k, v in templates.items()}