anchor.diff:      |  The following examples and code snippets give you an overview of spaCy's
       |  functionality and its usage.
   
  -+h(2, "models") Install and load models
  ++h(2, "models") Install models and process text
   
   +code(false, "bash").
       python -m spacy download en
  +    python -m spacy download de
   
   +code.
       import spacy
       nlp = spacy.load('en')
  -
  -+h(2, "examples-resources") Load resources and process text
  +    doc = nlp(u'Hello, world. Here are two sentences.')
  +
  +    nlp_de = spacy.load('de')
  +    doc_de = nlp_de(u'Ich bin ein Berliner.')
  +
  ++infobox
  +    |  #[strong API:] #[+api("spacy#load") #[code spacy.load()]]
  +    |  #[strong Usage:] #[+a("/docs/usage/models") Models],
  +    |  #[+a("/docs/usage/spacy-101") spaCy 101]
  +
  ++h(2, "examples-tokens-sentences") Get tokens, noun chunks & sentences
  +    +tag-model("dependency parse")
  +
  ++code.
  +    doc = nlp(u"Peach emoji is where it has always been. Peach is the superior "
  +              u"emoji. It's outranking eggplant 🍑 ")
  +
  +    assert doc[0].text == u'Peach'
  +    assert doc[1].text == u'emoji'
  +    assert doc[-1].text == u'🍑'
  +    assert doc[17:19] == u'outranking eggplant'
  +    assert doc.noun_chunks[0].text == u'Peach emoji'
  +
  +    sentences = list(doc.sents)
  +    assert len(sentences) == 3
  +    assert sentences[0].text == u'Peach is the superior emoji.'
  +
  ++infobox
  +    |  #[strong API:] #[+api("doc") #[code Doc]], #[+api("token") #[code Token]]
  +    |  #[strong Usage:] #[+a("/docs/usage/spacy-101") spaCy 101]
  +
  ++h(2, "examples-pos-tags") Get part-of-speech tags and flags
  +    +tag-model("tagger")
  +
  ++code.
  +    doc = nlp(u'Apple is looking at buying U.K. startup for $1 billion')
  +    apple = doc[0]
  +    assert [apple.pos_, apple.pos] == [u'PROPN', 94]
  +    assert [apple.tag_, apple.tag] == [u'NNP', 475]
  +    assert [apple.shape_, apple.shape] == [u'Xxxxx', 684]
  +    assert apple.is_alpha == True
  +    assert apple.is_punct == False
  +
  +    billion = doc[10]
  +    assert billion.is_digit == False
  +    assert billion.like_num == True
  +    assert billion.like_email == False
  +
  ++infobox
  +    |  #[strong API:] #[+api("token") #[code Token]]
  +    |  #[strong Usage:] #[+a("/docs/usage/pos-tagging") Part-of-speech tagging]
  +
  ++h(2, "examples-integer-ids") Use integer IDs for any string
  +
  ++code.
  +    hello_id = nlp.vocab.strings['Hello']
  +    hello_str = nlp.vocab.strings[hello_id]
  +    assert token.text  == hello_id  == 3125
  +    assert token.text == hello_str == 'Hello'
  +
  ++h(2, "examples-entities") Recongnise and update named entities
  +    +tag-model("NER")
  +
  ++code.
  +    doc = nlp(u'San Francisco considers banning sidewalk delivery robots')
  +    ents = [(e.text, e.start_char, e.end_char, e.label_) for e in doc.ents]
  +    assert ents == [(u'San Francisco', 0, 13, u'GPE')]
  +
  +    from spacy.tokens import Span
  +    doc = nlp(u'Netflix is hiring a new VP of global policy')
  +    doc.ents = [Span(doc, 0, 1, label=doc.vocab.strings[u'ORG'])]
  +    ents = [(e.start_char, e.end_char, e.label_) for ent in doc.ents]
  +    assert ents == [(0, 7, u'ORG')]
  +
  ++infobox
  +    |  #[strong Usage:] #[+a("/docs/usage/entity-recognition") Named entity recognition]
  +
  ++h(2, "displacy") Visualize a dependency parse and named entities in your browser
  +    +tag-model("dependency parse", "NER")
  +
  ++code.
  +    from spacy import displacy
  +
  +    doc_dep = nlp(u'This is a sentence.')
  +    displacy.serve(doc_dep, style='dep')
  +
  +    doc_ent = nlp(u'When Sebastian Thrun started working on self-driving cars at '
  +                  u'Google in 2007, few people outside of the company took him seriously.')
  +    displacy.serve(doc_ent, style='ent')
  +
  ++infobox
  +    |  #[strong API:] #[+api("displacy") #[code displacy]]
  +    |  #[strong Usage:] #[+a("/docs/usage/visualizers") Visualizers]
  +
  ++h(2, "examples-word-vectors") Word vectors
  +    +tag-model("word vectors")
  +
  ++code.
  +    doc = nlp(u"Apple and banana are similar. Pasta and hippo aren't.")
  +    apple = doc[0]
  +    banana = doc[2]
  +    pasta = doc[6]
  +    hippo = doc[8]
  +    assert apple.similarity(banana) > pasta.similarity(hippo)
  +
  ++infobox
  +    |  #[strong Usage:] #[+a("/docs/usage/word-vectors-similarities") Word vectors and similarity]
  +
  ++h(2, "examples-serialization") Simple and efficient serialization
   
   +code.
       import spacy
  -    en_nlp = spacy.load('en')
  -    de_nlp = spacy.load('de')
  -    en_doc = en_nlp(u'Hello, world. Here are two sentences.')
  -    de_doc = de_nlp(u'ich bin ein Berliner.')
  -
  -+h(2, "displacy-dep") Visualize a dependency parse in your browser
  -
  -+code.
  -    from spacy import displacy
  -
  -    doc = nlp(u'This is a sentence.')
  -    displacy.serve(doc, style='dep')
  -
  -+h(2, "displacy-ent") Visualize named entities in your browser
  -
  -+code.
  -    from spacy import displacy
  -
  -    doc = nlp(u'When Sebastian Thrun started working on self-driving cars at '
  -              u'Google in 2007, few people outside of the company took him seriously.')
  -    displacy.serve(doc, style='ent')
  +    from spacy.tokens.doc import Doc
  +
  +    nlp = spacy.load('en')
  +    moby_dick = open('moby_dick.txt', 'r')
  +    doc = nlp(moby_dick)
  +    doc.to_disk('/moby_dick.bin')
  +
  +    new_doc = Doc().from_disk('/moby_dick.bin')
  +
  ++infobox
  +    |  #[strong Usage:] #[+a("/docs/usage/saving-loading") Saving and loading]
   
   +h(2, "multi-threaded") Multi-threaded generator
   
  
positive.code:         if i == 100:
              break
  
  +h(2, "examples-tokens-sentences") Get tokens and sentences
  
  +code.
      token = doc[0]
      sentence = next(doc.sents)
      assert token is sentence[0]
      assert sentence.text == 'Hello, world.'
  
  +h(2, "examples-integer-ids") Use integer IDs for any string
  
  +code.
      hello_id = nlp.vocab.strings['Hello']
      hello_str = nlp.vocab.strings[hello_id]
  
      assert token.orth  == hello_id  == 3125
      assert token.orth_ == hello_str == 'Hello'
  
  +h(2, "examples-string-views-flags") Get and set string views and flags
  
  +code.
      assert token.shape_ == 'Xxxxx'
      for lexeme in nlp.vocab:
          if lexeme.is_alpha:
              lexeme.shape_ = 'W'
          elif lexeme.is_digit:
              lexeme.shape_ = 'D'
          elif lexeme.is_punct:
              lexeme.shape_ = 'P'
          else:
              lexeme.shape_ = 'M'
      assert token.shape_ == 'W'
  
  +h(2, "examples-numpy-arrays") Export to numpy arrays
  
  
negative.code:         string = string.replace('\n', '')
          string = string.replace('\t', '    ')
          return string
  