def string_matching_simple_contains_word_nnqt_question_construction(
        generated_template: Dict[str, Any]):
    # There are 2 templates covered in this file, which have different NNQT_question construction. The extraction of word or letter is common
    word = re.findall("'(.*?)'", generated_template['sparql_wikidata'])[0]
    if generated_template['template_id'] == 1:
        # Word matching
        questions_generator.recreate_nnqt_question(
            generated_template,
            "Give me |property_0||entity_0| that contains the word {" + word +
            "} in their name", [0], [])
    else:
        # Starting letter matching
        questions_generator.recreate_nnqt_question(
            generated_template,
            "Give me |property_0||entity_0| that starts with {'" + word + "'}",
            [0], [])
    # Change NNQT_question format if property is not "instance of", otherwise there wouldn't be differences between the original and the modified questions
    query_property = questions_generator.get_elements_from_query(
        generated_template['sparql_wikidata'], [0], True)[0]
    if query_property == "P31":
        generated_template['NNQT_question'] = generated_template[
            'NNQT_question'].replace("|property_0|", "")
    else:
        generated_template['NNQT_question'] = generated_template[
            'NNQT_question'].replace(
                "|property_0|",
                "{" + questions_generator.get_entity_name_from_wikidata_id(
                    query_property) + "} ")
コード例 #2
0
def rank_nnqt_question_construction(generated_template: Dict[str, Any]):
    if 'desc' in generated_template['sparql_wikidata'].lower():
        order_string = "MAX"
    else:
        order_string = "MIN"
    questions_generator.recreate_nnqt_question(
        generated_template, "What is the |entity_0| with the |property_0| ?",
        [0], [1])
    property_name = re.findall("{(.*?)}",
                               generated_template['NNQT_question'])[1]
    generated_template['NNQT_question'] = generated_template[
        'NNQT_question'].replace(property_name,
                                 order_string + "(" + property_name + ")")
def string_matching_type_relation_contains_word_nnqt_question_construction(
        generated_template: Dict[str, Any]):
    # There are 2 templates covered in this file, which have different NNQT_question construction. The extraction of word or letter is common
    word = re.findall("'(.*?)'", generated_template['sparql_wikidata'])[0]
    if generated_template['template_id'] == 3:
        # Word matching
        questions_generator.recreate_nnqt_question(
            generated_template,
            "Give me |entity_0| that |property_0| |entity_1| and which contains the word {"
            + word + "} in their name", [0, 1], [1])
    else:
        # Starting letter matching
        questions_generator.recreate_nnqt_question(
            generated_template,
            "Give me |entity_0| that |property_0| |entity_1| and which that starts with {'"
            + word + "'}", [0, 1], [1])
コード例 #4
0
def statement_property_nnqt_question_construction(generated_template: Dict[str, Any]):
    sparql_query = generated_template['old_sparql_wikidata']
    if 'filter' in sparql_query.lower():
        # Find second entity value, substituting the answer variable with the corresponding variable
        answer_var_name = re.findall(r'SELECT (\?\w*) WHERE', sparql_query, re.IGNORECASE)[0]
        entity_var_name = re.findall(r' (\?\w*) filter', sparql_query, re.IGNORECASE)[0]
        sparql_query_entity = sparql_query.replace(answer_var_name, entity_var_name, 1)
        fixed_entity = next(iter(questions_generator.get_sparql_query_results(sparql_query_entity)['results']['bindings'][0].values()))['value'].split("/")[-1]
        # If entity is a date, keep only year-month-day part
        if questions_generator.get_element_type(fixed_entity) == questions_generator.ElementType.date:
            fixed_entity = fixed_entity.split("T")[0]
        fixed_entities = [fixed_entity]
        questions_generator.recreate_nnqt_question(generated_template, "What is |property_0| of |entity_0| that is |property_1| is |element_0| ?", [0], [0], False,
        fixed_entities = fixed_entities)
    else:
        questions_generator.recreate_nnqt_question(generated_template, "What is |property_0| of |entity_0| that is |property_1| is |entity_1| ?", [0, 1], [0], False)
コード例 #5
0
def right_subgraph_2_nnqt_question_construction(generated_template: Dict[str, Any]):
    questions_generator.recreate_nnqt_question(generated_template, "What is |property_1| of |property_0| of |entity_0| ?", [0], [0, 1])
コード例 #6
0
def simple_question_left_nnqt_question_construction(
        generated_template: Dict[str, Any]):
    questions_generator.recreate_nnqt_question(
        generated_template,
        "What is the |entity_1| for |property_0| of |entity_0|", [0, 1], [0])
コード例 #7
0
def unknown_nnqt_question_construction(generated_template: Dict[str, Any]):
    questions_generator.recreate_nnqt_question(generated_template, "What is |property_0| of |entity_0| and |property_1|", [0], [0], False)
コード例 #8
0
def center_2_nnqt_question_construction(generated_template: Dict[str, Any]):
    questions_generator.recreate_nnqt_question(
        generated_template, "What is |property_0| of |entity_0|", [0], [0])