A macOS text service for morphological analysis and in situ marking of Russian syllabic stress

Building on my earlier explorations of the UDAR project, I’ve created a macOS Service-like method for in-situ marking of syllabic stress in arbitrary Russian text.

The Keyboard Maestro is simple; we execute the following script, bracketed by Copy and Paste:

#!/Users/alan/.pyenv/shims/python3
import xerox
import udar
import re

rawText = xerox.paste()
doc1 = udar.Document(rawText, disambiguate=True)
searchText = doc1.stressed()
result = re.sub(r'( ,)', ",", searchText)
xerox.copy(result)

This presumes that udar and its prerequisites have already been installed, of course.

So why not build out this idea as an actual macOS text service? In theory, it should be possible. Maybe even ideal but for Python version management I use pyenv. Because some of the UDAR dependencies will not run under my current system Python version of 3.8.5, I use 3.7.4 under pyenv and it appears that the correct Python version run under whatever environment the service launches. Someone with deeper system knowledge could undoubtedly figure it out; but instead I accomplished the same effect via a Keyboard Maestro macro.

Solzhenitsyn on the folly of looking for good/evil dichotomies

Постепенно открылось мне, что линия, разделяющая добро и зло, проходит не между государствами, не между классами, не между партиями, — она проходит через каждое человеческое сердце — и черезо все человеческие сердца. Линия эта подвижна, она колеблется в нас с годами. Даже в сердце, объятом злом, она удерживает маленький плацдарм добра. Даже в наидобрейшем сердце — неискоренённый уголок зла.

Alexander Solzhenitsyn Gulag Archipelago

My rough translation to English:

“Gradually it was revealed to me that the line separating good from evil passes not between States, nor between classes or parties. It passes through every human heart. The line shifts; it oscillates in us with the years. Even in a heart overwhelmed by evil, it retains a small bridgehead of good. Even the kindest hearts, there is an corner of evil not uprooted.”

Solzhenitsyn is Luke Skywalker on the forest moon confronting Vader: “I know there is still good in you.”