OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Request for a macro: add words to spell checker dictionary

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
hanslist
General User
General User


Joined: 10 Apr 2012
Posts: 6

PostPosted: Tue Apr 10, 2012 11:49 am    Post subject: Request for a macro: add words to spell checker dictionary Reply with quote

Hi,

I am using CafeTran, a translation editor written in Java that is using the OpenOffice spelling checker.

When I add a word with an unknown spelling in OOW to standard.dic the spelling of this word is known in CafeTran too.

My request is this:

- Would somebody please be so helpful as to write a macro that I can use to add all words with unknown spelling automatically to standard.dic?

I'd feed the macro with a list of Dutch words, each word on a separate line, known and unknown words mixed. I think the list will be about 100,000 words long.

Thanks in advance for your help!

Hans
Back to top
View user's profile Send private message
floris_v
Moderator
Moderator


Joined: 12 Jul 2007
Posts: 4599
Location: Netherlands

PostPosted: Tue Apr 10, 2012 11:54 am    Post subject: Reply with quote

That's a bit roundabout, isn't it? You can also open that file in Notepad or something similar and add the words yourself in one fell swoop. Make a copy first and experiment with that in case the file gets corrupted.
_________________
LibreOffice 3.6.3; OOo 3.4.1 on Windows Vista
Join the Official community forum - in several languages, including Nederlandstalig forum
Back to top
View user's profile Send private message
hanslist
General User
General User


Joined: 10 Apr 2012
Posts: 6

PostPosted: Tue Apr 10, 2012 12:12 pm    Post subject: Unknown words are mixed with known words Reply with quote

The list is huge: words with known spelling are mixed with words with unknown spelling.

If I had a list containing only the unknown words, I would indeed follow your suggestion.
Back to top
View user's profile Send private message
probe1
Moderator
Moderator


Joined: 18 Aug 2004
Posts: 2465
Location: Chonburi Thailand Asia

PostPosted: Tue Apr 10, 2012 8:30 pm    Post subject: Reply with quote

Last time I checked there was a limit of 64k words to such a dictionary.


For your request:
add2dicAuto

add2dicAuto wrote:
Automatically add to dictionary.

Add all the marked words (red curly underlined) to your standard dictionary

Generates a simple writer document to log the added words.

To change the dictionary change it's name in source code.

_________________
Cheers
Winfried
My Macros
DateTime2 extension: insert date, time or timestamp, formatted to your needs
Back to top
View user's profile Send private message Visit poster's website
Tommy27
OOo Advocate
OOo Advocate


Joined: 18 Nov 2006
Posts: 300

PostPosted: Tue Apr 10, 2012 9:59 pm    Post subject: Reply with quote

probe1 wrote:
Last time I checked there was a limit of 64k words to such a dictionary.


yes, and I was the one who discovered it...

see: https://issues.apache.org/ooo/show_bug.cgi?id=87672
Back to top
View user's profile Send private message
hanslist
General User
General User


Joined: 10 Apr 2012
Posts: 6

PostPosted: Tue Apr 10, 2012 10:36 pm    Post subject: Thanks for the macro Reply with quote

Thanks for writing this macro!

Hans Very Happy
Back to top
View user's profile Send private message
hanslist
General User
General User


Joined: 10 Apr 2012
Posts: 6

PostPosted: Tue Apr 10, 2012 11:04 pm    Post subject: Got error Reply with quote

Sorry to report this but I got an error message:


http://dl.dropbox.com/u/509643/Clients/Screen%20Shot%202012-04-11%20at%209.02.13%20AM.png

BASIC runtime error
Incorrect property value

at 'If Not_' in Wort markieren.

Alas I'm not familiar with OO BASIC at all ... How can I avoid this error?

Thanks,

Hans
Back to top
View user's profile Send private message
karolus
OOo Advocate
OOo Advocate


Joined: 22 Jun 2011
Posts: 208

PostPosted: Wed Apr 11, 2012 12:47 am    Post subject: Reply with quote

Hi
Delete the Space after _
or change to
if not paste here the next line of code

Karo
Back to top
View user's profile Send private message
hanslist
General User
General User


Joined: 10 Apr 2012
Posts: 6

PostPosted: Wed Apr 11, 2012 1:08 am    Post subject: Help still needed Reply with quote

karolus wrote:
Hi
Delete the Space after _
or change to
if not paste here the next line of code

Karo


Hi,

Thanks for looking into this. I've placed everything after the If Not on one line, but there is still an error:


http://dl.dropbox.com/u/509643/Clients/Screen%20Shot%202012-04-11%20at%2011.02.35%20AM.png


I must admit that I don't understand why there are 2 '))' before the Then ...

Hans
Back to top
View user's profile Send private message
karolus
OOo Advocate
OOo Advocate


