The online dictionary La Simpla Vortaro, while basing its content on the data of ReVo, also analyses the searched word for whether it could be a compound word. It can also handle compounds that have more than one interpretation, such as kolego.
The creator of simplavortaro.org, Vilfredo, explains the working principle of their approach or "algorithm" (as well as some challenges and how they solved them) in two blog posts:
The gist of it seems to be:
- remove the word type marker, if any (e.g. -o for nouns)
- generate all prefixes¹ of the thus shortened word
- of these prefixes, keep those that can be found in a list of word building parts (roots, affixes and complete² nouns and adjectives)
- for each of the kept prefixes, split it off the beginning of the word and repeat with the remainders from step 2
This generates a list of (potentially many) combinations on how the word might be built from word building parts. These combinations are weighted against each other according to the formula
badness := (number of word building parts) – 0.5 × (number of affixes)
If I'm not mistaken, as affixes are also word building parts, this is equivalent to
badness := 1 × (number of non-affix word building parts) + 0.5 × (number of affixes)
(A penalty function that is a linear combination with only positive weights might be easier to reason about.)
simplavortaro.org then displays only the two "least bad" options, with the "worse" of them second.
The website's (or web application's, if you will) code is free software (licensed under GNU AGPL 3). The part doing the segmentation and weighting seems to be the function parse_morphology(word)
from the package vortaro.morphology
.
The website's search functionality is also available through a simple RESTful API (with only a single endpoint, it seems), whose responses also include the segmentation results.
¹all strings that match the beginning of the word, not all of which necessarily are prefixes in the sense of Esperanto's word building system.
²"complete" as in: including the word type marker