From e3af19a076104052f5ee0401868eb670346bd410 Mon Sep 17 00:00:00 2001 From: mpuels Date: Wed, 6 Dec 2017 20:08:42 +0100 Subject: [PATCH] doc: Replace 'is not' with '!=' in code example The function `dependency_labels_to_root(token)` defined in section *Get syntactic dependencies* does not terminate. Here is a complete example: import spacy nlp = spacy.load('en') doc = nlp("Apple and banana are similar. Pasta and hippo aren't.") def dependency_labels_to_root(token): """Walk up the syntactic tree, collecting the arc labels.""" dep_labels = [] while token.head is not token: dep_labels.append(token.dep) token = token.head return dep_labels dep_labels = dependency_labels_to_root(doc[1]) dep_labels Replacing `is not` with `!=` solves the issue: import spacy nlp = spacy.load('en') doc = nlp("Apple and banana are similar. Pasta and hippo aren't.") def dependency_labels_to_root(token): """Walk up the syntactic tree, collecting the arc labels.""" dep_labels = [] while token.head != token: dep_labels.append(token.dep) token = token.head return dep_labels dep_labels = dependency_labels_to_root(doc[1]) dep_labels The output is ['cc', 'nsubj'] --- website/usage/_spacy-101/_lightning-tour.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/usage/_spacy-101/_lightning-tour.jade b/website/usage/_spacy-101/_lightning-tour.jade index 45c934319..96f274002 100644 --- a/website/usage/_spacy-101/_lightning-tour.jade +++ b/website/usage/_spacy-101/_lightning-tour.jade @@ -264,7 +264,7 @@ p def dependency_labels_to_root(token): """Walk up the syntactic tree, collecting the arc labels.""" dep_labels = [] - while token.head is not token: + while token.head != token: dep_labels.append(token.dep) token = token.head return dep_labels