mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-05 12:50:20 +03:00
docs: Use actual constants from parts_of_speech
* It turns out `ADVERB` is not in `parts_of_speech` Signed-off-by: mr.Shu <mr@shu.io>
This commit is contained in:
parent
48447d7355
commit
202f74aeff
|
@ -184,14 +184,14 @@ adverbs to. Recall that our previous adverb highlighting function looked like
|
||||||
this:
|
this:
|
||||||
|
|
||||||
>>> import spacy.en
|
>>> import spacy.en
|
||||||
>>> from spacy.parts_of_speech import ADVERB
|
>>> from spacy.parts_of_speech import ADV
|
||||||
>>> # Load the pipeline, and call it with some text.
|
>>> # Load the pipeline, and call it with some text.
|
||||||
>>> nlp = spacy.en.English()
|
>>> nlp = spacy.en.English()
|
||||||
>>> tokens = nlp("‘Give it back,’ he pleaded abjectly, ‘it’s mine.’",
|
>>> tokens = nlp("‘Give it back,’ he pleaded abjectly, ‘it’s mine.’",
|
||||||
tag=True, parse=True)
|
tag=True, parse=True)
|
||||||
>>> output = ''
|
>>> output = ''
|
||||||
>>> for tok in tokens:
|
>>> for tok in tokens:
|
||||||
... output += tok.string.upper() if tok.pos == ADVERB else tok.string
|
... output += tok.string.upper() if tok.pos == ADV else tok.string
|
||||||
... output += tok.whitespace
|
... output += tok.whitespace
|
||||||
>>> print(output)
|
>>> print(output)
|
||||||
‘Give it BACK,’ he pleaded ABJECTLY, ‘it’s mine.’
|
‘Give it BACK,’ he pleaded ABJECTLY, ‘it’s mine.’
|
||||||
|
@ -206,9 +206,9 @@ problematic, given our starting assumptions:
|
||||||
>>> from numpy import dot
|
>>> from numpy import dot
|
||||||
>>> from numpy.linalg import norm
|
>>> from numpy.linalg import norm
|
||||||
>>> import spacy.en
|
>>> import spacy.en
|
||||||
>>> from spacy.parts_of_speech import ADVERB, VERB
|
>>> from spacy.parts_of_speech import ADV, VERB
|
||||||
>>> def is_bad_adverb(token, target_verb, tol):
|
>>> def is_bad_adverb(token, target_verb, tol):
|
||||||
... if token.pos != ADVERB
|
... if token.pos != ADV
|
||||||
... return False
|
... return False
|
||||||
... elif toke.head.pos != VERB:
|
... elif toke.head.pos != VERB:
|
||||||
... return False
|
... return False
|
||||||
|
|
Loading…
Reference in New Issue
Block a user