mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-29 02:34:08 +03:00
Fix consistency of imports from spacy.tokens in examples
This commit is contained in:
parent
bfd58dd0fc
commit
f4ae6763b9
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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):
|
||||||
|
|
|
@ -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):
|
||||||
|
|
|
@ -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')
|
||||||
|
|
||||||
|
|
|
@ -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')
|
||||||
|
|
||||||
|
|
|
@ -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')
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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'
|
||||||
|
|
||||||
|
|
|
@ -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')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user