Fix consistency of imports from spacy.tokens in examples

This commit is contained in:
ines 2017-10-11 02:30:40 +02:00
parent bfd58dd0fc
commit f4ae6763b9
10 changed files with 16 additions and 23 deletions

View File

@ -6,8 +6,7 @@ they're called on is passed in as the first argument."""
from __future__ import unicode_literals
from spacy.lang.en import English
from spacy.tokens.doc import Doc
from spacy.tokens.span import Span
from spacy.tokens import Doc, Span
from spacy import displacy
from pathlib import Path

View File

@ -5,9 +5,7 @@ import requests
from spacy.lang.en import English
from spacy.matcher import PhraseMatcher
from spacy.tokens.doc import Doc
from spacy.tokens.span import Span
from spacy.tokens.token import Token
from spacy.tokens import Doc, Span, Token
class RESTCountriesComponent(object):

View File

@ -3,9 +3,7 @@ from __future__ import unicode_literals
from spacy.lang.en import English
from spacy.matcher import PhraseMatcher
from spacy.tokens.doc import Doc
from spacy.tokens.span import Span
from spacy.tokens.token import Token
from spacy.tokens import Doc, Span, Token
class TechCompanyRecognizer(object):

View File

@ -148,7 +148,7 @@ p
| #[+a("/usage/processing-pipelines#custom-components-attributes") custom attributes].
+aside-code("Example").
from spacy.tokens.doc import Doc
from spacy.tokens import Doc
city_getter = lambda doc: doc.text in ('New York', 'Paris', 'Berlin')
Doc.set_extension('has_city', getter=city_getter)
doc = nlp(u'I like New York')
@ -201,7 +201,7 @@ p
| registered. Raises a #[code KeyError] otherwise.
+aside-code("Example").
from spacy.tokens.doc import Doc
from spacy.tokens import Doc
Doc.set_extension('is_city', default=False)
extension = Doc.get_extension('is_city')
assert extension == (False, None, None, None)
@ -226,7 +226,7 @@ p
p Check whether an extension has been registered on the #[code Doc] class.
+aside-code("Example").
from spacy.tokens.doc import Doc
from spacy.tokens import Doc
Doc.set_extension('is_city', default=False)
assert Doc.has_extension('is_city')

View File

@ -126,7 +126,7 @@ p
| #[+a("/usage/processing-pipelines#custom-components-attributes") custom attributes].
+aside-code("Example").
from spacy.tokens.span import Span
from spacy.tokens import Span
city_getter = lambda span: span.text in ('New York', 'Paris', 'Berlin')
Span.set_extension('has_city', getter=city_getter)
doc = nlp(u'I like New York in Autumn')
@ -179,7 +179,7 @@ p
| registered. Raises a #[code KeyError] otherwise.
+aside-code("Example").
from spacy.tokens.span import Span
from spacy.tokens import Span
Span.set_extension('is_city', default=False)
extension = Span.get_extension('is_city')
assert extension == (False, None, None, None)
@ -204,7 +204,7 @@ p
p Check whether an extension has been registered on the #[code Span] class.
+aside-code("Example").
from spacy.tokens.span import Span
from spacy.tokens import Span
Span.set_extension('is_city', default=False)
assert Span.has_extension('is_city')

View File

@ -61,7 +61,7 @@ p
| #[+a("/usage/processing-pipelines#custom-components-attributes") custom attributes].
+aside-code("Example").
from spacy.tokens.token import Token
from spacy.tokens import Token
fruit_getter = lambda token: token.text in ('apple', 'pear', 'banana')
Token.set_extension('is_fruit', getter=fruit_getter)
doc = nlp(u'I have an apple')
@ -114,7 +114,7 @@ p
| registered. Raises a #[code KeyError] otherwise.
+aside-code("Example").
from spacy.tokens.token import Token
from spacy.tokens import Token
Token.set_extension('is_fruit', default=False)
extension = Token.get_extension('is_fruit')
assert extension == (False, None, None, None)
@ -139,7 +139,7 @@ p
p Check whether an extension has been registered on the #[code Token] class.
+aside-code("Example").
from spacy.tokens.token import Token
from spacy.tokens import Token
Token.set_extension('is_fruit', default=False)
assert Token.has_extension('is_fruit')

View File

@ -146,9 +146,7 @@ p
| been registered, spaCy will raise an #[code AttributeError].
+code("Example").
from spacy.tokens.token import Token
from spacy.tokens.doc import Doc
from spacy.tokens.span import Span
from spacy.tokens import Doc, Span, Token
fruits = ['apple', 'pear', 'banana', 'orange', 'strawberry']
is_fruit_getter = lambda token: token.text in fruits

View File

@ -46,7 +46,7 @@ p
+code-wrapper
+code-new.
from spacy.tokens.doc import Doc
from spacy.tokens import Doc
def __init__(attr='my_attr'):
Doc.set_extension(attr, getter=self.get_doc_attr)
+code-old.

View File

@ -21,7 +21,7 @@ p
+code.
import spacy
from spacy.tokens.span import Span
from spacy.tokens import Span
text = u'Netflix is hiring a new VP of global policy'

View File

@ -175,7 +175,7 @@ p
+code.
import spacy
from spacy.tokens.doc import Doc
from spacy.tokens import Doc
from spacy.vocab import Vocab
nlp = spacy.load('en')