Page 1 of 1

AutoCorrect Service

Posted: Tue Feb 16, 2021 10:49 pm
by John23
Hi OO Forum,

I'm stuck with implementation of AutoCorrect function using UNO API to work with LibreOffice Writer.
Is there a service or solution to perform same action as Tools -> AutoCorrect -> Apply.
This question is certainly a part of this topic: viewtopic.php?f=20&t=86979.
However there is no answer there regarding AutoCorrect.

Thanks.

Re: AutoCorrect Service

Posted: Tue Feb 16, 2021 11:53 pm
by Villeroy
AutoCorrect and AutoComplete intervene while you are typing. How could this be useful in a macro?

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 12:49 pm
by John23
I guess it's useful because there is such option to apply autocorrection for existing text in LibreOffice itself, isn't it?

E.g. insert already preformatted text (*text*, _text_, -text-) into range and apply autocorrection afterwards.

Btw the question is not about macro but about UNO API service.

I foresee answer about macro recording.
However DispatchHelper is no go for me.

Code: Select all

sub Autocorrect
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:AutoFormatApply", "", 0, Array())

end sub

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 1:04 pm
by Villeroy
If you want to manipulate strings, you do not need any office suite. A mature script language like Perl or Python does a much better job.

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 1:27 pm
by RoryOF
Also, unsupervised autocorrect might leave a document in a less intelligible state than originally. Any potential autocorrection will need intelligent steering if multiple choices are offered.

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 1:36 pm
by JeJe
E.g. insert already preformatted text (*text*, _text_, -text-) into range and apply autocorrection afterwards.
That looks like a markup language like Markdown. Is what you want to do here just a series of find/replace in code? That doesn't need autocorrect...


Edit: I started the thread you linked to in your opening post because I wanted to implement autocorrect in dialog textboxes. I couldn't work out how to access the autocorrect list of words (except the file where they're stored) and I ended up writing my own separate replacement autocorrect code for textboxes using a collection object to store the list of words.

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 1:50 pm
by John23
I have just mentioned simplest use case in order to answer the question "Why?".
What I want is to use all existing AutoCorrect features if it is possible.

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 1:56 pm
by JeJe
If the answers remains... (as per that previous thread)... that no-one here knows how to access the autocorrect... and maybe you just can't... what are you trying to do exactly? I'm asking so we can perhaps help you solve the problem in a different way.

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 1:57 pm
by Hagar Delest
John23 wrote:E.g. insert already preformatted text (*text*, _text_, -text-) into range and apply autocorrection afterwards.
To do something like in this topic: [Solved] Taking note and tagging format?

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 2:00 pm
by Villeroy

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 2:09 pm
by RoryOF
Just for information: the acor_en-GB.dat file (modify according to language used) is a zip file; it contains several .xml files of which DocumentList.xml seems to be the file with the match words and their suggested replacements. It is in alphabetical order.

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 2:13 pm
by John23
No need to hold to that example so much.
What I need is to support ALL the rules from built in AutoCorrect options.
Perhaps even user defined, that was added through application.

I'm building framework on top of UNO API to work with LibreOffice to generate reports.
Input text is black box for me. I don't have an info about what rules exactly from AutoCorrect I need.
If I knew that, I would have implemented a simple replace function.

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 2:25 pm
by John23
RoryOF wrote:Also, unsupervised autocorrect might leave a document in a less intelligible state than originally. Any potential autocorrection will need intelligent steering if multiple choices are offered.
Yeah, this is a very good point of revising the idea itself.
JeJe wrote:Edit: I started the thread you linked to in your opening post because I wanted to implement autocorrect in dialog textboxes. I couldn't work out how to access the autocorrect list of words (except the file where they're stored) and I ended up writing my own separate replacement autocorrect code for textboxes using a collection object to store the list of words.
I guess I will end up with some custom replacement function after all.

Thanks.

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 2:34 pm
by RoryOF
One could open DocumentList.xml, parse it into a Python 'dict' structure, then pass through the test file making lookups and replacements from the Python dictionary just built. That would be the first step. Then one could examine the other files in acor_en-GB.dat and consider implementing their changes, integrating with the file pass-through code already written.

I'm not a Python expert, but I think that language would lend itself better to the project than BASIC.

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 2:37 pm
by JeJe
An alternative auto-correct system shouldn't be too hard - a keyhandler to look at what's typed against a list of replacements - then replace appropriately, with a dialog to edit the word list.

Re: AutoCorrect Service

Posted: Wed Feb 17, 2021 3:50 pm
by John23
@RoryOF, @JeJe, thanks for your suggestions.
I'll give it a try.