AutoCorrect Service

Creating a macro - Writing a Script - Using the API

AutoCorrect Service

Postby John23 » Tue Feb 16, 2021 10:49 pm

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: https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=86979.
However there is no answer there regarding AutoCorrect.

Thanks.
LibreOffice 7.0.4.2 on Windows 10
John23
 
Posts: 6
Joined: Tue Feb 16, 2021 10:24 pm

Re: AutoCorrect Service

Postby Villeroy » Tue Feb 16, 2021 11:53 pm

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
User avatar
Villeroy
Volunteer
 
Posts: 29898
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: AutoCorrect Service

Postby John23 » Wed Feb 17, 2021 12:49 pm

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   Expand viewCollapse view
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.0.4.2 on Windows 10
John23
 
Posts: 6
Joined: Tue Feb 16, 2021 10:24 pm

Re: AutoCorrect Service

Postby Villeroy » Wed Feb 17, 2021 1:04 pm

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
Villeroy
Volunteer
 
Posts: 29898
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: AutoCorrect Service

Postby RoryOF » Wed Feb 17, 2021 1:27 pm

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.10 on Xubuntu 20.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 32682
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: AutoCorrect Service

Postby JeJe » Wed Feb 17, 2021 1:36 pm

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.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1565
Joined: Wed Mar 09, 2016 2:40 pm

Re: AutoCorrect Service

Postby John23 » Wed Feb 17, 2021 1:50 pm

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.0.4.2 on Windows 10
John23
 
Posts: 6
Joined: Tue Feb 16, 2021 10:24 pm

Re: AutoCorrect Service

Postby JeJe » Wed Feb 17, 2021 1:56 pm

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.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1565
Joined: Wed Mar 09, 2016 2:40 pm

Re: AutoCorrect Service

Postby Hagar Delest » Wed Feb 17, 2021 1:57 pm

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.0.5 on Xubuntu 21.04 and 7.0.5 portable on Windows 10
User avatar
Hagar Delest
Moderator
 
Posts: 29817
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: AutoCorrect Service

Postby Villeroy » Wed Feb 17, 2021 2:00 pm

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
Villeroy
Volunteer
 
Posts: 29898
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: AutoCorrect Service

Postby RoryOF » Wed Feb 17, 2021 2:09 pm

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.10 on Xubuntu 20.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 32682
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: AutoCorrect Service

Postby John23 » Wed Feb 17, 2021 2:13 pm

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.0.4.2 on Windows 10
John23
 
Posts: 6
Joined: Tue Feb 16, 2021 10:24 pm

Re: AutoCorrect Service

Postby John23 » Wed Feb 17, 2021 2:25 pm

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.0.4.2 on Windows 10
John23
 
Posts: 6
Joined: Tue Feb 16, 2021 10:24 pm

Re: AutoCorrect Service

Postby RoryOF » Wed Feb 17, 2021 2:34 pm

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.10 on Xubuntu 20.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 32682
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: AutoCorrect Service

Postby JeJe » Wed Feb 17, 2021 2:37 pm

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.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1565
Joined: Wed Mar 09, 2016 2:40 pm

Re: AutoCorrect Service

Postby John23 » Wed Feb 17, 2021 3:50 pm

@RoryOF, @JeJe, thanks for your suggestions.
I'll give it a try.
LibreOffice 7.0.4.2 on Windows 10
John23
 
Posts: 6
Joined: Tue Feb 16, 2021 10:24 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 8 guests