def check_match()

in dataset-construction/src/ndb_data/generation/finalize_hypothesis.py [0:0]


def check_match(snak, test):
    if snak is None or snak[0] is None:
        return False

    if "amount" in snak[0]:
        if snak[0]["amount"] == test:
            return True

        if "unit" in snak[0] and snak[0]["unit"] is not None and snak[0]["unit"] != "1":
            unit = get_unit(snak[0]["unit"])
            if f"{snak[0]['amount']} {unit['english_name']}" == test:
                return True

        return False
    else:
        if "time" in snak[0] and "precision" in snak[0]:

            matches = re.match(
                r"\+([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})([A-Za-z0-9+-:]+)",
                snak[0]["time"],
            )

            if matches is None:
                print(snak[0]["time"])
                return False

            if snak[0]["precision"] == 9:  # Year
                return matches.group(1) in test
            elif snak[0]["precision"] == 11:  # Year month date
                return (
                    matches.group(1) in test
                    and calendar.month_name[int(matches.group(2))] in test
                    and matches.group(3) in test
                )
            elif snak[0]["precision"] == 10:  # Year month
                return (
                    matches.group(1) in test
                    and calendar.month_name[int(matches.group(2))] in test
                )
            elif snak[0]["precision"] == 7:  # Century
                return matches.group(1)[:-2] in test
            elif snak[0]["precision"] == 8:  # Decade
                return matches.group(1)[:-1] in test

        print("*******")
        print(test)
        print(snak)
        print("*******")
        return False