Skip to content

Instantly share code, notes, and snippets.

@standy66
Created August 2, 2017 14:27
Show Gist options
  • Save standy66/22d7adfec647f07fe25903e4bd97263d to your computer and use it in GitHub Desktop.
Save standy66/22d7adfec647f07fe25903e4bd97263d to your computer and use it in GitHub Desktop.
pymystem3 example
import sys, re, pymystem3
mystem = pymystem3.Mystem()
def stem(s):
return [(e['text'].strip(), \
e['analysis'][0]['lex'] \
if 'analysis' in e and len(e['analysis']) > 0 else '', \
re.match('^([A-Z]+)', e['analysis'][0]['gr']).group(0) \
if 'analysis' in e and len(e['analysis']) > 0 else '', \
','.join(set(re.findall(r"[\w']+", e['analysis'][0]['gr'])[1:])) \
if 'analysis' in e and len(e['analysis']) > 0 else '')\
for e in mystem.analyze(s) if len(e['text'].strip()) > 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment