spaCy/website/usage/_spacy-101
mpuels e3af19a076
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']
2017-12-06 20:08:42 +01:00
..
_architecture.jade Don't document the tensorizer for now 2017-11-01 19:49:04 +01:00
_community-faq.jade Remove outdated aside 2017-10-14 12:52:07 +02:00
_language-data.jade Update usage documentation 2017-10-03 14:26:20 +02:00
_lightning-tour.jade doc: Replace 'is not' with '!=' in code example 2017-12-06 20:08:42 +01:00
_named-entities.jade Update usage documentation 2017-10-03 14:26:20 +02:00
_pipelines.jade Don't document the tensorizer for now 2017-11-01 19:49:04 +01:00
_pos-deps.jade Update usage documentation 2017-10-03 14:26:20 +02:00
_serialization.jade Update usage documentation 2017-10-03 14:26:20 +02:00
_similarity.jade Fix similarity visual 2017-11-09 11:08:26 +01:00
_tokenization.jade Update links 2017-11-13 08:30:06 +01:00
_training.jade Update usage documentation 2017-10-03 14:26:20 +02:00
_vocab.jade Update usage documentation 2017-10-03 14:26:20 +02:00
_word-vectors.jade Re-add python -m to commands, too brittle :( (see #1536) 2017-11-10 02:30:55 +01:00