mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-12 04:38:28 +03:00
Move add_node and add_edge methods to the Tree base class
This commit is contained in:
parent
8ff4f512a2
commit
d9c567371f
|
@ -15,6 +15,16 @@ class Tree(object):
|
|||
def __getitem__(self, item):
|
||||
return self.nodes[item]
|
||||
|
||||
def add_node(self, node, attr_dict=None):
|
||||
attr_dict = attr_dict or {}
|
||||
self.nodes[node] = attr_dict
|
||||
|
||||
def add_edge(self, u, v, dep=None):
|
||||
if u not in self.nodes or v not in self.nodes:
|
||||
raise ValueError("Each node must be defined before adding an edge.")
|
||||
|
||||
self.adjacency[u][v] = dep
|
||||
|
||||
def number_of_nodes(self):
|
||||
return len(self)
|
||||
|
||||
|
@ -67,16 +77,6 @@ class Tree(object):
|
|||
|
||||
|
||||
class DependencyPattern(Tree):
|
||||
def add_node(self, node, attr_dict=None):
|
||||
attr_dict = attr_dict or {}
|
||||
self.nodes[node] = attr_dict
|
||||
|
||||
def add_edge(self, u, v, dep=None):
|
||||
if u not in self.nodes or v not in self.nodes:
|
||||
raise ValueError("Each node must be defined before adding an edge.")
|
||||
|
||||
self.adjacency[u][v] = dep
|
||||
|
||||
@property
|
||||
def root_node(self):
|
||||
if self.number_of_nodes() == 1:
|
||||
|
|
Loading…
Reference in New Issue
Block a user