Esempio n. 1
0
def test_punctuation_symetrify(discont_tree, cont_tree):
    """transform.punctuation_symetrify
    """
    temp = tempfile.NamedTemporaryFile(mode='w')
    temp.write('1\t3\t"\t$(\n')
    temp.write('1\t5\t"\t$(\n')
    temp.write('1\t8\t,\t$,\n')
    temp.flush()
    params = {'terminalfile': temp.name, 'quiet': True}
    old_terms = trees.terminals(discont_tree)
    discont_tree = transform.insert_terminals(discont_tree,
                                              **params)
    new_terms = trees.terminals(discont_tree)
    assert len(old_terms) == len(new_terms) - 3
    discont_tree = transform.root_attach(discont_tree)
    discont_tree = transform.punctuation_symetrify(discont_tree)
    treeoutput.compute_export_numbering(discont_tree)
    assert new_terms[2].parent.data['num'] == 504
    assert new_terms[4].parent.data['num'] == 504
    assert new_terms[7].parent.data['num'] == 503
    # cont
    temp = tempfile.NamedTemporaryFile(mode='w')
    temp.write('1\t3\t"\t$(\n')
    temp.write('1\t5\t"\t$(\n')
    temp.write('1\t8\t,\t$,\n')
    temp.flush()
    params = {'terminalfile': temp.name, 'quiet': True}
    old_terms = trees.terminals(cont_tree)
    cont_tree = transform.insert_terminals(cont_tree,
                                           **params)
    new_terms = trees.terminals(cont_tree)
    assert len(old_terms) == len(new_terms) - 3
    cont_tree = transform.root_attach(cont_tree)
    cont_tree = transform.punctuation_symetrify(cont_tree)
    treeoutput.compute_export_numbering(cont_tree)
    assert new_terms[2].parent.data['num'] == 504
    assert new_terms[4].parent.data['num'] == 504
    assert new_terms[7].parent.data['num'] == 503
Esempio n. 2
0
def test_boyd(discont_tree):
    """See transform.boyd_split
    """
    tree = discont_tree
    tree = transform.root_attach(tree)
    tree = transform.negra_mark_heads(tree)
    tree = transform.boyd_split(tree)
    nodes = [node for node in trees.preorder(tree)]
    labels = [node.data['label'] for node in nodes]
    terms = trees.terminals(tree)
    words = [node.data['word'] for node in terms]
    uterms = trees.unordered_terminals(tree)
    uwords = [node.data['word'] for node in uterms]
    assert labels == testdata.DISCONT_LABELSBOYD_PREORDER
    assert words == testdata.WORDS
    assert set(uwords) == set(testdata.WORDS)
Esempio n. 3
0
def test_root_attach(discont_tree):
    """See transform.root_attach
    """
    tree = discont_tree
    tree = transform.root_attach(tree)
    nodes = [node for node in trees.preorder(tree)]
    labels = [node.data['label'] for node in nodes]
    terms = trees.terminals(tree)
    words = [node.data['word'] for node in terms]
    uterms = trees.unordered_terminals(tree)
    uwords = [node.data['word'] for node in uterms]
    assert labels == testdata.DISCONT_LABELS_PREORDER
    assert words == testdata.WORDS
    assert set(uwords) == set(testdata.WORDS)
    with pytest.raises(ValueError):
        transform.boyd_split(tree)