It’s probably worth describing the whole process.
- Installed pymorphy2 (but installed it in a virtual directory, since it should work on a Windows PC as well).
- Taking into account that I installed it in a virtual directory, I copied the folders pymorphy2, pymorphy2-0.9.1.dist-info, pymorphy2_dicts_uk and pymorphy2_dicts_uk-2.4.1.1.1460299261.dist-info to /usr/lib/libreoffice/share/Scripts/python
- In the /usr/lib/libreoffice/share/Scripts/python folder, create a cod.py file with the following contents:
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
Then I needed to go to Tools > Macros > Organize Macros > Python, select the created script, and select the change_case function. But I don’t have Tools > Macros > Organize Macros > Python, I only have BASIC
So, I tried to create a Basic function that calls a Python script.
I created a new module and added the following Basic code:
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
I entered =ChangeCase(A1; “родовий”) in the necessary cells, since it did not work, I also tried =ChangeCase(A1; “datv”)
And got the above errors…
I don’t know what to do next, so I created this thread.
P&s. The text was translated with the help of several services, so it may not be completely correct. I apologize in advance.