mirror of https://github.com/explosion/spaCy.git
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']
This commit is contained in:
parent
050a94867b
commit
e3af19a076
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue