Skip to content

Instantly share code, notes, and snippets.

@luismond
Last active March 15, 2019 00:33
Show Gist options
  • Select an option

  • Save luismond/f66f20c0a3e0bf679667f11fe965036b to your computer and use it in GitHub Desktop.

Select an option

Save luismond/f66f20c0a3e0bf679667f11fe965036b to your computer and use it in GitHub Desktop.
import stanfordnlp
MODELS_DIR = 'C:\\Users\\user\\stanfordnlp_resources\\'
nlp = stanfordnlp.Pipeline(processors='tokenize,pos,lemma', models_dir=MODELS_DIR, lang='es')
def get_lemmas(line):
line = nlp(line)
tagged = [[w.lemma for w in sent.words if w.pos == 'ADV' or w.pos == 'ADJ' or w.pos == 'VERB']
for sent in line.sentences]
return ' '.join([w for sent in tagged for w in sent])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment