Example #1
0
def test_syntax_path():
    string = "Line AB is perpendicular to CD."
    tokens = string_to_tokens(string)
    k = 5
    syntax = create_syntax(tokens, k)
    from_token = tokens[0]
    to_token = tokens[5]
    paths = get_syntax_paths(syntax, from_token, to_token)
    print([len(path) for path in paths.values()])
    syntax.syntax_trees[0].display_graph()
Example #2
0
def test_syntax_path():
    string = "Line AB is perpendicular to CD."
    tokens = string_to_tokens(string)
    k = 5
    syntax = create_syntax(tokens, k)
    from_token = tokens[0]
    to_token = tokens[5]
    paths = get_syntax_paths(syntax, from_token, to_token)
    print([len(path) for path in paths.values()])
    syntax.syntax_trees[0].display_graph()
Example #3
0
def test_get_grounded_syntax_paths():
    string = "Circle O has a radius of 5."
    tokens = string_to_tokens(string)
    syntax = create_syntax(tokens, 1)
    grounded_syntax = get_grounded_syntax(syntax, ontology_semantics, geowordnet, 0.99)
    circle = grounded_syntax.grounded_tokens[(0, 'circle')]
    radius = grounded_syntax.grounded_tokens[(4, 'radiusOf')]
    grounded_syntax_paths = get_grounded_syntax_paths(grounded_syntax, circle, radius)
    ontology_paths = get_ontology_paths(grounded_syntax.basic_ontology, radius.ground.arg_types[0], circle.ground)
    print(ontology_paths)
    print(get_grounded_syntax_path_cost(grounded_syntax_paths[0]))
    print(get_ontology_path_cost(ontology_paths[0]))
    pprint(grounded_syntax_paths)
    pprint(ontology_paths)

    grounded_syntax.display_graphs()
Example #4
0
def test_get_grounded_syntax_paths():
    string = "Circle O has a radius of 5."
    tokens = string_to_tokens(string)
    syntax = create_syntax(tokens, 1)
    grounded_syntax = get_grounded_syntax(syntax, ontology_semantics,
                                          geowordnet, 0.99)
    circle = grounded_syntax.grounded_tokens[(0, 'circle')]
    radius = grounded_syntax.grounded_tokens[(4, 'radiusOf')]
    grounded_syntax_paths = get_grounded_syntax_paths(grounded_syntax, circle,
                                                      radius)
    ontology_paths = get_ontology_paths(grounded_syntax.basic_ontology,
                                        radius.ground.arg_types[0],
                                        circle.ground)
    print(ontology_paths)
    print(get_grounded_syntax_path_cost(grounded_syntax_paths[0]))
    print(get_ontology_path_cost(ontology_paths[0]))
    pprint(grounded_syntax_paths)
    pprint(ontology_paths)

    grounded_syntax.display_graphs()
Example #5
0
def test_trees():
    root_path = "/Users/minjoon/Desktop/questions2"
    if not os.path.exists(root_path):
        os.mkdir(root_path)
    k = 300
    numbers = [26, 28]
    questions = geoserver_interface.download_questions(numbers)
    for pk, question in questions.iteritems():
        folder_name = get_number_string(pk, 4)
        question_path = os.path.join(root_path, folder_name)
        if not os.path.exists(question_path):
            os.mkdir(question_path)
        lexical_parses = get_lexical_parses(question.text)
        for idx, lexical_parse in enumerate(lexical_parses):
            sentence_folder_name = get_number_string(idx, 2)
            sentence_path = os.path.join(question_path, sentence_folder_name)
            if not os.path.exists(sentence_path):
                os.mkdir(sentence_path)

            syntax = create_syntax(lexical_parse.tokens, k)
            syntax.save_graphs(sentence_path)
            print(pk, idx)
Example #6
0
def test_trees():
    root_path = "/Users/minjoon/Desktop/questions2"
    if not os.path.exists(root_path):
        os.mkdir(root_path)
    k = 300
    numbers = [26, 28]
    questions = geoserver_interface.download_questions(numbers)
    for pk, question in questions.iteritems():
        folder_name = get_number_string(pk, 4)
        question_path = os.path.join(root_path, folder_name)
        if not os.path.exists(question_path):
            os.mkdir(question_path)
        lexical_parses = get_lexical_parses(question.text)
        for idx, lexical_parse in enumerate(lexical_parses):
            sentence_folder_name = get_number_string(idx, 2)
            sentence_path = os.path.join(question_path, sentence_folder_name)
            if not os.path.exists(sentence_path):
                os.mkdir(sentence_path)

            syntax = create_syntax(lexical_parse.tokens, k)
            syntax.save_graphs(sentence_path)
            print(pk, idx)
Example #7
0
def test_get_semantic_trees():
    string = "Circle O has a radius of 5."
    tokens = string_to_tokens(string)
    print("Tokens initalized.")
    syntax = create_syntax(tokens, 10)
    syntax.display_graphs()
    print("Syntax initialized.")
    threshold = 0.99
    grounded_syntax = get_grounded_syntax(syntax, ontology_semantics, geowordnet, threshold)
    print("Grounded syntax initialized.")
    semantic_forest = get_semantic_forest(grounded_syntax, 3, 3)
    print("Forest initialized.")
    truth = grounded_syntax.basic_ontology.types['truth']
    qnumber = grounded_syntax.basic_ontology.types['uNumber']
    semantic_trees = get_semantic_trees(semantic_forest, truth)

    grounded_syntax.display_graphs()
    semantic_forest.display_graph()
    print(len(semantic_trees))
    for semantic_tree in semantic_trees.values():
        print(get_semantic_tree_cost(semantic_tree))
        print(semantic_tree.formula)
        semantic_tree.display_graph()
Example #8
0
def test_get_semantic_trees():
    string = "Circle O has a radius of 5."
    tokens = string_to_tokens(string)
    print("Tokens initalized.")
    syntax = create_syntax(tokens, 10)
    syntax.display_graphs()
    print("Syntax initialized.")
    threshold = 0.99
    grounded_syntax = get_grounded_syntax(syntax, ontology_semantics,
                                          geowordnet, threshold)
    print("Grounded syntax initialized.")
    semantic_forest = get_semantic_forest(grounded_syntax, 3, 3)
    print("Forest initialized.")
    truth = grounded_syntax.basic_ontology.types['truth']
    qnumber = grounded_syntax.basic_ontology.types['uNumber']
    semantic_trees = get_semantic_trees(semantic_forest, truth)

    grounded_syntax.display_graphs()
    semantic_forest.display_graph()
    print(len(semantic_trees))
    for semantic_tree in semantic_trees.values():
        print(get_semantic_tree_cost(semantic_tree))
        print(semantic_tree.formula)
        semantic_tree.display_graph()
Example #9
0
def test_create_syntax():
    string = "Line AB is perpendicular to CD."
    tokens = string_to_tokens(string)
    k = 5
    syntax = create_syntax(tokens, k)
    syntax.display_graphs()
Example #10
0
def test_create_syntax():
    string = "Line AB is perpendicular to CD."
    tokens = string_to_tokens(string)
    k = 5
    syntax = create_syntax(tokens, k)
    syntax.display_graphs()