Disvortilo is a simple tool that breaks Esperanto words into roots and affixes.
You can install Disvortilo from PyPI using pip:
pip install disvortilofrom disvortilo import Disvortilo, rank
disvortilo = Disvortilo()
print(disvortilo.parse("malliberejo"))
# > [('mal', 'liber', 'ej', 'o')]
# some have more than one possible output
print(disvortilo.parse("esperantistino"))
# > [('esper', 'ant', 'ist', 'in', 'o'), ('esperant', 'ist', 'in', 'o')]
# you can also get the morphemes along the their categories
print(disvortilo.parse_detailed("plibonigojn"))
# > [(('pli', WordPart.FULL_WORD), ('bon', WordPart.ROOT), ('ig', WordPart.SUFFIX), ('ojn', WordPart.POS))]
# sort the values from most likely to less likely
print(rank(disvortilo.parse_detailed("envias"), n=2)) # get the 2 most likely options
# > [(('envi', WordPart.ROOT), ('as', WordPart.POS)), (('en', WordPart.FULL_WORD), ('vi', WordPart.FULL_WORD), ('as', WordPart.POS))]Parser class for splitting Esperanto words into morphemes.
Returns all valid analyses of word. Each analysis is a tuple of morpheme strings in order.
Example return value:
[('esper', 'ant', 'ist', 'in', 'o'), ('esperant', 'ist', 'in', 'o')]Like parse, but each morpheme is returned together with its detected category (WordPart). Each analysis is a tuple
of (morpheme, WordPart) pairs. The n options limits the returned options and sorts them based on a heuristic of the
most likely option.
Example return value:
[(('pli', WordPart.FULL_WORD), ('bon', WordPart.ROOT), ('ig', WordPart.SUFFIX), ('ojn', WordPart.POS))]Sorts options based on a heuristic of the most likely option.
Note, that this will only work with the returned values from parse_detailed.
Example return value:
[(('neĝ', WordPart.ROOT), ('is', WordPart.POS)), (('ne', WordPart.FULL_WORD), ('ĝis', WordPart.FULL_WORD))]Enum values used by parse_detailed:
PREFIXROOTSUFFIXFULL_WORDPOSNUMBERNAMECORRELATIVE_STARTCORRELATIVE_END
Splits a sentence into Esperanto word-like tokens. Supports Esperanto diacritics, optional trailing apostrophes, and
forms like 3 and 3an.
Example:
from disvortilo import split_sentence
split_sentence("Mi vidas 3an domon.")
# > ['Mi', 'vidas', '3an', 'domon']