Created
August 2, 2017 14:27
-
-
Save standy66/22d7adfec647f07fe25903e4bd97263d to your computer and use it in GitHub Desktop.
pymystem3 example
This file contains 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 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