Commit c8566098 by Dmitrijs Milajevs

Warn a user when there is no ROOT node, instead of throwing an exception.

This should resolve issues faced at #944. However, there is code that
depends on a fake root node, for example the tree visualisation code reads this and FStructure.to_depgraph() sets it.
parent 2fd71c85
...@@ -19,6 +19,7 @@ from collections import defaultdict ...@@ -19,6 +19,7 @@ from collections import defaultdict
from itertools import chain from itertools import chain
from pprint import pformat from pprint import pformat
import subprocess import subprocess
import warnings
from nltk.tree import Tree from nltk.tree import Tree
from nltk.compat import python_2_unicode_compatible, string_types from nltk.compat import python_2_unicode_compatible, string_types
...@@ -291,13 +292,14 @@ class DependencyGraph(object): ...@@ -291,13 +292,14 @@ class DependencyGraph(object):
rel = 'ROOT' rel = 'ROOT'
self.nodes[head]['deps'][rel].append(index) self.nodes[head]['deps'][rel].append(index)
if not self.nodes[0]['deps']['ROOT']: if self.nodes[0]['deps']['ROOT']:
raise DependencyGraphError( root_address = self.nodes[0]['deps']['ROOT'][0]
"The graph does'n contain a node " self.root = self.nodes[root_address]
else:
warnings.warn(
"The graph doesn't contain a node "
"that depends on the root element." "that depends on the root element."
) )
root_address = self.nodes[0]['deps']['ROOT'][0]
self.root = self.nodes[root_address]
def _word(self, node, filter=True): def _word(self, node, filter=True):
w = node['word'] w = node['word']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment