| View previous topic :: View next topic |
| Author |
Message |
hanslist General User

Joined: 10 Apr 2012 Posts: 6
|
Posted: Tue Apr 10, 2012 11:49 am Post subject: Request for a macro: add words to spell checker dictionary |
|
|
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 |
|
 |
floris_v Moderator


Joined: 12 Jul 2007 Posts: 4599 Location: Netherlands
|
Posted: Tue Apr 10, 2012 11:54 am Post subject: |
|
|
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 |
|
 |
hanslist General User

Joined: 10 Apr 2012 Posts: 6
|
Posted: Tue Apr 10, 2012 12:12 pm Post subject: Unknown words are mixed with known words |
|
|
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 |
|
 |
probe1 Moderator


Joined: 18 Aug 2004 Posts: 2465 Location: Chonburi Thailand Asia
|
Posted: Tue Apr 10, 2012 8:30 pm Post subject: |
|
|
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 |
|
 |
Tommy27 OOo Advocate


Joined: 18 Nov 2006 Posts: 300
|
|
| Back to top |
|
 |
hanslist General User

Joined: 10 Apr 2012 Posts: 6
|
Posted: Tue Apr 10, 2012 10:36 pm Post subject: Thanks for the macro |
|
|
Thanks for writing this macro!
Hans  |
|
| Back to top |
|
 |
hanslist General User

Joined: 10 Apr 2012 Posts: 6
|
|
| Back to top |
|
 |
karolus OOo Advocate

Joined: 22 Jun 2011 Posts: 208
|
Posted: Wed Apr 11, 2012 12:47 am Post subject: |
|
|
Hi
Delete the Space after _
or change to
if not paste here the next line of code
Karo |
|
| Back to top |
|
 |
hanslist General User

Joined: 10 Apr 2012 Posts: 6
|
Posted: Wed Apr 11, 2012 1:08 am Post subject: Help still needed |
|
|
| 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 |
|
 |
karolus OOo Advocate

Joined: 22 Jun 2011 Posts: 208
|
Posted: Wed Apr 11, 2012 2:23 am Post subject: |
|
|
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 |
|
 |
hanslist General User

Joined: 10 Apr 2012 Posts: 6
|
Posted: Wed Apr 11, 2012 4:41 am Post subject: Re: Help still needed /FIXED |
|
|
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 |
|
 |
Tommy27 OOo Advocate


Joined: 18 Nov 2006 Posts: 300
|
Posted: Wed Apr 11, 2012 11:05 am Post subject: |
|
|
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 |
|
 |
floris_v Moderator


Joined: 12 Jul 2007 Posts: 4599 Location: Netherlands
|
Posted: Wed Apr 11, 2012 11:22 am Post subject: |
|
|
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 |
|
 |
Tommy27 OOo Advocate


Joined: 18 Nov 2006 Posts: 300
|
Posted: Wed Apr 11, 2012 12:36 pm Post subject: |
|
|
| thanks floris. it works!!! |
|
| Back to top |
|
 |
|