From d9c567371f9ae85cb75b86ecd90bae5b00544905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bournhonesque?= Date: Sun, 11 Jun 2017 18:29:28 +0200 Subject: [PATCH] Move add_node and add_edge methods to the Tree base class --- spacy/pattern/pattern.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spacy/pattern/pattern.py b/spacy/pattern/pattern.py index 42a15f769..de7a54e05 100644 --- a/spacy/pattern/pattern.py +++ b/spacy/pattern/pattern.py @@ -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: