Getting things ready
First, you will need to install UralicNLP like so:
sudo pip install uralicNLP
Next, run the following python script to download the Finnish model
from uralicNLP import uralicApi
uralicApi.download("fin")
Now you have everything ready to use Omorfi in Python. ☺️
Analysing Finnish morphology
You can use the analyze function provided in uralicApi to analyse a given word morphologically.
from uralicNLP import uralicApi
uralicApi.analyze("hattunikin", "fin")
>> (('hattu+N+Pl+Nom+PxSg1+Foc/kin', 0.0), ('hattu+N+Sg+Gen+PxSg1+Foc/kin', 0.0), ('hattu+N+Sg+Nom+PxSg1+Foc/kin', 0.0))
For hattu, Omorfi will produce the correct readings as it being in genitive or nominative in singular or in nominative in plural. The numbers at the end of each analysis are weights, however, weights are currently not implemented in Omorfi.
Inflecting Finnish words
Omorfi can also be used in generation of surface forms given an abstract morphological representation. This generation is also known as morphological inflection.
from uralicNLP import uralicApi
uralicApi.generate("hattu+N+Sg+Abl", "fin")
>> (('hatulta', 0.0),)
This inflects the word hattu correctly in ablative. You can use the analyze function on different word forms to see what the morphology looks like for generation.
If you are more interested in inflecting full sentences instead of individual words, you might want to look at my syntax maker tutorial.
Don't forget to cite
If you use Omorfi and UralicNLP in a scientific publication, please remember to cite them. 🙂
For UralicNLP, use
Hämäläinen, Mika. (2019). UralicNLP: An NLP Library for Uralic Languages. Journal of open source software, 4(37), [1345]. https://doi.org/10.21105/joss.01345
For Omorfi, use
Pirinen, Tommi A ; Listenmaa, Inari ; Johnson, Ryan ; Tyers, Francis M. ; Kuokkala, Juha Open morphology of Finnish, (2017) PID: http://hdl.handle.net/11372/LRT-1992