Ejemplo n.º 1
0
def test_graph():
    _check_jena()
    t = SyntaxTree(TEST_SAF, sentence_id=1)
    g = t.get_graphviz()
    assert_equal(
        set(g.edges()), {(u"t_3_Mary", u"t_2_marry"), (u"t_1_John", u"t_2_marry"), (u"t_4_little", u"t_1_John")}
    )
    assert_in("lemma: John", g.get_node("t_1_John").attr["label"])

    # Can we 'gray out' syntax relations after applying rules
    t.apply_ruleset(TEST_RULES)
    t.apply_lexicon([{"lexclass": "man", "lemma": "john"}])
    g = t.get_graphviz()  # triple_args_function=VIS_GREY_REL)
    assert_equal(
        set(g.edges()),
        {
            (u"t_3_Mary", u"t_2_marry"),
            (u"t_1_John", u"t_2_marry"),
            (u"t_4_little", u"t_1_John"),
            (u"t_1_John", u"t_3_Mary"),
        },
    )
    # assert_false(g.get_edge(u't_1_John', u't_3_Mary').attr.get("color"))
    # assert_equal(g.get_edge(u't_1_John', u't_2_marry').attr.get("color"),
    # "grey")

    # can we draw it? can't check output, but we can check for errors
    with tempfile.NamedTemporaryFile() as f:
        g.draw(f.name, prog="dot")
        g.draw("/tmp/test.png", prog="dot")
Ejemplo n.º 2
0
def test_lexicon():
    _check_jena()
    t = SyntaxTree(TEST_SAF, sentence_id=1)
    t.apply_lexicon(TEST_RULES["lexicon"])

    classes = {k.replace(NS_AMCAT, ":"): v.get("lexclass") for (k, v) in t.get_tokens().iteritems()}
    assert_equal(
        classes, {":t_2_marry": ["marry"], ":t_3_Mary": ["person"], ":t_1_John": ["person"], ":t_4_little": None}
    )