GMK

OpenOffice/LibreOffice Spell Checker

6 posts in this topic

#1 ·  Posted (edited)

@mLipok asked me to come up with an AutoIt example for this.

So here's what I came up with, including an added bonus.

#include <Array.au3>

Global $oMyError = ObjEvent('AutoIt.Error', '_ErrFunc')

Global $sLocale = 'en'
Global $sCountry = 'US'
Global $sWord = InputBox("Spell Checker", "File to check (empty for end)?")
While $sWord <> ""
    Global $vSpell = _OOo_SpellChecker($sWord, $sLocale, $sCountry)
    If $vSpell Then
        MsgBox(0, "Spell Checker", $sWord & " is valid")
    Else
        If MsgBox(4, "Spell Checker", $sWord & " is NOT valid. Would you like to see alternatives?") = 6 Then
            Global $aAlternatives = _OOo_SpellChecker($sWord, $sLocale, $sCountry, True)
            _ArrayDisplay($aAlternatives, "Spell Checker")
        EndIf
    EndIf
    $sWord = InputBox("Spell Checker", "File to check (empty for end)?")
WEnd

; #FUNCTION# ====================================================================================================================
; Name ..........: _OOo_SpellChecker
; Description ...: Checks a single word with the OpenOffice/LibreOffice spell checker to see if it is spelled correctly in a
;                  given locale.
; Syntax ........: _OOo_SpellChecker($sWord[, $sLocale = 'en'[, $sCountry = 'US'[, $bShowAlternatives = False]]])
; Parameters ....: $sWord             - a string value.
;                  $sLocale           - [optional] a string value. Default is 'en'.
;                  $sCountry          - [optional] a string value. Default is 'US'.
;                  $bShowAlternatives - [optional] a boolean value. Default is False.
; Return values .: On Success         - Returns True if the word is spelled correctly using the specified language, False
;                                       otherwise. If word is not spelled correctly and $bShowAlternatives is set to True,
;                                       an array of suggestions is returned.
;                  On Failure         - Returns 0 and sets @error and @extended:
;                  |                    @error    = 0 - Success (No error)
;                  |                                1 - General error
;                  |                                2 - Invalid type
;                  |                                3 - Invalid value
;                  |                                4 - No match found
;                  |                    @extended = number of offending parameter
; Author ........: GMK
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://www.openoffice.org/api/docs/common/ref/com/sun/star/linguistic2/XSpellChecker.html
;                  https://www.openoffice.org/api/docs/common/ref/com/sun/star/linguistic2/XSpellAlternatives.html
;                  http://www.loc.gov/standards/iso639-2/php/code_list.php
;                  https://www.iso.org/obp/ui/#search
; Example .......: Yes
; ===============================================================================================================================
Func _OOo_SpellChecker($sWord, $sLocale = 'en', $sCountry = 'US', $bShowAlternatives = False)
    Local Enum $eErr_Success, _
            $eErr_GeneralError, _
            $eErr_InvalidType, _
            $eErr_InvalidValue, _
            $eErr_NoMatch
    If Not IsString($sWord) Then Return SetError($eErr_InvalidType, 1, 0)
    If StringRegExp($sWord, '\d|\s') Then Return SetError($eErr_InvalidValue, 1, 0)
    If Not IsString($sLocale) Then Return SetError($eErr_InvalidType, 2, 0)
    If StringLen($sLocale) <> 2 Then Return SetError($eErr_InvalidValue, 2, 0)
    If Not IsString($sCountry) Then Return SetError($eErr_InvalidType, 3, 0)
    If StringLen($sCountry) <> 2 Then Return SetError($eErr_InvalidValue, 3, 0)
    Local $oSM = ObjCreate('com.sun.star.ServiceManager')
    If Not IsObj($oSM) Then Return SetError($eErr_GeneralError, 10, 0)
    Local $oLocale = $oSM.Bridge_GetStruct('com.sun.star.lang.Locale')
    If Not IsObj($oLocale) Then Return SetError($eErr_GeneralError, 11, 0)
    $oLocale.Language = $sLocale
    $oLocale.Country = $sCountry
    Local $oLinguService = $oSM.createInstance('com.sun.star.linguistic2.LinguServiceManager')
    If Not IsObj($oLinguService) Then Return SetError($eErr_GeneralError, 12, 0)
    Local $oSpellChecker = $oLinguService.getSpellChecker
    If Not IsObj($oSpellChecker) Then Return SetError($eErr_GeneralError, 13, 0)
    If Not $oSpellChecker.hasLocale($oLocale) Then Return SetError($eErr_NoMatch, 2, 0)
    Local $oPropertyValue = $oSM.Bridge_GetStruct('com.sun.star.beans.PropertyValue')
    If Not IsObj($oPropertyValue) Then Return SetError($eErr_GeneralError, 14, 0)
    Local $aPropertyValue[1] = [$oPropertyValue]
    Local $nRandom = Random(0, 0.5)
    Local $bReturn = $oSpellChecker.isValid($sWord, $nRandom, $aPropertyValue)
    If @error Then Return SetError($eErr_GeneralError, 15, 0)
    If Not $bReturn And $bShowAlternatives Then
        Local $oSpell = $oSpellChecker.spell($sWord, $nRandom, $aPropertyValue)
        If Not IsObj($oSpell) Then Return SetError($eErr_GeneralError, 16, 0)
        Local $aReturn = $oSpell.getAlternatives()
        Local $iAlternatives = UBound($aReturn)
        ReDim $aReturn[$iAlternatives + 1]
        $iAlternatives += 1
        For $i = $iAlternatives - 1 To 1 Step -1
            $aReturn[$i] = $aReturn[$i - 1]
        Next
        $aReturn[0] = $oSpell.getAlternativesCount()
        If @error Then Return SetError($eErr_GeneralError, 17, 0)
        Return SetError($eErr_Success, 0, $aReturn)
    EndIf
    Return SetError($eErr_Success, 0, $bReturn)
EndFunc

Func _ErrFunc($oError)
    ConsoleWrite(@ScriptName & ' (' & $oError.scriptline & ') : ==> COM Error intercepted !' & @CRLF & _
            @TAB & 'err.number is: ' & @TAB & @TAB & '0x' & Hex($oError.number) & @CRLF & _
            @TAB & 'err.windescription:' & @TAB & $oError.windescription & @CRLF & _
            @TAB & 'err.description is: ' & @TAB & $oError.description & @CRLF & _
            @TAB & 'err.source is: ' & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & 'err.helpfile is: ' & @TAB & $oError.helpfile & @CRLF & _
            @TAB & 'err.helpcontext is: ' & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & 'err.lastdllerror is: ' & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & 'err.scriptline is: ' & @TAB & $oError.scriptline & @CRLF & _
            @TAB & 'err.retcode is: ' & @TAB & '0x' & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

Edited by GMK
Edited tags
2 people like this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

@GMK Thanks for this Function, this is very handy !

I just make a small modyfication for example:

#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <WinAPILocale.au3>

Global $oMyError = ObjEvent('AutoIt.Error', '_ErrFunc')

_Example()
Func _Example()
    Local $sLocale = 'pl'
    Local $sCountry = 'PL'
    Local $sWord = InputBox("Spell Checker", "Type single word to check (empty for end) ?")
    While $sWord <> ""
        Global $vSpell = _OOo_SpellChecker($sWord, $sLocale, $sCountry)
        If @error Then
            MsgBox($MB_ICONERROR, '_OOo_SpellChecker', '@error = ' & @error & @CRLF & '@extended = ' & @extended)
        ElseIf $vSpell Then
            MsgBox($MB_OK, "Spell Checker", $sWord & " is valid")
        Else
            If MsgBox($MB_YESNO, "Spell Checker", $sWord & " is NOT valid. Would you like to see alternatives?") = $IDYES Then
                Global $aAlternatives = _OOo_SpellChecker($sWord, $sLocale, $sCountry, True)
                _ArrayDisplay($aAlternatives, "Spell Checker")
            EndIf
        EndIf
        $sWord = InputBox("Spell Checker", "File to check (empty for end)?")
    WEnd
EndFunc

 

ps.
Try to not use magic numbers.

 

EDIT:
Small mod:

Func _OOo_SpellChecker($sWord, $sLocale = 'en', $sCountry = 'US', $bShowAlternatives = False)
    Local Enum _
            $eErr_Success, _
            $eErr_GeneralError, _
            $eErr_InvalidType, _
            $eErr_InvalidValue, _
            $eErr_NoMatch

    If Not IsString($sWord) Then Return SetError($eErr_InvalidType, 1, 0)
    If StringRegExp($sWord, '\d|\s') Or $sWord = '' Then Return SetError($eErr_InvalidValue, 1, 0)
    If Not IsString($sLocale) Then Return SetError($eErr_InvalidType, 2, 0)
    If StringLen($sLocale) <> 2 Then Return SetError($eErr_InvalidValue, 2, 0)
    If Not IsString($sCountry) Then Return SetError($eErr_InvalidType, 3, 0)
    If StringLen($sCountry) <> 2 Then Return SetError($eErr_InvalidValue, 3, 0)

    Local $oSM = ObjCreate('com.sun.star.ServiceManager')
    If Not IsObj($oSM) Then Return SetError($eErr_GeneralError, 10, 0)

    Local $oLocale = $oSM.Bridge_GetStruct('com.sun.star.lang.Locale')
    If Not IsObj($oLocale) Then Return SetError($eErr_GeneralError, 11, 0)

    $oLocale.Language = $sLocale
    $oLocale.Country = $sCountry
    Local $oLinguService = $oSM.createInstance('com.sun.star.linguistic2.LinguServiceManager')
    If Not IsObj($oLinguService) Then Return SetError($eErr_GeneralError, 12, 0)

    Local $oSpellChecker = $oLinguService.getSpellChecker
    If Not IsObj($oSpellChecker) Then Return SetError($eErr_GeneralError, 13, 0)
    If Not $oSpellChecker.hasLocale($oLocale) Then Return SetError($eErr_NoMatch, 2, 0)

    Local $oPropertyValue = $oSM.Bridge_GetStruct('com.sun.star.beans.PropertyValue')
    If Not IsObj($oPropertyValue) Then Return SetError($eErr_GeneralError, 14, 0)

    Local $aPropertyValue[1] = [$oPropertyValue]
    Local $nRandom = Random(0, 0.5)
    Local $bReturn = $oSpellChecker.isValid($sWord, $nRandom, $aPropertyValue)
    If @error Then Return SetError($eErr_GeneralError, 15, 0)

    If Not $bReturn And $bShowAlternatives Then
        Local $oSpell = $oSpellChecker.spell($sWord, $nRandom, $aPropertyValue)
        If Not IsObj($oSpell) Then Return SetError($eErr_GeneralError, 16, 0)

        Local $aReturn = $oSpell.getAlternatives()
        Local $iAlternatives = UBound($aReturn)
        ReDim $aReturn[$iAlternatives + 1]
        $iAlternatives += 1
        For $i = $iAlternatives - 1 To 1 Step -1
            $aReturn[$i] = $aReturn[$i - 1]
        Next
        $aReturn[0] = $oSpell.getAlternativesCount()
        If @error Then Return SetError($eErr_GeneralError, 17, 0)
        Return SetError($eErr_Success, 0, $aReturn)
    EndIf

    Return SetError($eErr_Success, 0, $bReturn)
EndFunc   ;==>_OOo_SpellChecker

 

Edited by mLipok
1 person likes this

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hey, I just wrote this to fulfill a request.  I had no standards in mind, nor did I write it to be included in the next release.  I'm not sure how often I'll use it, but hopefully others will find a use for it.

 

P.S. Glad you like it!

Edited by GMK
P.S.

Share this post


Link to post
Share on other sites

I'm really grateful for this example.
But as usual, I just added my 2 cents, of course, not in order to upset you, I just simply shared my observations and ideas.
Sorry for the bad feelings.

mLipok


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

No  worries.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • GMK
      By GMK
      I decided to enhance the functionality of the OOo COM UDF found >here and >here.  Thanks to Leagnus and Andy G for providing the initial functions and framework.
      This UDF includes the following working functions:
      _OOoCalc_BookNew
      _OOoCalc_BookOpen
      _OOoCalc_BookAttach
      _OOoCalc_BookSave
      _OOoCalc_BookSaveAs
      _OOoCalc_BookClose
      _OOoCalc_WriteCell
      _OOoCalc_WriteFormula
      _OOoCalc_WriteFromArray
      _OOoCalc_HyperlinkInsert
      _OOoCalc_RangeMoveOrCopy
      _OOoCalc_RangeSort
      _OOoCalc_RangeClearContents
      _OOoCalc_CreateBorders
      _OOoCalc_NumberFormat
      _OOoCalc_ReadCell
      _OOoCalc_ReadSheetToArray
      _OOoCalc_RowDelete
      _OOoCalc_ColumnDelete
      _OOoCalc_RowInsert
      _OOoCalc_ColumnInsert
      _OOoCalc_SheetAddNew
      _OOoCalc_SheetDelete
      _OOoCalc_SheetNameGet
      _OOoCalc_SheetNameSet
      _OOoCalc_SheetList
      _OOoCalc_SheetActivate
      _OOoCalc_SheetSetVisibility
      _OOoCalc_SheetMove
      _OOoCalc_SheetPrint
      _OOoCalc_HorizontalAlignSet
      _OOoCalc_FontSetProperties
      _OOoCalc_CellSetColors
      _OOoCalc_RowSetColors
      _OOoCalc_ColumnSetColors
      _OOoCalc_RowSetProperties
      _OOoCalc_ColumnSetProperties
      _OOoCalc_FindInRange
      _OOoCalc_ReplaceInRange
      Please help me test this and let me know of any problems, questions, suggestions or comments you may have.
      Edit (August 5, 2016): Latest files have been uploaded.  Script-breaking changes include renaming the functions to start with _OOoCalc_.
      Edit (November 14, 2016): New version, including fixed sort function!
      Edit (November 15, 2016): Lots of minor changes including tightening up the error checking.
      Edit (November 16, 2016): Added ByRef to object parameters. Edited demo.
       
       
       
       
      OOoCalcConstants.au3
       
      OOoCalc.au3
      OOoCalc_Demo.au3
    • iCode
      By iCode
      This UDF was originally written by ProgAndy, who gave up Windows, and thus AutoIt, in favor of Linux. Apparently he was well liked and respected for his capabilities, and will be missed. I have been playing with this UDF and modifying it a bit for my own use and i wanted to post the code (permission was granted from ProgAndy after i finally managed to reach him).
      The original code is still available at progandy.de and is also added here as an attachment. My modified version is attached. You will need the ProgAndy version for the dll code and examples.
      I think this is a really cool project that could be useful to many, so it would be nice if we could work on it and improve it. I'm not very knowledgeable regarding the depths of AutoIt capabilities, and am especially weak in anything having to do with DLL's.
      I will post a complete example with a GUI in the near future, but for now, here is my modified UDF...
      #include-once ; #INDEX# ======================================================================================================================= ; Title .........: Hunspell Hypenate MyThes ; Description ...: This module contains various functions to call Hunspell, Hyphenate and MyThes ; Author ........: Prog@ndy http://progandy.co.cc/downloads/view.download/12 ; Licence .......: The DLLs are open source, taken from the NHunspell project (http://nhunspell.sf.net) ; NHunspell is licenced under: GPL/LGPL/MPL. ; Free use in commercial applications is permittet according to the LGPL and MPL licenses. ; Your commercial application can link against the NHunspell DLLs. ; =============================================================================================================================== OnAutoItExitRegister("__Spell_Shutdown") ; =============================================================================================================================== ; GLOBAL VARIABLES ; =============================================================================================================================== Global $hHunspellDll = -1, $hHunspell = -1 ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_Spell_HunspellAdd ;_Spell_HunspellAddWithAffix ;_Spell_HunspellAnalyze ;_Spell_HunspellFree ;_Spell_HunspellGenerate ;_Spell_HunspellInit ;_Spell_HunspellSpell ;_Spell_HunspellStem ;_Spell_HunspellSuggest ;_Spell_HyphenFree ;_Spell_HyphenHyphenate ;_Spell_HyphenInit ;_Spell_MyThesFree ;_Spell_MyThesInit ;_Spell_MyThesLookup ;_Spell_Startup ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ;__Spell_PtrStringReadW ;__Spell_HunspellReadStringArray ;__Spell_MyThesReadMarshalBuffer ;__Spell_MyThesReadMeaningBuffer ;__Spell_Shutdown ; =============================================================================================================================== ; #ORIGINAL_CALLCONV#============================================================================================================ ; definitions taken from sourcefile: /trunk/Hunspell/HunspellExportFunctions.cpp ; Link: http://nhunspell.svn.sourceforge.net/viewvc/nhunspell/trunk/Hunspell/ ; ; #define DLLEXPORT extern "C" _declspec( dllexport ) ==> CDECL ! ; ; DLLEXPORT NHunspell * HunspellInit(wchar_t * aff_file, wchar_t *dict_file, wchar_t * key) ; DLLEXPORT void HunspellFree(NHunspell * handle ) ; DLLEXPORT bool HunspellAdd(NHunspell * handle, wchar_t * word ) ; DLLEXPORT bool HunspellAddWithAffix(NHunspell * handle, wchar_t * word, wchar_t * affix ) ; DLLEXPORT bool HunspellSpell(NHunspell * handle, wchar_t * word ) ; DLLEXPORT void * HunspellSuggest(NHunspell * handle, wchar_t * word ) ; DLLEXPORT void * HunspellAnalyze(NHunspell * handle, wchar_t * word ) ; DLLEXPORT void * HunspellStem(NHunspell * handle, wchar_t * word ) ; DLLEXPORT void * HunspellGenerate(NHunspell * handle, wchar_t * word, wchar_t * word2 ) ; ; DLLEXPORT void * HyphenInit(wchar_t * dict_file) ; DLLEXPORT void HyphenFree(NHyphen * handle ) ; DLLEXPORT void * HyphenHyphenate(NHyphen * handle, wchar_t * word ) ; ; DLLEXPORT void * MyThesInit(wchar_t * idx_file, wchar_t * dat_file) ; DLLEXPORT void MyThesFree(NMyThes * handle ) ; DLLEXPORT void * MyThesLookup(NMyThes * handle, wchar_t * word ) ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_HunspellAdd ; Description ...: add word to the run-time dictionary ; Syntax.........: _Spell_HunspellAdd($hHunspell, $sWord) ; Parameters ....: $hHunspell - Hunspell handle returned from _Spell_HunspellInit ; $sWord - the word to add ; Return values .: Success - 1 ; Failure - 0 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: ; Related .......: _Spell_HunspellAddWithAffix ; Link ..........; ; Example .......; ; =============================================================================================================================== Func _Spell_HunspellAdd($hHunspell, $sWord) Local $aResult = DllCall($hHunspellDll, "int:cdecl", "HunspellAdd", "ptr", $hHunspell, "wstr", $sWord) If @error Then Return SetError(1, 0, 0) Return $aResult[0] EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_HunspellAddWithAffix ; Description ...: add word to the run-time dictionary with affix flags of the example (a dictionary word) ; Syntax.........: _Spell_HunspellAddWithAffix($hHunspell, $sWord, $sAffix) ; Parameters ....: $hHunspell - Hunspell handle returned from _Spell_HunspellInit ; $sWord - the word to add ; $sAffix - Affix ; Return values .: Success - 1 ; Failure - 0 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: Hunspell will recognize affixed forms of the new word, too. ; Related .......: _Spell_HunspellAdd ; Link ..........; ; Example .......; ; =============================================================================================================================== Func _Spell_HunspellAddWithAffix($hHunspell, $sWord, $sAffix) Local $aResult = DllCall($hHunspellDll, "int:cdecl", "HunspellAddWithAffix", "ptr", $hHunspell, "wstr", $sWord, "wstr", $sAffix) If @error Then Return SetError(1, 0, 0) Return $aResult[0] EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_HunspellAnalyze ; Description ...: morphological analysis of the word ; Syntax.........: _Spell_HunspellAnalyze($hHunspell, $sWord) ; Parameters ....: $hHunspell - Hunspell handle returned from _Spell_HunspellInit ; $sWord - the word to analyze ; Return values .: Success - array with analyzation result ; Failure - 0 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: ; Related .......: _Spell_HunspellGenerate ; Link ..........; ; Example .......; ; =============================================================================================================================== Func _Spell_HunspellAnalyze($hHunspell, $sWord) Local $aResult = DllCall($hHunspellDll, "ptr:cdecl", "HunspellAnalyze", "ptr", $hHunspell, "wstr", $sWord) If @error Then Return SetError(1, 0, 0) If $aResult[0] = 0 Then Return SetError(2, 0, 0) Local $aTemp = __Spell_HunspellReadStringArray($aResult[0]) If @error Then Return SetError(3, 0, 0) Return $aTemp EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_HunspellFree ; Description ...: Frees memory associated with a Hunspell handle ; Syntax.........: _Spell_HunspellFree($hHunspell) ; Parameters ....: $hHunspell - Hunspell handle returned from _Spell_HunspellInit ; Return values .: Failure - Sets @error = 1 ; Author ........: Prog@ndy, iCode ; Modified.......: 13-Jun-2014 ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _Spell_HunspellFree($hHunspell) DllCall($hHunspellDll, "none:cdecl", "HunspellFree", "ptr", $hHunspell) If @error Then Return SetError(1) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_HunspellGenerate ; Description ...: morphological generation by example(s) ; Syntax.........: _Spell_HunspellGenerate($hHunspell, $sWord, $sWord2) ; Parameters ....: $hHunspell - Hunspell handle returned from _Spell_HunspellInit ; $sWord - first word ; $sWord2 - second word ; Return values .: Success - array with result ; Failure - 0 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: ; Related .......: _Spell_HunspellAnalyze ; Link ..........; ; Example .......; ; =============================================================================================================================== Func _Spell_HunspellGenerate($hHunspell, $sWord, $sWord2) Local $aResult = DllCall($hHunspellDll, "ptr:cdecl", "HunspellGenerate", "ptr", $hHunspell, "wstr", $sWord, "wstr", $sWord2) If @error Then Return SetError(1, 0, 0) If $aResult[0] = 0 Then Return SetError(2,0,0) Local $aTemp = __Spell_HunspellReadStringArray($aResult[0]) If @error Then Return SetError(3, 0, 0) Return $aTemp EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_HunspellInit ; Description ...: Initializes Hunspell ; Syntax.........: _Spell_HunspellInit($sAff_file, $sDict_file, $sKey=0) ; Parameters ....: $sAff_file - Hunspell .aff-file ; $sDict_file - Hunspell .dict-file ; $sKey - [optional] a Key String ; Return values .: Success - 1 ; Failure - 0 ; Author ........: Prog@ndy, iCode ; Modified.......: 13-Jun-2014 ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _Spell_HunspellInit($sAff_file, $sDict_file, $sKey=0) Local $tpKey='ptr' If IsString($sKey) Then $tpKey='wstr' Local $aResult = DllCall($hHunspellDll, 'ptr:cdecl', 'HunspellInit', 'wstr', $sAff_file, 'wstr', $sDict_file, $tpKey, $sKey) If @error Then Return SetError(1, 0, 0) Return $aResult[0] EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_HunspellSpell ; Description ...: Checks the spelling of the given word ; Syntax.........: _Spell_HunspellSpell($hHunspell, $sWord) ; Parameters ....: $hHunspell - Hunspell handle returned from _Spell_HunspellInit ; $sWord - the Word to check ; Return values .: Success - 1 ; Failure - 0 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: ; Related .......: _Spell_HunspellSuggest ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _Spell_HunspellSpell($hHunspell, $sWord) Local $aResult = DllCall($hHunspellDll, "int:cdecl", "HunspellSpell", "ptr", $hHunspell, "wstr", $sWord) If @error Then Return SetError(1, 0, 0) Return $aResult[0] EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_HunspellStem ; Description ...: stemmer function ; Syntax.........: _Spell_HunspellStem($hHunspell, $sWord) ; Parameters ....: $hHunspell - Hunspell handle returned from _Spell_HunspellInit ; $sWord - the word to stem ; Return values .: Success - array with result ; Failure - 0 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; ; =============================================================================================================================== Func _Spell_HunspellStem($hHunspell, $sWord) Local $aResult = DllCall($hHunspellDll, "ptr:cdecl", "HunspellStem", "ptr", $hHunspell, "wstr", $sWord) If @error Then Return SetError(1, 0, 0) If $aResult[0] = 0 Then Return SetError(2, 0, 0) Local $aTemp = __Spell_HunspellReadStringArray($aResult[0]) If @error Then Return SetError(3, 0, 0) Return $aTemp EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_HunspellSuggest ; Description ...: Suggests alternatives for a misspelled word ; Syntax.........: _Spell_HunspellSuggest($hHunspell, $sWord) ; Parameters ....: $hHunspell - Hunspell handle returned from _Spell_HunspellInit ; $sWord - The word you want alternatives for ; Return values .: Success - Array with suggestions (0 based) ; Failure - 0 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: ; Related .......: _Spell_HunspellSpell ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _Spell_HunspellSuggest($hHunspell, $sWord) Local $aResult = DllCall($hHunspellDll, "ptr:cdecl", "HunspellSuggest", "ptr", $hHunspell, "wstr", $sWord) If @error Then Return SetError(1, 0, 0) If $aResult[0] = 0 Then Return SetError(2, 0, 0) Local $aTemp = __Spell_HunspellReadStringArray($aResult[0]) If @error Then Return SetError(3, 0, 0) Return $aTemp EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_HyphenFree ; Description ...: Frees memory associated with a Hyphen-handle ; Syntax.........: _Spell_HyphenFree($hHyphen) ; Parameters ....: $hHyphen - Hyphen-handle returned from _Spell_HyphenInit ; Return values .: Failure - Sets @error = 1 ; Author ........: Prog@ndy, iCode ; Modified.......: 13-Jun-2014 ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _Spell_HyphenFree($hHyphen) DllCall($hHunspellDll, "none:cdecl", "HyphenFree", "ptr", $hHyphen) If @error Then Return SetError(1) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_HyphenHyphenate ; Description ...: Analyze a word for possible hyphenation ; Syntax.........: _Spell_HyphenHyphenate($hHyphen, $sWord) ; Parameters ....: $hHyphen - Hyphen-handle returned from _Spell_HyphenInit ; $sWord - Word to be analyzed ; Return values .: Success - Array with hyphenation result ; |$array[0] contains the siblings separated with = ; |$array[$i] is 0 if you can"t split the word after letter $i ; |$array[$i] is 1 if it is possible to split the word after letter $i ; Failure - 0 ; Author ........: Prog@ndy, iCode ; Modified.......: 13-Jun-2014 ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _Spell_HyphenHyphenate($hHyphen, $sWord) Local $aResult = DllCall($hHunspellDll, "ptr:cdecl", "HyphenHyphenate", "ptr", $hHyphen, "wstr", $sWord) If @error Then Return SetError(1, 0, 0) If $aResult[0] = 0 Then Return SetError(2, 0, 0) Local $stHyphen = DllStructCreate("ptr;ptr;",$aResult[0]) Local $sTemp = __Spell_PtrStringReadW(DllStructGetData($stHyphen,1)) Local $iMax = StringLen($sWord), $iIndex Local $aTemp[$iMax+1] = [$sTemp] $stHyphen = DllStructCreate("byte[" & $iMax & "]",DllStructGetData($stHyphen,2)) If @error Then Return SetError(3, 0, 0) For $iIndex = 1 To $iMax $aTemp[$iIndex] = Mod(DllStructGetData($stHyphen,1,$iIndex),2) Next Return $aTemp EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_HyphenInit ; Description ...: Initializes a Hyphen-handle ; Syntax.........: _Spell_HyphenInit($sDict_file) ; Parameters ....: $sDict_file - Dictionary for hyphenation ; Return values .: Success - 1 ; Failure - 0 ; Author ........: Prog@ndy, iCode ; Modified.......: 13-Jun-2014 ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _Spell_HyphenInit($sDict_file) Local $aResult = DllCall($hHunspellDll, "ptr:cdecl", "HyphenInit", "wstr", $sDict_file) If @error Then Return SetError(1, 0, 0) Return $aResult[0] EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_MyThesFree ; Description ...: Frees memory associated with a MyThes handle ; Syntax.........: _Spell_MyThesFree($hMyThes) ; Parameters ....: $hMyThes - MyThes-handle returned from _Spell_MyThesInit ; Return values .: Failure - Sets @error = 1 ; Author ........: Prog@ndy, iCode ; Modified.......: 13-Jun-2014 ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _Spell_MyThesFree($hMyThes) DllCall($hHunspellDll, "none:cdecl", "MyThesFree", "ptr", $hMyThes) If @error Then Return SetError(1) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_MyThesInit ; Description ...: Initializes a Thesaurus ; Syntax.........: _Spell_MyThesInit($sIdx_file, $sDat_file) ; Parameters ....: $sIdx_file - MyThes .idx-file ; $sDat_file - MyThes .dat-file ; Return values .: Success - 1 ; Failure - 0 ; Author ........: Prog@ndy, iCode ; Modified.......: 13-Jun-2014 ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _Spell_MyThesInit($sIdx_file, $sDat_file) Local $aResult = DllCall($hHunspellDll, "ptr:cdecl", "MyThesInit", "wstr", $sIdx_file, "wstr", $sDat_file) If @error Then Return SetError(1, 0, 0) Return $aResult[0] EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_MyThesLookup ; Description ...: Looks up the meanings and synonyms of a word ; Syntax.........: _Spell_MyThesLookup($hMyThes, $sWord) ; Parameters ....: $hMyThes - MyThes-handle returned from _Spell_MyThesInit ; $sWord - The word o analyze ; Return values .: Success - Array of Arrays: ; |$array[$i] - the entries for one meaning of the word ; |--> $subarray[0] - the description of the meaning ; |--> $subarray[$j] - synonyms for this meaning ; Failure - 0 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _Spell_MyThesLookup($hMyThes, $sWord) Local $aResult = DllCall($hHunspellDll, "ptr:cdecl", "MyThesLookup", "ptr", $hMyThes, "wstr", $sWord) If @error Then Return SetError(1, 0, 0) $aResult = __Spell_MyThesReadMarshalBuffer($aResult[0]) If @error Then Return SetError(2, 0, 0) Return $aResult EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _Spell_Startup ; Description ...: Loads the DLL containing Hunspell, Hyphen and Thesaurus (selects 32 or 64 bit automatically) ; Syntax.........: _Spell_Startup(directory path where dll can be found) ; Parameters ....: $sDLL - Hunspell.dll for 32 bit ; $sDLLx64 - Hunspell.dll for 64 bit ; Return values .: Success - 1 ; Failure - 0 and sets @error = 1 ; Author ........: Prog@ndy, iCode ; Modified.......: 13-Jun-2014 ; Remarks .......: No Unload function included, AutoIt does it automatically on termination ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _Spell_Startup($sDir) If $hHunspellDll <> -1 Then Return 1 Local $sDLL = $sDir & "\Hunspell_x86.dll" If @AutoItX64 Then $sDLL = $sDir & "\Hunspell_x64.dll" $hHunspellDll = DllOpen($sDLL) If $hHunspellDll = -1 Then Return SetError(1, 0, 0) Return 1 EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: __Spell_HunspellReadStringArray ; Description ...: Reads a zero-terminated array of pointers to wstrings (zero-terminated) ; Syntax.........: __Spell_HunspellReadStringArray($ptr) ; Parameters ....: $ptr - Pointer to array ; Return values .: Success - Array with read strings ; Failure - 0 ; Author ........: Prog@ndy, iCode ; Modified.......: 13-Jun-2014 ; Remarks .......: This function is used internally by _Spell_HunspellSuggest, _Spell_HunspellAnalyze, _Spell_HunspellStem, and _Spell_HunspellGenerate ; Related .......: ; Link ..........; ; Example .......; ; =============================================================================================================================== Func __Spell_HunspellReadStringArray($ptr) If $ptr = 0 Then Return SetError(1, 0, 0) Local $stPtr = DllStructCreate("ptr", $ptr) Local $asStrings[50], $iIndex = 0, $iMax = 49 While 1 $asStrings[$iIndex] = __Spell_PtrStringReadW(DllStructGetData($stPtr,1)) If @error = 1 Then ExitLoop $iIndex += 1 If $iIndex > $iMax Then $iMax += 50 ReDim $asStrings[$iMax+1] EndIf $stPtr = DllStructCreate("ptr", $ptr + DllStructGetSize($stPtr)*$iIndex) WEnd If $iIndex = 0 Then Return SetError(2, 0, 0) ReDim $asStrings[$iIndex] Return $asStrings EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: __Spell_PtrStringReadW ; Description ...: Reads a zero-terminated wstrings from a pointer ; Syntax.........: __Spell_HunspellReadStringArray($ptr) ; Parameters ....: $ptr - Pointer to wstring ; Return values .: Success - read string ; Failure - empty string ("") ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: This function is used internally by __Spell_HunspellReadStringArray, and __Spell_MyThesReadMeaningBuffer ; Related .......: ; Link ..........; ; Example .......; ; =============================================================================================================================== Func __Spell_PtrStringReadW($ptr) If $ptr = 0 Then Return SetError(1, 0 ,"") Local $aLen = DllCall("kernel32.dll", "int", "lstrlenW", "ptr", $ptr) If @error Or $aLen[0]=0 Then Return SetError(2, 0, "") Local $struct = DllStructCreate("wchar[" & ($aLen[0] + 1) & "]", $ptr) Return DllStructGetData($struct, 1) EndFunc ;==>__Spell_PtrStringReadW ; #INTERNAL_USE_ONLY# ==================================================================================================================== ; Name ..........: __Spell_Shutdown ; Description ...: close hunspell DLL ; Syntax ........: __Spell_Shutdown() ; Parameters ....: ; Return values .: None ; Author ........: iCode ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __Spell_Shutdown() If $hHunspellDll <> -1 Then DllClose($hHunspellDll) EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: __Spell_MyThesReadMarshalBuffer ; Description ...: Reads the Marhal-Buffer for _Spell_MyThesLookup ; Syntax.........: __Spell_MyThesReadMarshalBuffer($pBuffer) ; Parameters ....: $pBuffer - Pointer to Marshal buffer ; Return values .: Success - Array of Arrays ; Failure - 0 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: This function is used internally by _Spell_MyThesLookup ; Related .......: ; Link ..........; ; Example .......; ; =============================================================================================================================== Func __Spell_MyThesReadMarshalBuffer($pBuffer) Local $stPtr = DllStructCreate("int_ptr", $pBuffer) If @error Then Return SetError(1, 0, 0) Local $iCount = DllStructGetData($stPtr, 1) $stPtr = DllStructCreate("int_ptr;ptr[" & $iCount & "]", $pBuffer) Local $aMeanings[$iCount], $i For $i = 1 To $iCount $aMeanings[$i-1] = __Spell_MyThesReadMeaningBuffer(DllStructGetData($stPtr, 2, $i)) Next Return $aMeanings EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: __Spell_MyThesReadMeaningBuffer ; Description ...: Helper to read the Marhal-Buffer for _Spell_MyThesLookup ; Syntax.........: __Spell_MyThesReadMeaningBuffer($pBuffer) ; Parameters ....: $pBuffer - Pointer to meaning-section in Marshal buffer ; Return values .: Success - Array of Strings ; Failure - 0 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: This function is used internally by __Spell_MyThesReadMarshalBuffer ; Related .......: ; Link ..........; ; Example .......; ; =============================================================================================================================== Func __Spell_MyThesReadMeaningBuffer($pBuffer) Local $stPtr = DllStructCreate("int_ptr", $pBuffer) Local $iCount = DllStructGetData($stPtr,1) $stPtr = DllStructCreate("int_ptr;ptr;ptr[" & $iCount & "]", $pBuffer) Local $aSynonyms[$iCount+1], $i $aSynonyms[0] = __Spell_PtrStringReadW(DllStructGetData($stPtr, 2)) For $i = 1 To $iCount $aSynonyms[$i] = __Spell_PtrStringReadW(DllStructGetData($stPtr, 3, $i)) Next Return $aSynonyms EndFunc  
      hunspell-0.9.2-ProgAndy.zip
      Hunspell_iCode_13_JUN_2014.zip