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 __future__ import unicode_literals
from spacy.lang.en import English from spacy.lang.en import English
from spacy.tokens.doc import Doc from spacy.tokens import Doc, Span
from spacy.tokens.span import Span
from spacy import displacy from spacy import displacy
from pathlib import Path from pathlib import Path

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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