pymorphy
First things first:
sudo pip install pymorphy
Now we need dictionaries https://bitbucket.org/kmike/pymorphy/downloads/
wget https://bitbucket.org/kmike/pymorphy/downloads/ru.sqlite-json.zip
unzip ru.sqlite-json.zip
And here is sample script:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def normalize(word):
from pymorphy import get_morph
morph_ru = get_morph('dicts/ru') # path to extracted dictionary
#word = u'менеджером'
res = morph_ru.normalize(word.upper())
for i in res:
return i.lower()
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description = 'Normalize word')
parser.add_argument('word', help = 'word to normalize')
args = parser.parse_args()
print normalize(args.word.decode('utf-8'))
Example:
$ ./normalize.py менеджерам
менеджер
$ ./normalize.py менеджеру
менеджер