How to implement cases in LibreOffice?
I have a surname, let’s say Ivanov, Semenov. How can I automate changing the name to Ivanova, Semenova? That is, to the accusative case?
Yes, this must be done in the Ukrainian language.
I tried using pymorphy2, installed the necessary libraries in python, copied the pymorphy2 and pymorphy2_dicts_uk folders to /usr/lib/libreoffice/share/Scripts/python and created a script
import pymorphy2
# Ініціалізуємо морфологічний аналізатор
morph = pymorphy2.MorphAnalyzer(lang='uk')
def change_case(word, case):
# Розбираємо слово
parsed = morph.parse(word)[0]
# Перевіряємо, чи можна відмінювати у вказаному відмінку
if case in parsed.tag.cases:
inflected = parsed.inflect({case})
if inflected:
return inflected.word
return word
but I did not find how to execute the script.
I also tried the following code through basic
Function ChangeCase(word As String, caseType As String) As String
Dim scriptProvider As Object
Dim pythonScript As Object
' Отримання доступу до Python-скриптів
scriptProvider = ThisComponent.getScriptProvider()
pythonScript = scriptProvider.getScript("vnd.sun.star.script:morphology.change_case?language=Python&location=user")
' Виклик Python-функції з параметрами
Dim args(1) As Variant
args(0) = word
args(1) = caseType
ChangeCase = pythonScript.invoke(args)
End Function
It gave an error…