Joined: 22 Jun 2011
Posts: 208

PostPosted: Wed Apr 11, 2012 2:23 am    Post subject: Reply with quote

Hi
What for are these silly Screenshots -- copy and paste exists.



The last ) close the first ( in that line.

But i have no guess about the Error

Karo
Back to top
View user's profile Send private message
hanslist
General User
General User


Joined: 10 Apr 2012
Posts: 6

PostPosted: Wed Apr 11, 2012 4:41 am    Post subject: Re: Help still needed /FIXED Reply with quote

Found another macro:

Code:
Sub WrongWordsList
    oDocModel = ThisComponent
    If IsNull(oDocModel) Then
        MsgBox("There's no active document.")
        Exit Sub
    End If

    If Not HasUnoInterfaces (oDocModel, "com.sun.star.text.XTextDocument") Then
        MsgBox("This document doesn't support the 'XTextDocument' interface.")
        Exit Sub
    End If

    oTextCursor = oDocModel.Text.createTextCursor()
    oTextCursor.gotoStart(False)

    oLinguSvcMgr = createUnoService("com.sun.star.linguistic2.LinguServiceManager")
    If Not IsNull(oLinguSvcMgr) Then
        oSpellChk = oLinguSvcMgr.getSpellChecker()
    End If
    If IsNull (oSpellChk) Then
        MsgBox("It's not possible to access to the spellcheck.")
        Exit Sub
    End If
       
    Do
        If oTextCursor.isStartOfWord() Then
            oTextCursor.gotoEndOfWord(True)
            oCharLoc = oTextCursor.getPropertyValue("CharLocale")
            If Not isEmpty (oCharLoc) Then
               If Not oSpellChk.com_sun_star_linguistic2_XSpellChecker_isValid(oTextCursor.getString(),oCharLoc, Array()) Then
                  sListaPalabras = sListaPalabras + oTextCursor.getString() + Chr(13)
               End If
            End If
            oTextCursor.collapseToEnd()
        End If
    Loop While oTextCursor.gotoNextWord(False)
       
    If Len(sListaPalabras) = 0 Then
        MsgBox("There are no errors in the document.")
        Exit Sub
    End If

    oListDocModel = StarDesktop.loadComponentFromURL("private:factory/swriter", "_default", 0, Array())
    oListDocModel.Text.String = sListaPalabras
    oListDocModel.CurrentController.Frame.activate()

End Sub


Tagged code - floris v, moderator
Back to top
View user's profile Send private message
Tommy27
OOo Advocate
OOo Advocate


Joined: 18 Nov 2006
Posts: 300

PostPosted: Wed Apr 11, 2012 11:05 am    Post subject: Reply with quote

hi, this is the original add2dic macro from probe1


Code:
Sub add2dic

oDok = StarDesktop.getCurrentComponent()
oViewCursor = oDok.getCurrentController().getViewCursor()
oCur = oViewCursor.getText().createTextCursorByRange(oViewCursor)
if oCur.IsCollapsed then
   if NOT oCur.isStartOfWord() then
      oCur.gotoStartofWord(FALSE)
   endif
   oCur.gotoEndofWord(TRUE)
   sWort = oCur.getString
else
   sWort = oCur.getString
end if
if Len(sWort) = 0 then
   exit sub
end if
oWBListe = createUnoService ("com.sun.star.linguistic2.DictionaryList")
oWB = oWBListe.getDictionaryByName("standard.dic")
oWB.add(sWort, FALSE, "")
End Sub


I'd like to modify in order to avoid addiction to the dictionary if the text selection contains a blank space " ".

sometimes if happen that an entire phrase with many words is inadvertently selected and erroneously added to the dictionary using the macro.

Iìd like to add to dictionary only single words so, if a blank space in included in the selection, I do not want to be added to the dictionary

is this possible to achieve?
Back to top
View user's profile Send private message
floris_v
Moderator
Moderator


Joined: 12 Jul 2007
Posts: 4599
Location: Netherlands

PostPosted: Wed Apr 11, 2012 11:22 am    Post subject: Reply with quote

Sure, change
Code:
if Len(sWort) = 0 then
   exit sub

to
Code:
if (Len(sWort) = 0) or (inStr(sWort, " ") > 0) then
   exit sub

_________________
LibreOffice 3.6.3; OOo 3.4.1 on Windows Vista
Join the Official community forum - in several languages, including Nederlandstalig forum
Back to top
View user's profile Send private message
Tommy27
OOo Advocate
OOo Advocate


Joined: 18 Nov 2006
Posts: 300

PostPosted: Wed Apr 11, 2012 12:36 pm    Post subject: Reply with quote

thanks floris. it works!!!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group