mirror of https://github.com/explosion/spaCy.git
e3af19a076
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'] |
||
---|---|---|
.. | ||
_adding-languages | ||
_deep-learning | ||
_facts-figures | ||
_install | ||
_linguistic-features | ||
_models | ||
_processing-pipelines | ||
_spacy-101 | ||
_training | ||
_v2 | ||
_vectors-similarity | ||
_visualizers | ||
_data.json | ||
_deep-learning.jade | ||
adding-languages.jade | ||
examples.jade | ||
facts-figures.jade | ||
index.jade | ||
linguistic-features.jade | ||
models.jade | ||
processing-pipelines.jade | ||
resources.jade | ||
spacy-101.jade | ||
training.jade | ||
v2.jade | ||
vectors-similarity.jade | ||
visualizers.jade |