Last active
February 10, 2021 18:44
-
-
Save maximtrp/def4a054a6a6bf37d6afd878721d9c4b to your computer and use it in GitHub Desktop.
MyStem Simple Wrapper Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess as sp | |
import json | |
def get_lemma(x): | |
lemma = x['analysis'][0].get('lex') if x['analysis'] else x.get('text') | |
return lemma | |
def mylem(x): | |
p = sp.Popen(['mystem', '-l', '--format', 'json'], stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.STDOUT) | |
stdout = p.communicate(input=bytes(x, encoding='utf-8')) | |
stdout = json.loads(stdout[0].decode('utf-8')) | |
return list(filter(None, map(get_lemma, stdout))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment