Skip to content

Instantly share code, notes, and snippets.

@ctava
Created October 14, 2016 17:11
Show Gist options
  • Save ctava/628b120c5a738a9b87a7b0b7e9f12c99 to your computer and use it in GitHub Desktop.
Save ctava/628b120c5a738a9b87a7b0b7e9f12c99 to your computer and use it in GitHub Desktop.
import spacy.en
from spacy.parts_of_speech import ADV
from spacy.parts_of_speech import NOUN
nouns = ['']
adverbs = ['']
# Load the pipeline, and call it with some text.
nlp = spacy.en.English()
doc = "The quick brown fox jumps over the lazy dog"
tokens = nlp(doc, tag=True, parse=False)
for tok in tokens:
if tok.pos == NOUN:
nouns.append(tok.string)
if tok.pos == ADV:
adverbs.append(tok.string)
print("nouns: " + ', '.join(nouns))
print("\n")
print("adverbs: " + ','.join(adverbs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment