def test_conll_readwrite_sentence_extra_whitespace(): sentence = Sentence.from_conll(conll_example2.splitlines() + ['', '', '']) assert sentence.as_conll() == conll_example2.strip() sentence = Sentence.from_conll(['', ''] + conll_example2.splitlines() + ['', '']) assert sentence.as_conll() == conll_example2.strip() sentence = Sentence.from_conll([''] + conll_example2.splitlines()) assert sentence.as_conll() == conll_example2.strip()
def test_conll_readwrite_sentence_extra_whitespace(): sentence = Sentence.from_conll(conll_example2.splitlines() + ['', '', '']) assert sentence.as_conll() == conll_example2.strip() sentence = Sentence.from_conll(['', ''] + conll_example2.splitlines() + ['', '']) assert sentence.as_conll() == conll_example2.strip() sentence = Sentence.from_conll([''] + conll_example2.splitlines()) assert sentence.as_conll() == conll_example2.strip()
def test_conll_as_dotgraph_custom_edgeformat(): if older_than_py27: # this feature disabled in older Pythons return formatted_dotgraph = ''' digraph { 0 [label=root] 1 [label=Cathy] 2 -> 1 [label=su color=blue] 2 [label=zag] 0 -> 2 [label=ROOT color=red] 3 [label=hen] 2 -> 3 [label=obj1 color=blue] 4 [label=wild] 5 -> 4 [label=mod color=blue] 5 [label=zwaaien] 2 -> 5 [label=vc color=blue] 6 [label="."] 5 -> 6 [label=punct color=blue] } '''.strip() sentence = Sentence.from_conll(conll_example.splitlines()) def edge_formatter(token): if token.head == 0: return {'color': 'red'} else: return {'color': 'blue'} dotgraph = sentence.as_dotgraph(edge_formatter=edge_formatter) assert dotgraph.source == formatted_dotgraph
def test_conll_as_dotgraph_custom_nodeformat(): if older_than_py27: # this feature disabled in older Pythons return formatted_dotgraph = ''' digraph { 0 [label=root color=red] 1 [label=Cathy color=green] 2 -> 1 [label=su] 2 [label=zag color=blue] 0 -> 2 [label=ROOT] 3 [label=hen] 2 -> 3 [label=obj1] 4 [label=wild] 5 -> 4 [label=mod] 5 [label=zwaaien color=green] 2 -> 5 [label=vc] 6 [label="."] 5 -> 6 [label=punct] } '''.strip() def node_formatter(token): if token is None: return {'color': 'red'} elif token.cpos == 'N': return {'color': 'green'} elif token.cpos == 'V': return {'color': 'blue'} else: return {} sentence = Sentence.from_conll(conll_example.splitlines()) dotgraph = sentence.as_dotgraph(node_formatter=node_formatter) assert dotgraph.source == formatted_dotgraph
def test_conll_as_dotgraph_custom_edgeformat(): if older_than_py27: # this feature disabled in older Pythons return formatted_dotgraph = """ digraph { 0 [label=root] 1 [label=Cathy] 2 -> 1 [label=su color=blue] 2 [label=zag] 0 -> 2 [label=ROOT color=red] 3 [label=hen] 2 -> 3 [label=obj1 color=blue] 4 [label=wild] 5 -> 4 [label=mod color=blue] 5 [label=zwaaien] 2 -> 5 [label=vc color=blue] 6 [label="."] 5 -> 6 [label=punct color=blue] } """.strip() sentence = Sentence.from_conll(conll_example.splitlines()) def edge_formatter(token): if token.head == 0: return {"color": "red"} else: return {"color": "blue"} dotgraph = sentence.as_dotgraph(edge_formatter=edge_formatter) assert dotgraph.source == formatted_dotgraph
def test_conll_as_dotgraph_custom_nodeformat(): if older_than_py27: # this feature disabled in older Pythons return formatted_dotgraph = """ digraph { 0 [label=root color=red] 1 [label=Cathy color=green] 2 -> 1 [label=su] 2 [label=zag color=blue] 0 -> 2 [label=ROOT] 3 [label=hen] 2 -> 3 [label=obj1] 4 [label=wild] 5 -> 4 [label=mod] 5 [label=zwaaien color=green] 2 -> 5 [label=vc] 6 [label="."] 5 -> 6 [label=punct] } """.strip() def node_formatter(token): if token is None: return {"color": "red"} elif token.cpos == "N": return {"color": "green"} elif token.cpos == "V": return {"color": "blue"} else: return {} sentence = Sentence.from_conll(conll_example.splitlines()) dotgraph = sentence.as_dotgraph(node_formatter=node_formatter) assert dotgraph.source == formatted_dotgraph
def test_conll_as_asciitree(): asciitree_out = ''' zag [ROOT] +-- Cathy [su] +-- hen [obj1] +-- zwaaien [vc] +-- wild [mod] +-- . [punct]''' sentence = Sentence.from_conll(conll_example.splitlines()) assert sentence.as_asciitree().strip() == asciitree_out.strip()
def test_conll_as_asciitree(): asciitree_out = """ zag [ROOT] +-- Cathy [su] +-- hen [obj1] +-- zwaaien [vc] +-- wild [mod] +-- . [punct]""" sentence = Sentence.from_conll(conll_example.splitlines()) assert sentence.as_asciitree().strip() == asciitree_out.strip()
def test_conll_as_asciitree_custom(): asciitree_out = """ ROOT:zag:V +--su:Cathy:N +--obj1:hen:Pron +--vc:zwaaien:N +--mod:wild:Adj +--punct:.:Punc""" def str_func(token): return "%s:%s:%s" % (token.deprel, token.form, token.cpos) sentence = Sentence.from_conll(conll_example.splitlines()) assert sentence.as_asciitree(str_func=str_func).strip() == asciitree_out.strip()
def test_conll_as_asciitree_custom(): asciitree_out = ''' ROOT:zag:V +--su:Cathy:N +--obj1:hen:Pron +--vc:zwaaien:N +--mod:wild:Adj +--punct:.:Punc''' def str_func(token): return '%s:%s:%s' % (token.deprel, token.form, token.cpos) sentence = Sentence.from_conll(conll_example.splitlines()) assert sentence.as_asciitree(str_func=str_func).strip() == \ asciitree_out.strip()
def test_conll_as_dotgraph_custom_digraph_and_idprefix(): if older_than_py27: # this feature disabled in older Pythons return formatted_dotgraph = """ digraph test { x0 [label=root] x1 [label=Cathy] x2 -> x1 [label=su] x2 [label=zag] x0 -> x2 [label=ROOT] x3 [label=hen] x2 -> x3 [label=obj1] x4 [label=wild] x5 -> x4 [label=mod] x5 [label=zwaaien] x2 -> x5 [label=vc] x6 [label="."] x5 -> x6 [label=punct] }""".strip() sentence = Sentence.from_conll(conll_example.splitlines()) dotgraph = sentence.as_dotgraph(id_prefix="x", digraph_kwargs={"name": "test"})
def test_conll_as_dotgraph_custom_digraph_and_idprefix(): if older_than_py27: # this feature disabled in older Pythons return formatted_dotgraph = ''' digraph test { x0 [label=root] x1 [label=Cathy] x2 -> x1 [label=su] x2 [label=zag] x0 -> x2 [label=ROOT] x3 [label=hen] x2 -> x3 [label=obj1] x4 [label=wild] x5 -> x4 [label=mod] x5 [label=zwaaien] x2 -> x5 [label=vc] x6 [label="."] x5 -> x6 [label=punct] }'''.strip() sentence = Sentence.from_conll(conll_example.splitlines()) dotgraph = sentence.as_dotgraph(id_prefix='x', digraph_kwargs={'name': 'test'})
def test_conll_readwrite_sentence2(): sentence = Sentence.from_conll(conll_example2.splitlines()) assert sentence.as_conll() == conll_example2.strip()
def test_conll_readwrite_sentence(): sentence = Sentence.from_conll(conll_example.splitlines()) assert sentence.as_conll() == conll_example.strip()