AutoCorrect Service

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
John23
Posts: 13
Joined: Tue Feb 16, 2021 10:24 pm

AutoCorrect Service

Post 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.
LibreOffice 7.2.7 x64 on Windows 10 x64
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: AutoCorrect Service

Post by Villeroy »

AutoCorrect and AutoComplete intervene while you are typing. How could this be useful in a macro?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
John23
Posts: 13
Joined: Tue Feb 16, 2021 10:24 pm

Re: AutoCorrect Service

Post 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
LibreOffice 7.2.7 x64 on Windows 10 x64
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: AutoCorrect Service

Post 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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
RoryOF
Moderator
Posts: 34611
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: AutoCorrect Service

Post 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.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: AutoCorrect Service

Post 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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
John23
Posts: 13
Joined: Tue Feb 16, 2021 10:24 pm

Re: AutoCorrect Service

Post 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.
LibreOffice 7.2.7 x64 on Windows 10 x64
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: AutoCorrect Service

Post 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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Hagar Delest
Moderator
Posts: 32653
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: AutoCorrect Service

Post 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?
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: AutoCorrect Service

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
RoryOF
Moderator
Posts: 34611
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: AutoCorrect Service

Post 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.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
John23
Posts: 13
Joined: Tue Feb 16, 2021 10:24 pm

Re: AutoCorrect Service

Post 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.
LibreOffice 7.2.7 x64 on Windows 10 x64
John23
Posts: 13
Joined: Tue Feb 16, 2021 10:24 pm

Re: AutoCorrect Service

Post 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.
LibreOffice 7.2.7 x64 on Windows 10 x64
User avatar
RoryOF
Moderator
Posts: 34611
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: AutoCorrect Service

Post 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.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: AutoCorrect Service

Post 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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
John23
Posts: 13
Joined: Tue Feb 16, 2021 10:24 pm

Re: AutoCorrect Service

Post by John23 »

@RoryOF, @JeJe, thanks for your suggestions.
I'll give it a try.
LibreOffice 7.2.7 x64 on Windows 10 x64
Post Reply