Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@igor-shevchenko
Created May 18, 2017 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igor-shevchenko/ba88bbbec73c91fe29afc71072197e42 to your computer and use it in GitHub Desktop.
Save igor-shevchenko/ba88bbbec73c91fe29afc71072197e42 to your computer and use it in GitHub Desktop.
rutermextract — примеры использования параметров https://github.com/igor-shevchenko/rutermextract
# Примеры на Python 2.7
from rutermextract import TermExtractor
term_extractor = TermExtractor()
text = u'Съешь еще этих мягких французских булок да выпей же чаю'
for term in term_extractor(text):
print term.normalized
# Выводит:
# мягкие французские булки
# чай
# Параметр strings=True сразу возвращает значение term.normalized
for normalized_term in term_extractor(text, strings=True):
print normalized_term
# Выводит:
# мягкие французские булки
# чай
# Параметр words в term дает доступ к словам в виде объектов класса ParsedWord
# Описание класса: https://github.com/igor-shevchenko/rutermextract/blob/master/rutermextract/parser.py#L5
for term in term_extractor(text):
print term.words
# Выводит:
# [<rutermextract.parser.ParsedWord object at 0x044C09F0>, <rutermextract.parser.ParsedWord object at 0x044C0790>, <rutermextract.parser.ParsedWord object at 0x044C0930>]
# [<rutermextract.parser.ParsedWord object at 0x044C0B30>]
for word in term_extractor(text)[0].words:
print word.get_word(), word.get_nominal()
# Выводит:
# мягких мягкие
# французских французские
# булок булки
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment