anchor.diff:      |  two integer-typed attributes, #[code .n_rights] and #[code .n_lefts],
       |  that give the number of left and right children.
   
  -+aside-code("Examples").
  -    apples = nlp(u'bright red apples on the tree')[2]
  -    print([w.text for w in apples.lefts])
  -    # ['bright', 'red']
  -    print([w.text for w in apples.rights])
  -    # ['on']
  -    assert apples.n_lefts == 2
  -    assert apples.n_rights == 1
  -
  -    from spacy.symbols import nsubj
  -    doc = nlp(u'Credit and mortgage account holders must submit their requests within 30 days.')
  -    root = [w for w in doc if w.head is w][0]
  ++code.
  +    doc = nlp(u'bright red apples on the tree')
  +    assert [token.text for token in doc[2].lefts]) == [u'bright', u'red']
  +    assert [token.text for token in doc[2].rights]) == ['on']
  +    assert doc[2].n_lefts == 2
  +    assert doc[2].n_rights == 1
  +
  +p
  +    |  You can get a whole phrase by its syntactic head using the
  +    |  #[code .subtree] attribute. This returns an ordered sequence of tokens.
  +    |  You can walk up the tree with the #[code .ancestors] attribute, and
  +    |  check dominance with the #[+api("token#is_ancestor") #[code .is_ancestor()]]
  +    |  method.
  +
  ++aside("Projective vs. non-projective")
  +    |  For the #[+a("/docs/usage/models#available") default English model], the
  +    |  parse tree is #[strong projective], which means that there are no crossing
  +    |  brackets. The tokens returned by #[code .subtree] are therefore guaranteed
  +    |  to be contiguous. This is not true for the German model, which has many
  +    |  #[+a(COMPANY_URL + "/blog/german-model#word-order", true) non-projective dependencies].
  +
  ++code.
  +    doc = nlp(u'Credit and mortgage account holders must submit their requests')
  +    root = [token for token in doc if token.head is token][0]
       subject = list(root.lefts)[0]
       for descendant in subject.subtree:
  -        assert subject.is_ancestor_of(descendant)
  -
  -    from spacy.symbols import nsubj
  -    doc = nlp(u'Credit and mortgage account holders must submit their requests.')
  -    holders = doc[4]
  -    span = doc[holders.left_edge.i : holders.right_edge.i + 1]
  +        assert subject.is_ancestor(descendant)
  +        print(descendant.text, descendant.dep_, descendant.n_lefts, descendant.n_rights,
  +              [ancestor.text for ancestor in descendant.ancestors])
  +
  ++table(["Text", "Dep", "n_lefts", "n_rights", "ancestors"])
  +    - var style = [0, 1, 1, 1, 0]
  +    +annotation-row(["Credit", "nmod", 0, 2, "holders, submit"], style)
  +    +annotation-row(["and", "cc", 0, 0, "Credit, holders, submit"], style)
  +    +annotation-row(["mortgage", "compound", 0, 0, "account, Credit, holders, submit"], style)
  +    +annotation-row(["account", "conj", 1, 0, "Credit, holders, submit"], style)
  +    +annotation-row(["holders", "nsubj", 1, 0, "submit"], style)
  +
  +p
  +    |  Finally, the #[code .left_edge] and #[code .right_edge] attributes
  +    |  can be especially useful, because they give you the first and last token
  +    |  of the subtree. This is the easiest way to create a #[code Span] object
  +    |  for a syntactic phrase. Note that #[code .right_edge] gives a token
  +    |  #[strong within] the subtree — so if you use it as the end-point of a
  +    |  range, don't forget to #[code +1]!
  +
  ++code.
  +    doc = nlp(u'Credit and mortgage account holders must submit their requests')
  +    span = doc[doc[4].left_edge.i : doc[4].right_edge.i+1]
       span.merge()
  -    for word in doc:
  -        print(word.text, word.pos_, word.dep_, word.head.text)
  -        # Credit and mortgage account holders nsubj NOUN submit
  -        # must VERB aux submit
  -        # submit VERB ROOT submit
  -        # their DET det requests
  -        # requests NOUN dobj submit
  -
  -p
  -    |  You can get a whole phrase by its syntactic head using the
  -    |  #[code .subtree] attribute. This returns an ordered sequence of tokens.
  -    |  For the default English model, the parse tree is #[em projective], which
  -    |  means that there are no crossing brackets. The tokens returned by
  -    |  #[code .subtree] are therefore guaranteed to be contiguous. This is not
  -    |  true for the German model, which has many
  -    |  #[+a("https://explosion.ai/blog/german-model#word-order", true) non-projective dependencies].
  -    |  You can walk up the tree with the #[code .ancestors] attribute, and
  -    |  check dominance with the #[code .is_ancestor()] method.
  -
  -p
  -    |  Finally, I often find the #[code .left_edge] and #[code right_edge]
  -    |  attributes especially useful. They give you the first and last token
  -    |  of the subtree. This is the easiest way to create a #[code Span] object
  -    |  for a syntactic phrase — a useful operation.
  -
  -p
  -    |  Note that #[code .right_edge] gives a token #[em within] the subtree —
  -    |  so if you use it as the end-point of a range, don't forget to #[code +1]!
  +    for token in doc:
  +        print(token.text, token.pos_, token.dep_, token.head.text)
  +
  ++table(["Text", "POS", "Dep", "Head text"])
  +    - var style = [0, 1, 1, 0]
  +    +annotation-row(["Credit and mortgage account holders", "NOUN", "nsubj", "submit"], style)
  +    +annotation-row(["must", "VERB", "aux", "submit"], style)
  +    +annotation-row(["submit", "VERB", "ROOT", "submit"], style)
  +    +annotation-row(["their", "ADJ", "poss", "requests"], style)
  +    +annotation-row(["requests", "NOUN", "dobj", "submit"], style)
  +
  ++h(2, "displacy") Visualizing dependencies
  +
  +p
  +    |  The best way to understand spaCy's dependency parser is interactively.
  +    |  To make this easier, spaCy v2.0+ comes with a visualization module. Simply
  +    |  pass a #[code Doc] or a list of #[code Doc] objects to
  +    |  displaCy and run #[+api("displacy#serve") #[code displacy.serve]] to
  +    |  run the web server, or #[+api("displacy#render") #[code displacy.render]]
  +    |  to generate the raw markup. If you want to know how to write rules that
  +    |  hook into some type of syntactic construction, just plug the sentence into
  +    |  the visualizer and see how spaCy annotates it.
  +
  ++code.
  +    from spacy import displacy
  +
  +    doc = nlp(u'Autonomous cars shift insurance liability toward manufacturers')
  +    displacy.serve(doc, style='dep')
  +
  ++infobox
  +    |  For more details and examples, see the
  +    |  #[+a("/docs/usage/visualizers") usage workflow on visualizing spaCy]. You
  +    |  can also test displaCy in our #[+a(DEMOS_URL + "/displacy", true) online demo].
   
   +h(2, "disabling") Disabling the parser
   
  
positive.code:     |  attribute, which provides a sequence of #[+api("token") #[code Token]]
      |  objects.
  
  p
      |  A few more convenience attributes are provided for iterating around the
      |  local tree from the token. The #[code .lefts] and #[code .rights]
  
negative.code:     |  the parser from being loaded:
  
  +code.
      nlp = spacy.load('en', parser=False)
  
  p
  