Sign in to follow this  
Followers 0
Noddle

Spell Checker

21 posts in this topic

Hi,

I've been looking for a while for a free spell checker that I can intergrate into my code,

but have not had much luck,

I did come across this,

http://norvig.com/spell-correct.html

which seem to be what I want, but since I don't know enough about these laungages, and autoit,

I though some cleaver peple on here might have a look and see what they can come up with,

it's allready been ported to 29 laungagues ( bottom of page )

Thanks

Nigel

Share this post


Link to post
Share on other sites



Noddle,

That was an interesting way to spend an hour or two. :)

Here is a single word version of the algorithm on that page:

#include <Array.au3>
#include <File.au3>

Global $sList = "WordList.txt"

$sToCheck = InputBox("Spell checker", "Insert the word to check", "", "", 300, 150)

If $sToCheck Then
    $sRet = Correct($sToCheck)
    If $sRet Then
        MsgBox(0, "Found", $sRet)
    Else
        MsgBox(0, "Not found", $sRet)
    EndIf
Else
    MsgBox(0, "Error", "Nothing to check!")
EndIf

Func Deletion($sWord)
    $iCount = StringLen($sWord)
    Local $aResults[$iCount]
    For $i = 0 To $iCount - 1
        $aResults[$i] = StringMid($sWord, 1, $i) & StringMid($sWord, $i + 2)
    Next
    Return $aResults
EndFunc

Func Transposition($sWord)
    $iCount = StringLen($sWord) - 1
    Local $aResults[$iCount]
    For $i = 1 To $iCount
        $aResults[$i - 1] = StringMid($sWord, 1, $i - 1) & StringMid($sWord, $i + 1, 1) & StringMid($sWord, $i, 1) & StringMid($sWord, $i + 2)
    Next
    Return $aResults
EndFunc

Func Alteration($sWord)
    Local $sAlphabet = "abcdefghijklmnopqrstuvwxyz"
    Local $iCount = StringLen($sWord)
    Local $aResults[26 * $iCount]
    Local $iIndex = -1
    For $j = 1 To 26
        For $i = 0 To $iCount - 1
            $iIndex += 1
            $aResults[$iIndex] = StringMid($sWord, 1, $i) & StringMid($sAlphabet, $j, 1) & StringMid($sWord, $i + 2)
        Next
    Next
    Return $aResults
EndFunc

Func Insertion($sWord)
    Local $sAlphabet = "abcdefghijklmnopqrstuvwxyz"
    Local $iCount = StringLen($sWord) + 1
    Local $aResults[26 * $iCount]
    Local $iIndex = -1
    For $j = 1 To 26
        For $i = 0 To $iCount - 1
            $iIndex += 1
            $aResults[$iIndex] = StringMid($sWord, 1, $i) & StringMid($sAlphabet, $j, 1) & StringMid($sWord, $i + 1)
        Next
    Next
    Return $aResults
EndFunc

Func Words($sText)
    ; Function to extract words from longer text
    ; At the moment we are only using 1 word
EndFunc

Func Read($sFile)
    Local $aList
    _FileReadToArray($sFile, $aList)
    _ArrayDelete($aList, 0)
    Return $aList
EndFunc

Func Alternatives($sWord)
    Local $aAlternatives = Deletion($sWord)
    Local $aArray = Transposition($sWord)
    _ArrayConcatenate($aAlternatives, $aArray)
    $aArray = Alteration($sWord)
    _ArrayConcatenate($aAlternatives, $aArray)
    $aArray = Insertion($sWord)
    _ArrayConcatenate($aAlternatives, $aArray)
    Return $aAlternatives
EndFunc

Func Known($sWord, ByRef $aList)

    $iIndex = _ArrayBinarySearch($aList, $sWord)
    If $iIndex <> -1 Then
        Return $aList[$iIndex]
    Else
        Return ""
    EndIf

EndFunc

Func Correct($sWord)
    Local $aList = Read($sList)
    ; look for the word itself
    $sFound = Known($sWord, $aList)
    If $sFound Then
        Return $sFound
    EndIf
    ; Look for alternatives to the word
    $sAllFound = ""
    $aAlternatives = Alternatives($sWord)
    $iCount = UBound($aAlternatives) - 1
    For $i = 0 To $iCount
        $sFound = Known($aAlternatives[$i], $aList)
        If $sFound Then
            $sAllFound &= $sFound & @CRLF
        EndIf
    Next
    If $sAllFound Then
        Return $sAllFound
    EndIf
    ; Look for second order alternatives
    For $j = 0 To UBound($aAlternatives) - 1
        ConsoleWrite($j & @CRLF)
        $aSecAlternatives = Alternatives($aAlternatives[$j])
        $iCount = UBound($aSecAlternatives) - 1
        For $i = 0 To $iCount
            $sFound = Known($aSecAlternatives[$i], $aList)
            If $sFound Then
                $sAllFound &= $sFound & @CRLF
            EndIf
        Next
    Next
    If $sAllFound Then
        Return $sAllFound
    EndIf
    Return ""
EndFunc

I used this file (expanded of course) as a dictionary - it is a word list that I think originally comes from GEOSoft:

Note that if the typed word is not itself correct, the algorithm will search first for a single error per word (SPEELLING or SPELING for SPELLING). If there are 2 errors (OCASSION for OCCASION) it then moves to a whole new level of complexity. Checking for a single error in a 7-letter word needs about 400 array searches (on my machine that takes about 1 sec), but if you check for 2 the number rises to 160,000 (and that takes about 1 minute). :o

An excellent example of why it is not really a good idea to write spell checkers in an interpreted language. ;)

M23


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

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I don't have any idea how to do it

But is it possible to embed an Word document or somewhat which is present in the Reply mechanism of this FORUM into the GUI


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

@Melba

Why not keep it simple(er) then. All you need is 1 error for a word to be wrong, so replace the checked word with the one from dictionary, then any additional errors in that word will be fixed and no need to check for more than 1 error/word.

it would probably need a dropdown list of different variations of the word (such as: rock, rocky, rocks)


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

Why not keep it simple(er) then. All you need is 1 error for a word to be wrong, so replace the checked word with the one from dictionary, then any additional errors in that word will be fixed and no need to check for more than 1 error/word.

it would probably need a dropdown list of different variations of the word (such as: rock, rocky, rocks)

This is similar to WordWeb Pro behavior, any error actions a list that you select from.


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Hi all,

I am not doing anything else to this script - converting the algorithm was just a way of passing the time this afternoon while my better half (over)filled the house with Xmas decorations. If anyone else wants to play with what I posted to improve it then feel free, but I am out of here as of now. :)

M23


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

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi all,

I am not doing anything else to this script - converting the algorithm was just a way of passing the time this afternoon while my better half (over)filled the house with Xmas decorations. If anyone else wants to play with what I posted to improve it then feel free, but I am out of here as of now. :)

M23

Me too, the other half is trying to single handedly shore up retail stock. The house is loaded!

Merry Christmas!

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

big_daddy has a great example of using word as a spell checker in your GUI:

Share this post


Link to post
Share on other sites

Noodle,

danwilli has advised the best alternative if you need an industrial strength spell checker.

However, while reading this thread something that M23 once said came to mind, "the thing about SRE's is knowing when to use them". With that in mind I came up with a rudimentary, all AutoIT spell checker. The dictionary is the same as above and can add/remove words. If a word is not found (misspelled) a list of words matching the most restrictive pattern from the start of the word is presented. You can chose to replace the word, cancel the replacement, add the word to the dictionary or delete one of the suggested words from the dictionary. The suggestions are presented in a simple listbox which does not support editing the selection. This could be changed to a listview item for greater flexibility. Also, the add/remove words capability should probably be on the main gui as well as the suggestions list.

As I said, this is a rudimentary spell checker, written mostly so that I don't have to help decorate the ##$%^#@ christmas tree!

#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <array.au3>
#include <string.au3>

#AutoIt3Wrapper_Add_Constants=n

local $st, $bad_word, $dict, $debug = false

local $gui010   =   guicreate('Spell Checker',600,600)
                    guictrlcreatelabel('Enter Text to Spell Check',10,10,250,20)
                    GUICtrlSetColor(-1,0xaa0000)
                    guictrlsetfont(-1,10,600)
local $edt010   =   guictrlcreateedit('',10,30,580,220)
                    guictrlcreatelabel('Status',10,260,200,20)
                    guictrlsetfont(-1,10,600)
                    guictrlsetcolor(-1,0xaa0000)
local $edt020   =   guictrlcreateedit('',10,280,580,250,$es_readonly+$ws_vscroll)
                    guictrlsetfont(-1,8,800,default,'Lucinda Console')
local $btn010   =   guictrlcreatebutton('Check Spelling',10,555,580,30)
                    guictrlsetcolor(-1,0x000088)
                    guictrlsetfont(-1,12,800,-1,'arial black')
                    guisetstate()

L020('Starting Dictionary Load')
local $fl = @scriptdir & '\wordlist.txt'
if not fileexists($fl) Then
    L020('Word Dictionary does not exist in Script Dir - Exiting in 5 Seconds')
    sleep(5000)
    Exit
endif
local $hfl= Fileopen($fl)
$dict = fileread($hfl)
fileclose($hfl)
$hfl = 0
L020('Dictionary Load Complete')

while 1

    switch guigetmsg()
        case $gui_event_close
            Exit
        case $btn010
            if not guictrlread($edt010) then
                L020('Input Blank - Enter One Or More Words To Check')
                guictrlsetstate($edt010,$gui_focus)
                continueloop
            endif
            $ret = check()
    endswitch

wend

func check()

    $st = timerinit()
    L020('Starting Spell Check')

    local $a10 = stringregexp(guictrlread($edt010),'(?i)\b\w+\b',3)
    if @error = 1 then
        L020('Spell Check finished [' & round(timerdiff($st)/1000,3) & ' seconds]')
        return
    endif
    for $1 = 0 to ubound($a10) - 1
        if $debug then L020('DEBUG - checking word = ' & $a10[$1])
        if stringregexp($dict,'(?i)\b' & $a10[$1] & '\b',0) then
            ContinueLoop
        else
            $ret = show_alternatives($a10[$1])
            if $ret = 1 then continueloop
            L020('Replacing "' & $a10[$1] & '" with "' & $ret & '"')
            guictrlsetdata($edt010,stringreplace(guictrlread($edt010),$a10[$1],stringlower($ret)))
        endif
    next

    L020('Spell Check finished [' & round(timerdiff($st)/1000,3) & ' seconds]')

    return 0

EndFunc

func show_alternatives($str)

    L020('"' & $str & '" is misspelled - suggesting alternative words')
    local $sre_array = 0, $save_error, $save_word
    local $gui020   = guicreate('',200,300)
    local $aSize    = wingetclientsize($gui020)
    local $lbx010   = guictrlcreatelist('',0,0,$aSize[0]-10,$aSize[1]-100,$ws_vscroll)
    local $btn010   = guictrlcreatebutton('Replace With Selected',10,$aSize[1]-90,$aSize[0]-20,20)
    local $btn020   = guictrlcreatebutton('Delete From Dictionary',10,$aSize[1]-60,$aSize[0]-20,20)
    local $btn030   = guictrlcreatebutton('Add To Dictionary',10,$aSize[1]-30,$aSize[0]-20,20)

    for $2 = 0 to stringlen($str) - 1
        if $debug then
            L020('DEBUG - Testing word pattern = ' & stringleft($str,stringlen($str) - $2))
            L020('DEBUG - Loop iteration = ' & $2)
        endif
        $sre_array = stringregexp($dict,'(?i)\b' & stringleft($str,stringlen($str) - $2) & '.*?\b',3)
        $save_error = @error
        switch $save_error
            case 1
                ContinueLoop
            case 0
                exitloop
            case 2
                L020('SRE ERROR pattern = ' & '(?i)\b' & stringleft($str,stringlen($str) - $2) & '.*?\b')
        EndSwitch
    Next

    if not isarray($sre_array) then
        L020('Unable to find suggestions for word = "' & $str & '"')
        return 1
    endif

    local $lbstr = '|' & $str

    for $2 = 0 to ubound($sre_array) - 1
        $lbstr &= '|' & $sre_array[$2]
    next

    guictrlsetdata($lbx010,$lbstr)
    guisetstate()

    while 1
        switch guigetmsg()
            case $gui_event_close
                L020('Replacement cancelled')
                guidelete($gui020)
                return 1
            case $btn010
                $save_word = guictrlread($lbx010)
                guidelete($gui020)
                return $save_word
            case $btn030
                $dict &= stringstripws(guictrlread($lbx010),3) & @lf
                l020('Adding Word = "' & guictrlread($lbx010) & '"')
                guidelete($gui020)
                filedelete($fl)
                filewrite($fl,$dict)
                $dict = fileread($fl)
                L020('Dictionary Refreshed')
                return 1
            case $btn020
                L020('Deleting Word = "' & guictrlread($lbx010) & '"')
                $dict = stringreplace($dict,guictrlread($lbx010),'')
                guidelete($gui020)
                filedelete($fl)
                filewrite($fl,$dict)
                $dict = fileread($fl)
                L020('Dictionary Refreshed')
                return 1
        endswitch
    wend

endfunc

func L020($str)
    guictrlsetdata($edt020,@hour & ':' & @min & ':' & @sec & ' ' & $str & @crlf,' ')
endfunc

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Thank you both for having a go at this for me,

once I started to play with it, I realized it was not a spell checker i need.

I was wanting something like what SciTE editor uses with suggestive words as you type,

I noticed ( I'm a little slow ) PhoenixXL has done a "Predict Text" script, so I've been playing with that,

It took me awhile to figure how to use it with my code ( I know only a tiny fraction of AutoIT and it's command set ),

but i got it working, but it's still not really what I want.

I find that if I have multiply word with similar letters at the beginning it only suggests the fist one, till i "type" past the character, then it offers the next one,

ie,

administration

admirable

admiration

admission

admittance

admixture

admonish

admonition

so if I'm after "admission", i have to type "admis" before it auto fills,

But if I had something that shows a pull down of suggestive words, that would be a better solution for my needs.

So I'll keep searching. I'm sure someone has done it before, I just need to find it,

thank you again, for the time you put into this.

After a few hours of searching I have found some examples, but they only work with single "words", and not in a sentence, time for more searching.

Nigel

Edited by Noddle

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

but it's still not really what I want.

What you really want is AutoSuggestion, I have already mentioned it as a Future Update in my PredictText UDF

The Basic Framework is ready,

I would convert it to UDF when i get sufficient time

For the time-being you could try the following and find a workaround ;)

Screenshot

Posted Image

Basic Framework

#cs
This is the Basic Framework of Auto-Suggestion UDF [date: 27.December.2012]
There might be many bugs.
#ce

;Author : Phoenix XL
#region -KeyPoints
; Suggestion of Words from a List
; The List is Minimized, and set Hidden when not required.
; The List is Updated as the User types.
; Pressing Enter sets the Text in the Edit.
; By Pressing Up and Down the user can choose b/w words.
; Pressing Left and Right will reset the Suggestion
#endregion -KeyPoints
;Known Bug : The Main GUI loses focus when List is clicked

#include-once
#include <GuiEdit.au3>
#include <SendMessage.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <Array.au3>
#include <GuiListBox.au3>

Opt('CaretCoordMode', 0)
Opt('GUIOnEventMode', 1)

Global $___cEdit, $___hSuggestGUI, $cWordLen = 0
Global $___Edit_Change = False, $hList, $List_SelChange = False

Global $_List[8] = ["administration with Evaluation", "admirable", _
"admiration", "admission", _
"admittance", "admixture", _
"admonish", "admonition"]

Global $hMainGUI = GUICreate(@ScriptName & ' | Phoenix XL', 300, 200)
GUISetOnEvent(-3, 'OnExit')
GUICtrlCreateLabel('Suggest Text - Basic Frameword', 10, 30, 200, 30)
Global $iEdit = GUICtrlCreateInput('', 10, 50, 280, 20)
_SetAutoSuggestion($iEdit, $hMainGUI, 50)
GUICtrlCreateLabel('Type "A" to find out what happens... :)', 10, 160, 200, 30)
GUICtrlCreateButton('Exit', 262, 160, 30, 30)
GUICtrlSetOnEvent(-1, 'OnExit')

;Dummies for Accelerators
Global $iUp = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, 'SetSel')
Global $iDown = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, 'SetSel')
Global $Left = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, 'Del')
Global $Right = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, 'Del')
Global $Enter = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, 'Set')


Global $aArray[5][2] = [['{UP}', $iUp],['{DOWN}', $iDown],['{LEFT}', $Left],['{RIGHT}', $Right],['{ENTER}', $Enter]]
GUISetAccelerators($aArray)
GUISetState()

Global $String, $Caret, $n, $Word
While 1
Sleep( 10 )
WEnd


Func _SetAutoSuggestion($iControl, $hParent, $iHeight = 50)
$___cEdit = GUICtrlGetHandle($iControl)
Local $aPos = ControlGetPos($hParent, '', $iControl)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
$___hSuggestGUI = GUICreate('', $aPos[2] / 2, $iHeight, _
- 1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_MDICHILD), $hParent)
GUICtrlCreateList('', 0, 0, $aPos[2] / 2, $iHeight, -1) ;ControlID = 4
$hList = GUICtrlGetHandle(-1)
GUICtrlSetColor(-1, 0xFF0080)
GUICtrlSetColor(-1, 0)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISwitch($hParent)
EndFunc   ;==>_SetAutoSuggestion


Func WM_COMMAND($hWnd, $iMsg, $wParam, $hWndFrom)
Local $nCode = _WinAPI_HiWord($wParam)
If $hWnd = $___hSuggestGUI Then
Switch $nCode
Case $LBN_SELCHANGE
GUISwitch($hMainGUI)
GUIRegisterMsg($WM_COMMAND, '')
_GUICtrlEdit_ReplaceSel($___cEdit, '')
$Caret = _GetCaretOffset()
$nWord = _GetCurrentWord()
$n = StringLen($nWord);
$Word = StringTrimLeft(_GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList)), $n)
_GUICtrlEdit_ReplaceSel($___cEdit, $Word)
_GUICtrlEdit_SetSel($___cEdit, $Caret, $Caret + StringLen($Word))
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
;Case $LBN_SETFOCUS
; $List_SelChange = True
;Case $LBN_KILLFOCUS
; $List_SelChange = False
EndSwitch
EndIf

Switch $hWndFrom
Case $___cEdit
Switch $nCode
Case $EN_CHANGE
$String = _ReturnStrings()
If $String Then
AutoSuggestionSetPos()
AutoSuggestionSetData($String)
_SuggestGUISetState()
Else
_SuggestGUISetState(@SW_HIDE)
EndIf
Case $EN_KILLFOCUS
Local $hFocus = _WinAPI_GetFocus()
If Not ($hFocus = $hList Or $hFocus = $___hSuggestGUI) Then _SuggestGUISetState(@SW_HIDE)
EndSwitch
EndSwitch
EndFunc   ;==>WM_COMMAND

Func _SuggestGUISetState($iCode = @SW_SHOWNOACTIVATE)
GUISetState($iCode, $___hSuggestGUI)
;If $iCode = @SW_HIDE Then AutoSuggestionSetData('')
EndFunc   ;==>_SuggestGUISetState

Func _ReturnStrings()
Local $sWord = _GetCurrentWord()
$cWordLen = StringLen($sWord)
Local $aRet[1] = [''], $iDimension, $iCount = 1
If Not $sWord Then Return
For $i = 0 To UBound($_List) - 1
;~   _ArrayDisplay($aRet)
Switch StringCompare(StringLeft($_List[$i], StringLen($sWord)), $sWord, 2)
Case 0
If $_List[$i] = $sWord Then ContinueLoop
If $aRet[0] = '' Then
$aRet[0] = $_List[$i]
Else
_ArrayAddEx($aRet, $_List[$i], $iDimension, $iCount)
EndIf
EndSwitch
Next
ReDim $aRet[$iCount]
Return _ArrayToString($aRet)
EndFunc   ;==>_ReturnStrings

Func AutoSuggestionSetData($sData, $iReset = 1)
Local $hPrv = GUISwitch($___hSuggestGUI)
Local $ControlID = _WinAPI_GetDlgCtrlID($hList)
If $iReset Then GUICtrlSetData($ControlID, '')
GUICtrlSetData($ControlID, $sData)
GUISwitch($hPrv)
EndFunc   ;==>AutoSuggestionSetData

Func AutoSuggestionSetPos($xOffset = 10, $yOffset = 17)
Local $aPos = _GUICtrlEdit_PosFromChar($___cEdit, _GetCaretOffset() - 1)
Local $cPos = _WinAPI_GetWindowRect($___cEdit)
For $i = 1 To 2
DllStructSetData($cPos, $i, DllStructGetData($cPos, $i) + $aPos[$i - 1])
Next
WinMove($___hSuggestGUI, '', DllStructGetData($cPos, 1) + $xOffset, DllStructGetData($cPos, 2) + $yOffset)
EndFunc   ;==>AutoSuggestionSetPos

Func IsSuggestionActive($iCondition = 2)
Return BitAND(WinGetState($___hSuggestGUI, ''), $iCondition)
EndFunc   ;==>IsSuggestionActive

Func SetSel()
If IsSuggestionActive() Then

Local $i, $Max = _GUICtrlListBox_GetCount($hList)
$i = _GUICtrlListBox_GetCurSel($hList)
Switch @GUI_CtrlId
Case $iDown
If $i = $Max Then Return
_GUICtrlListBox_SetCurSel($hList, $i + 1)
Case $iUp
If $i <= 0 Then Return
_GUICtrlListBox_SetCurSel($hList, $i - 1)
EndSwitch
;Notification is not sent until clicked this is a workaround
_SendMessage($___hSuggestGUI, $WM_COMMAND, _WinAPI_MakeLong(0, $LBN_SELCHANGE), $hList)
Else
SendAccel(@GUI_CtrlId)
EndIf
EndFunc   ;==>SetSel

Func Del()
If IsSuggestionActive() Then Return _SuggestGUISetState(@SW_HIDE) = 0
;~  MsgBox(0,0,@GUI_CtrlId)
SendAccel(@GUI_CtrlId)
EndFunc   ;==>Del

Func SendAccel($ID)
Local $hCtl = _WinAPI_GetFocus()
Local $hParent = _WinAPI_GetParent($hCtl)
Local $nId = _WinAPI_GetDlgCtrlID($hCtl)
Local $2Snd

If $ID = $Left Then $2Snd = '{LEFT}'
If $ID = $Right Then $2Snd = '{RIGHT}'
If $ID = $iUp Then $2Snd = '{UP}'
If $ID = $iDown Then $2Snd = '{DOWN}'
If $ID = $Enter Then $2Snd = '{ENTER}'

GUISwitch($hMainGUI)
GUISetAccelerators('')
ControlSend($hParent, '', $nId, $2Snd)
GUISetAccelerators($aArray)
EndFunc   ;==>SendAccel

Func Set()
If Del() Then _GUICtrlEdit_SetSel($___cEdit, -1, -1)
EndFunc   ;==>Set

Func _ArrayAddEx(ByRef $aArray, $sData, ByRef $iDimension, ByRef $iCount) ; Taken from Array.au3 and modified by guinness to reduce the use of ReDim.
If IsArray($aArray) = 0 Then
Return SetError(1, 0, -1)
EndIf
If UBound($aArray, 0) <> 1 Then
Return SetError(2, 0, -1)
EndIf
If $iCount = 0 Then
$iCount = UBound($aArray, 1)
EndIf
$iCount += 1
If ($iCount + 1) >= $iDimension Then
$iDimension = (UBound($aArray) + 1) * 2
ReDim $aArray[$iDimension]
EndIf
$aArray[$iCount - 1] = $sData
Return $iCount - 1
EndFunc   ;==>_ArrayAddEx

;From PredictText Library
Func _GetCurrentWord($_CaretIndex = -10, $cEnter = 0)
If $_CaretIndex = Default Then $_CaretIndex = -10
Local $_LineIndex
If $_CaretIndex = -10 Then $_CaretIndex = _GetCaretOffset()
If $_CaretIndex < 0 Then Return SetError(1, $_CaretIndex, -1)
Local $_Selection = _GUICtrlEdit_GetSel($___cEdit)
Switch $_Selection[0]
Case $_Selection[1]
$_LineIndex = _GUICtrlEdit_LineFromChar($___cEdit, -1)
Case Else
_GUICtrlEdit_SetSel($___cEdit, -1, -1)
$_LineIndex = _GUICtrlEdit_LineFromChar($___cEdit, -1)
_GUICtrlEdit_SetSel($___cEdit, $_Selection[0], $_Selection[1])
EndSwitch
$_LineIndex -= $cEnter
Local $_Offset = 0
For $Index = 0 To $_LineIndex - 1
$_Offset += StringLen(_GUICtrlEdit_GetLine($___cEdit, $Index)) + 2 ; 2 for Carriage Return and Line Feed
Next
Local $_LineText = _GUICtrlEdit_GetLine($___cEdit, $_LineIndex)
If $_LineText = -1 Then Return SetError(2, 0, -1)
Local $_SpaceSplit = StringSplit($_LineText, ' ', 1)
For $x = 1 To $_SpaceSplit[0]
Switch $_CaretIndex
Case $_Offset To $_Offset + StringLen($_SpaceSplit[$x])
Return SetError(0, $_Offset, $_SpaceSplit[$x])
EndSwitch
$_Offset += StringLen($_SpaceSplit[$x]) + 1
Next
Return SetError(1, 0, -1)
EndFunc   ;==>_GetCurrentWord

;From PredictText Library
Func _GetCaretOffset()
Local $_LineIndex = _GUICtrlEdit_GetSel($___cEdit)
If Not IsArray($_LineIndex) Then Return SetError(1, 0, -1)
Switch $_LineIndex[0]
Case $_LineIndex[1]
Return SetExtended(0, $_LineIndex[1])
Case Else
Local $_CoordMode = Opt('CaretCoordMode', 2)
Local $_Caret = WinGetCaretPos()
Local $_TextPos = _GUICtrlEdit_PosFromChar($___cEdit, $_LineIndex[0])
Opt('CaretCoordMode', $_CoordMode)
Return SetExtended(1, $_TextPos[0] = $_Caret[0] And $_Caret[1] = $_TextPos[1])
EndSwitch
EndFunc   ;==>_GetCaretOffset

Func OnExit()
GUIDelete($hMainGUI)
GUIDelete($___hSuggestGUI)
Exit
EndFunc   ;==>OnExit
Dont forget to use Tidy [the code is very messy] Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Hi,

This is a major cut down of my program,

but is enough to to show the main GUI,

I had a play with your "AutoSuggestion" but I was unable to get it work with my main GUI loop,

Can you have a look and see how it would integrate ?,

the $WordtoFind variable is what need to hold the entered data

any help would be appreciated.

also my code is rough, this is the first large program I wrote in AutoIt, you will see, how little I know of this language,

but I have updated parts of the code, as I learn better ways of doing things, and the command set.

Nigel

$version = "75a"




#include <array.au3>
 #include <file.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include 'PredictText.au3'

; this would be read from my dictonary
Dim $avArray [13] = ["crazy|baliw", "good|magandang", "morning|umaga", "kid|bata", "kids|mga bata", "good|mabait", "it's ok|okey lang", "i'm ok|okey lang ako", "money|kwarta", "to trick|atik", "eat|kain", "old|tiguwang", "flirty|igat"]
Dim $English_Filipino[1][3] ; 1 row, 3 columns
Dim $DisplayEng_Filipino[1][4] ; 1 row, 3 columns
Dim $SoundButton[1]
; would be read from my list or key words
Dim $Dictionary [13] = ["crazy", "good", "morning", "kid", "kids", "good", "it's ok", "i'm ok", "money", "to trick", "eat", "old", "flirty"] ; Dictonary for Auto Complete

$Language = 0
$Toclear = True
$ToRank = True
$find_Any_Part_word = False
$LaungTxt = "Bisaya"
$find_Full_word = False
$find_Any_word = False
$PartAny = False
$trap = False
$BuildSentence = False
$TempToRank = False
$Drives = DriveGetDrive("ALL")
$DictionaryLanguage = "EnglishDict.txt"

if @Compiled then
$Path = @ScriptDir & "\Audio\"
Else
$Path = "H:\. My How To Docs\Coding\AutoIT Code\Bisaya\Audio\"
; $Path = "D:\CD-Burn\Apps\Coding\AutoIT Code\Bisaya\Audio\"
EndIf



; _ArrayDisplay($CmdLine)
if ($CmdLine[0] > 0) and ($CmdLine[0] < 2) Then
if StringLower($CmdLine[1]) ="tagalog" Then
$LaungTxt="Tagalog"
$sSrc = "Tagalog.txt"
ElseIf StringLower($CmdLine[1]) ="bisayan" Then
$LaungTxt="Bisaya"
$sSrc = "Bisaya.txt"
EndIf
Else
Global $Form1 = GUICreate("", 233, 186)
; Global $Button1 = GUICtrlCreateButton("Bisaya", 56, 16, 121, 41)
Global $Button2 = GUICtrlCreateButton("Tagalog", 56, 72, 121, 41)
Global $Button3 = GUICtrlCreateButton("Exit", 56, 128, 121, 41)

GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
; Case $Button1
; GUISetState(@SW_HIDE)
; $LaungTxt="Bisaya"
; $sSrc = "Bisaya.txt"
; ExitLoop
Case $Button2
GUISetState(@SW_HIDE)
$LaungTxt="Tagalog"
$sSrc = "Tagalog.txt"
ExitLoop
Case $Button3
Exit
EndSwitch
WEnd
EndIf


_Initilize($English_Filipino) ; reads database


; create the form
Global $Form1 = GUICreate("English to "& $LaungTxt& " 1." & $version & " database size - "& UBound($avArray), 600, 420,-1,-1,$WS_MINIMIZEBOX + $WS_SIZEBOX), $Form2 = 999
GUICtrlSetResizing(-1, $GUI_DOCKLEFT)

; create input
Global $Input1 = GUICtrlCreateInput("", 16, 8, 323, 21)
Local $Edit_hWnd=GUICtrlGetHandle(-1) ; 75a Preditcive text This attaches to the $Input1 = GUICtrlCreateInput("", 16, 8, 323, 21) line above
GUICtrlSetFont(-1, 11, 400, 0, "Consolas")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUISetState()

_InitilizeDict() ; Load English word list for PredictText


;----------------

; select font size
$hCombo = GUICtrlCreateCombo("10", 350, 8, 40, 20)
GUICtrlSetData(-1, "11|12|13|14|15|16|17|18|19|20")
GUICtrlSetResizing(-1, $GUI_DOCKALL)

; search & reload buttons
Global $Search = GUICtrlCreateButton("Search", 18, 38, 97, 33)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $BuildButton = GUICtrlCreateButton("Build", 32, 75, 70, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

Global $Reload = GUICtrlCreateButton("Reload", 400, 8, 55, 22)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

If $LaungTxt="Tagalog" Then
Global $Restart = GUICtrlCreateButton("Bisayan", 400, 38, 55, 22)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Else
Global $Restart = GUICtrlCreateButton("Tagalog", 400, 38, 55, 22)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
EndIf

;Global $Restart = GUICtrlCreateButton("Restart", 400, 38, 55, 22)
;GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Sound = GUICtrlCreateButton("Sound", 400, 65, 55, 22)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

$yy=36
; radio button for full or partial word search
GUIStartGroup()
Global $Radio3 = GUICtrlCreateRadio("Full", 135, $yy, 65, 18)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Radio4 = GUICtrlCreateRadio("Part Full", 135, $yy+16, 65, 18)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Radio6 = GUICtrlCreateRadio("Part Any", 135, $yy+32, 65, 18)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Radio5 = GUICtrlCreateRadio("Any", 135, $yy+48, 65, 18)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Group2 = GUICtrlCreateGroup("", 125, 26, 80, 80)
GUICtrlSetResizing(-1, $GUI_DOCKALL)


GUIStartGroup()
$Checkbox1 = GUICtrlCreateCheckbox("Clear", 224, 40, 57, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Checkbox2 = GUICtrlCreateCheckbox("Rank", 224, 59, 65, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Group3 = GUICtrlCreateGroup("", 216, 32, 81, 55)
GUICtrlSetResizing(-1, $GUI_DOCKALL)


; radio buttons for launage type to search on
GUIStartGroup()
Global $Radio1 = GUICtrlCreateRadio("English", 316, 40, 57, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Radio2 = GUICtrlCreateRadio($LaungTxt, 316, 60, 57, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Group1 = GUICtrlCreateGroup("", 308, 32, 81, 55)
GUICtrlSetResizing(-1, $GUI_DOCKALL)


; preset what is set as default
GUICtrlSetState($Checkbox1, $GUI_CHECKED)
GUICtrlSetState($Checkbox2, $GUI_CHECKED)
GUICtrlSetState($Radio1, $GUI_CHECKED)
GUICtrlSetState($Radio4, $GUI_CHECKED)
GUICtrlSetState($Sound, $GUI_DISABLE)

; creates output area with Consolas Font
$Edit1 = GUICtrlCreateEdit("", 16, 110, 570, 275)
GUICtrlSetFont(-1, 11, 400, 0, "Consolas")
GUICtrlSetData(-1, "")
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

GUISetState(@SW_SHOW)


$WordtoFind="try these words" & @CRLF & @CRLF & "crazy, good, morning, kid, kids, good, it's ok" & @CRLF & "i'm ok, money, to trick, eat, old, flirty"
_DisplayOutput ()


winsetontop("English to "& $LaungTxt,"",1)
While 1
$nMsg = GUIGetMsg(1)
Switch $nMsg[1]
Case $Form1
Switch $nMsg[0]
Case $GUI_EVENT_CLOSE
Exit
Case $Sound
GUISetState(@SW_DISABLE, $Form1)
_Form2()

Case $Radio1
$DictionaryLanguage = "EnglishDict.txt"
_InitilizeDict()
; MsgBox(0,"","eng")

Case $Radio2
$DictionaryLanguage = $LaungTxt & "Dict.txt"
_InitilizeDict()
; MsgBox(0,"",$LaungTxt)

Case $Search
GUICtrlSetState($Sound, $GUI_DISABLE)
$WordtoFind = StringStripWS ( StringLower (GUICtrlRead($Input1)),1)
if $WordtoFind <> "" Then
$WordtoFind = _StripString ($WordtoFind)
If BitAnd(GUICtrlRead($Radio1),$GUI_CHECKED) Then
$Language = 0
Else
$Language =1
EndIf
If BitAnd(GUICtrlRead($Radio3),$GUI_CHECKED) Then
If $Toclear then Guictrlsetdata($Edit1,"")
_Findfullword($English_Filipino,$WordtoFind)
$find_Full_word = False
ElseIf BitAnd(GUICtrlRead($Radio4),$GUI_CHECKED) Then
If $Toclear then Guictrlsetdata($Edit1,"")
$find_Any_Part_word = False
_Findpartword($English_Filipino,$WordtoFind)
ElseIf BitAnd(GUICtrlRead($Radio5),$GUI_CHECKED) Then
If $Toclear then Guictrlsetdata($Edit1,"")
$find_Any_Part_word = True
_Findpartword($English_Filipino,$WordtoFind)
$find_Any_Part_word = False
ElseIf BitAnd(GUICtrlRead($Radio6),$GUI_CHECKED) Then
If $Toclear then Guictrlsetdata($Edit1,"")
$PartAny = True
_Findfullword($English_Filipino,$WordtoFind)
; $find_Full_word = False
$PartAny = False
EndIf
EndIf
Case $BuildButton
If BitAnd(GUICtrlRead($Radio1),$GUI_CHECKED) Then
$Language = 0
Else
$Language =1
EndIf
$WordtoFind = StringStripWS ( StringLower (GUICtrlRead($Input1)),1)
If $WordtoFind <> "" Then
GUICtrlSetState($Sound, $GUI_DISABLE)
$WordtoFind = _StripString ($WordtoFind)
If $Toclear then Guictrlsetdata($Edit1,"")
$find_Full_word = True
$BuildSentence = True
$find_Any_Part_word = False
_BuildSentence($English_Filipino, $WordtoFind)
EndIf

Case $Reload
_Initilize($English_Filipino)
Case $Checkbox1
$Toclear = Not $Toclear
Case $Checkbox2
$ToRank = Not $ToRank
Case $hCombo
GUICtrlSetFont(-1,GUICtrlRead($hCombo), 400, 0, "Consolas")
Case $Restart
If $LaungTxt="Tagalog" then
Run("English-Bisaya.exe Bisayan")
Else
Run("English-Bisaya.exe Tagalog")
EndIf
sleep(500)
exit
EndSwitch

Case $Form2
Switch $nMsg[0]
Case $GUI_EVENT_CLOSE
GUIDelete($Form2)
GUISetState(@SW_ENABLE, $Form1)
GUICtrlSetState($Sound, $GUI_DISABLE)
WinActivate ("English to "& $LaungTxt,"")
Case $SoundButton[1] To $SoundButton[$SoundButton[0]]
For $_x = 1 To UBound($SoundButton)-1
If ($nMsg[0] = $SoundButton[$_x]) Then
; msgbox(0,"",$Path & $LaungTxt &"\" & $DisplayEng_Filipino[$_x][3] & ".mp3")
SoundPlay ($Path & $LaungTxt &"\" & $DisplayEng_Filipino[$_x][3] & ".mp3",1)
EndIf
Next
EndSwitch
EndSwitch
WEnd

Func _Form2() ; audio buttons selection
GUISetState(@SW_SHOW)
EndFunc


Func _Initilize(ByRef $English_Filipino)
$xy = 0

; if NOT FileExists ($sSrc) Then
; MsgBox (0,"","Files does not exist")
; Exit
; EndIf
; _FileReadToArray($sSrc, $avArray)

ReDim $English_Filipino[UBound($avArray)][3]
$tt=TimerInit()
For $xy = 0 To UBound($avArray) - 1 ; build English and Filipino Arrays
if StringRegExp ($avArray[$xy],"(.*)\|(.*)\|(.*)") Then ; checks for 3 fields 2 x |
$StrReEx=StringRegExp ($avArray[$xy],"(.*)\|(.*)\|(.*)",1)
; msgbox(0,"",$StReEx[0])
$English_Filipino[$xy][0]=$StrReEx[0]
$English_Filipino[$xy][1]=$StrReEx[1]
$English_Filipino[$xy][2]=$StrReEx[2]

ElseIf StringRegExp ($avArray[$xy],"(.*)\|(.*)") Then ; checks for 2 fields 1 x |
$StrReEx=StringRegExp ($avArray[$xy],"(.*)\|(.*)",1)
; msgbox(0,"",$StReEx[0])
$English_Filipino[$xy][0]=$StrReEx[0]
$English_Filipino[$xy][1]=$StrReEx[1]
EndIf
Next
EndFunc

Func _InitilizeDict()
; if NOT FileExists ($DictionaryLanguage) Then
; MsgBox (0,"","Dictionary Files do not exist")
; Exit
; EndIf
; _FileReadToArray($DictionaryLanguage, $Dictionary) ; Dictionarry for Autocomplete

_RegisterPrediction($Edit_hWnd,$Dictionary,2,0)
EndFunc




Func _BuildSentence(byRef $English_Filipino, $WordtoFindX)
_DisplayOutput()
EndFunc


Func _Findfullword(ByRef $English_Filipino, $WordtoFindX) ; find partial string non Case
_DisplayOutput()
EndFunc


Func _Findpartword(ByRef $English_Filipino,$WordtoFind)
_DisplayOutput()
EndFunc



Func _DisplayOutput ()
GUICtrlSetData($Edit1, $WordtoFind & @CRLF)
EndFunc

Func _StripString ($stringstrip)
;
; use StrinRegExp to strip , ' ; / ( including inside ) [ includng inside ]
;
$stringstrip=StringRegExpReplace($stringstrip," "," ") ; strips any double spaces to a single space
$stringstrip=StringRegExpReplace($stringstrip,"([{}\^$&._%#!@=<>:;,~`'\’\*\?\/\+\|\\\\]|\-)","") ; looks for \^$&._%#!@=<>:;,~`'’*?\ and removes them, but not ( [ ] )
$stringstrip=StringRegExpReplace($stringstrip,"\(.*\)","") ; removes all information between ( and )
$stringstrip=StringRegExpReplace($stringstrip,"\[.*\]","") ; removes all information between [ and ]

; msgbox(0,"",$stringstrip)
Return StringStripWS ( $stringstrip, 2 )
EndFunc

Exit

Testing.au3

Edited by Noddle

Share this post


Link to post
Share on other sites

noodle,

There is a rudimentary auto-suggester in the code that I posted in #9. It does exactly this

so if I'm after "admission", i have to type "admis" before it auto fills,

But if I had something that shows a pull down of suggestive words, that would be a better solution for my needs.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

kylomas

I looked at this, I found in the end it was not a spellchecker i needed, but a autofill with a "word list",

the PredictText.au3 UDF worked very well, but i wanted to see what words were available to pick from as i typed them in,

PhoenixXL AutoSuggestion is exactly what I want, but i'm unable to integrate the code he has here,

i'm unable to figure out how to make it work with my GUI loop

Nigel

Share this post


Link to post
Share on other sites

Noodle,

I found in the end it was not a spellchecker i needed

or maybe not a spell checker at all. I thought that maybe you did not see the drop down list of suggsted words, that's all.

I'm sure that sooner or later PhoenixXL will read this and he/she is very helpfull.

Good Luck,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

noddle,

My framework required OnEventMode,

I just converted your Script to OnEventMode

and the Sound Button isnt organised much

I left that for you to organise

This is the code i edited, Suggests the Dictionary well

$version = "75a"
#region - Suggestion Variables and EnvironMent -

#include <GuiEdit.au3>
#include <SendMessage.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <Array.au3>
#include <GuiListBox.au3>
Global $___cEdit, $___hSuggestGUI, $cWordLen = 0
Global $___Edit_Change = False, $hList, $List_SelChange = False

Opt('CaretCoordMode', 0)

#endregion - Suggestion Variables and EnvironMent -
#cs
For $_x = 1 To UBound($SoundButton) - 1

Next
There is no organisation of the sound part, i therefore left it..
#ce

#include <array.au3>
#include <file.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; this would be read from my dictonary
Dim $avArray[13] = ["crazy|baliw", "good|magandang", "morning|umaga", "kid|bata", "kids|mga bata", "good|mabait", "it's ok|okey lang", "i'm ok|okey lang ako", "money|kwarta", "to trick|atik", "eat|kain", "old|tiguwang", "flirty|igat"]
Dim $English_Filipino[1][3] ; 1 row, 3 columns
Dim $DisplayEng_Filipino[1][4] ; 1 row, 3 columns
Dim $SoundButton[1]
; would be read from my list or key words
Global $Dictionary[13] = ["crazy", "good", "morning", "kid", "kids", "good", "it's ok", "i'm ok", "money", "to trick", "eat", "old", "flirty"] ; Dictonary for Auto Complete

$Language = 0
$Toclear = True
$ToRank = True
$find_Any_Part_word = False
$LaungTxt = "Bisaya"
$find_Full_word = False
$find_Any_word = False
$PartAny = False
$trap = False
$BuildSentence = False
$TempToRank = False
$Drives = DriveGetDrive("ALL")
$DictionaryLanguage = "EnglishDict.txt"

If @Compiled Then
$Path = @ScriptDir & "\Audio\"
Else
$Path = "H:\. My How To Docs\Coding\AutoIT Code\Bisaya\Audio\"
; $Path = "D:\CD-Burn\Apps\Coding\AutoIT Code\Bisaya\Audio\"
EndIf



; _ArrayDisplay($CmdLine)
If ($CmdLine[0] > 0) And ($CmdLine[0] < 2) Then
If StringLower($CmdLine[1]) = "tagalog" Then
$LaungTxt = "Tagalog"
$sSrc = "Tagalog.txt"
ElseIf StringLower($CmdLine[1]) = "bisayan" Then
$LaungTxt = "Bisaya"
$sSrc = "Bisaya.txt"
EndIf
Else
Global $Form2 = GUICreate("", 233, 186)
; Global $Button1 = GUICtrlCreateButton("Bisaya", 56, 16, 121, 41)
Global $Button2 = GUICtrlCreateButton("Tagalog", 56, 72, 121, 41)
Global $Button3 = GUICtrlCreateButton("Exit", 56, 128, 121, 41)

GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $Button3
OnExit()
Case $Button2
;Set to delete instead of hiding, made my work easier
;BTW you are assigning the same variable to both the GUI, you cannot even use explictly both GUI(s).
GUIDelete()
$LaungTxt = "Tagalog"
$sSrc = "Tagalog.txt"
ExitLoop
EndSwitch
WEnd
EndIf

Opt('GUIOnEventMode', 1)
GUISetOnEvent(-3, 'OnExit')

_Initilize($English_Filipino) ; reads database


; create the form
Global $Form1 = GUICreate("English to " & $LaungTxt & " 1." & $version & " database size - " & UBound($avArray), 600, 420, -1, -1, $WS_MINIMIZEBOX + $WS_SIZEBOX), $Form2 = 999
GUICtrlSetResizing(-1, $GUI_DOCKLEFT)
GUISetOnEvent(-3, 'OnExit')
; create input
Global $Input1 = GUICtrlCreateInput("", 16, 8, 323, 21)
GUICtrlSetFont(-1, 11, 400, 0, "Consolas")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
;Dummies for Accelerators
Global $iUp = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, 'SetSel')
Global $iDown = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, 'SetSel')
Global $Left = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, 'Del')
Global $Right = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, 'Del')
Global $Enter = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, 'Set')


Global $aArray[5][2] = [['{UP}', $iUp],['{DOWN}', $iDown],['{LEFT}', $Left],['{RIGHT}', $Right],['{ENTER}', $Enter]]
GUISetAccelerators($aArray)
GUISetState()

_InitilizeDict() ; Load English word list for PredictText


;----------------

; select font size
$hCombo = GUICtrlCreateCombo("10", 350, 8, 40, 20)
GUICtrlSetData(-1, "11|12|13|14|15|16|17|18|19|20")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetOnEvent(-1, 'hCombo')
; search & reload buttons
Global $Search = GUICtrlCreateButton("Search", 18, 38, 97, 33)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetOnEvent(-1, 'Search')
Global $BuildButton = GUICtrlCreateButton("Build", 32, 75, 70, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetOnEvent(-1, 'BuildButton')

Global $Reload = GUICtrlCreateButton("Reload", 400, 8, 55, 22)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetOnEvent(-1, 'Reload')

If $LaungTxt = "Tagalog" Then
Global $Restart = GUICtrlCreateButton("Bisayan", 400, 38, 55, 22)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Else
Global $Restart = GUICtrlCreateButton("Tagalog", 400, 38, 55, 22)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
EndIf
GUICtrlSetOnEvent(-1, 'Restart')

;Global $Restart = GUICtrlCreateButton("Restart", 400, 38, 55, 22)
;GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Sound = GUICtrlCreateButton("Sound", 400, 65, 55, 22)
GUICtrlSetOnEvent(-1, 'Sound')
GUICtrlSetResizing(-1, $GUI_DOCKALL)

$yy = 36
; radio button for full or partial word search
GUIStartGroup()
Global $Radio3 = GUICtrlCreateRadio("Full", 135, $yy, 65, 18)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Radio4 = GUICtrlCreateRadio("Part Full", 135, $yy + 16, 65, 18)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Radio6 = GUICtrlCreateRadio("Part Any", 135, $yy + 32, 65, 18)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Radio5 = GUICtrlCreateRadio("Any", 135, $yy + 48, 65, 18)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Group2 = GUICtrlCreateGroup("", 125, 26, 80, 80)
GUICtrlSetResizing(-1, $GUI_DOCKALL)


GUIStartGroup()
$Checkbox1 = GUICtrlCreateCheckbox("Clear", 224, 40, 57, 25)
GUICtrlSetOnEvent(-1, 'Checkbox1')
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Checkbox2 = GUICtrlCreateCheckbox("Rank", 224, 59, 65, 25)
GUICtrlSetOnEvent(-1, 'Checkbox2')
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Group3 = GUICtrlCreateGroup("", 216, 32, 81, 55)
GUICtrlSetResizing(-1, $GUI_DOCKALL)


; radio buttons for launage type to search on
GUIStartGroup()
Global $Radio1 = GUICtrlCreateRadio("English", 316, 40, 57, 25)
GUICtrlSetOnEvent(-1, 'Radio1')
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Radio2 = GUICtrlCreateRadio($LaungTxt, 316, 60, 57, 25)
GUICtrlSetOnEvent(-1, 'Radio2')
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Group1 = GUICtrlCreateGroup("", 308, 32, 81, 55)
GUICtrlSetResizing(-1, $GUI_DOCKALL)


; preset what is set as default
GUICtrlSetState($Checkbox1, $GUI_CHECKED)
GUICtrlSetState($Checkbox2, $GUI_CHECKED)
GUICtrlSetState($Radio1, $GUI_CHECKED)
GUICtrlSetState($Radio4, $GUI_CHECKED)
GUICtrlSetState($Sound, $GUI_DISABLE)

; creates output area with Consolas Font
$Edit1 = GUICtrlCreateEdit("", 16, 110, 570, 275)
GUICtrlSetFont(-1, 11, 400, 0, "Consolas")
GUICtrlSetData(-1, "")
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

For $_x = 1 To UBound($SoundButton) - 1
GUICtrlSetOnEvent( $SoundButton[$_x], 'SoundButton' )
Next

GUISetState(@SW_SHOW)


$WordtoFind = "try these words" & @CRLF & @CRLF & "crazy, good, morning, kid, kids, good, it's ok" & @CRLF & "i'm ok, money, to trick, eat, old, flirty"
_DisplayOutput()


WinSetOnTop("English to " & $LaungTxt, "", 1)

Func SoundButton()
SoundPlay($Path & $LaungTxt & "\" & $DisplayEng_Filipino[$_x][@GUI_CtrlId] & ".mp3", 1)
EndFunc

Func Sound()
GUISetState(@SW_DISABLE, $Form1)
_Form2()
EndFunc   ;==>Sound


Func Radio1()
$DictionaryLanguage = "EnglishDict.txt"
_InitilizeDict()
EndFunc   ;==>Radio1


Func Radio2()
$DictionaryLanguage = $LaungTxt & "Dict.txt"
_InitilizeDict()
EndFunc   ;==>Radio2

Func Search()
GUICtrlSetState($Sound, $GUI_DISABLE)
$WordtoFind = StringStripWS(StringLower(GUICtrlRead($Input1)), 1)
If $WordtoFind <> "" Then
$WordtoFind = _StripString($WordtoFind)
If BitAND(GUICtrlRead($Radio1), $GUI_CHECKED) Then
$Language = 0
Else
$Language = 1
EndIf
If BitAND(GUICtrlRead($Radio3), $GUI_CHECKED) Then
If $Toclear Then GUICtrlSetData($Edit1, "")
_Findfullword($English_Filipino, $WordtoFind)
$find_Full_word = False
ElseIf BitAND(GUICtrlRead($Radio4), $GUI_CHECKED) Then
If $Toclear Then GUICtrlSetData($Edit1, "")
$find_Any_Part_word = False
_Findpartword($English_Filipino, $WordtoFind)
ElseIf BitAND(GUICtrlRead($Radio5), $GUI_CHECKED) Then
If $Toclear Then GUICtrlSetData($Edit1, "")
$find_Any_Part_word = True
_Findpartword($English_Filipino, $WordtoFind)
$find_Any_Part_word = False
ElseIf BitAND(GUICtrlRead($Radio6), $GUI_CHECKED) Then
If $Toclear Then GUICtrlSetData($Edit1, "")
$PartAny = True
_Findfullword($English_Filipino, $WordtoFind)
; $find_Full_word = False
$PartAny = False
EndIf
EndIf
EndFunc   ;==>Search

Func BuildButton()
If BitAND(GUICtrlRead($Radio1), $GUI_CHECKED) Then
$Language = 0
Else
$Language = 1
EndIf
$WordtoFind = StringStripWS(StringLower(GUICtrlRead($Input1)), 1)
If $WordtoFind <> "" Then
GUICtrlSetState($Sound, $GUI_DISABLE)
$WordtoFind = _StripString($WordtoFind)
If $Toclear Then GUICtrlSetData($Edit1, "")
$find_Full_word = True
$BuildSentence = True
$find_Any_Part_word = False
_BuildSentence($English_Filipino, $WordtoFind)
EndIf
EndFunc   ;==>BuildButton

Func Reload()
_Initilize($English_Filipino)
EndFunc   ;==>Reload


Func Checkbox1()
$Toclear = Not $Toclear
EndFunc   ;==>Checkbox1

Func Checkbox2()
$ToRank = Not $ToRank
EndFunc   ;==>Checkbox2

Func hCombo()
GUICtrlSetFont(-1, GUICtrlRead($hCombo), 400, 0, "Consolas")
EndFunc   ;==>hCombo

Func Restart()
If $LaungTxt = "Tagalog" Then
Run("English-Bisaya.exe Bisayan")
Else
Run("English-Bisaya.exe Tagalog")
EndIf
Sleep(500)
OnExit()
EndFunc   ;==>Restart


Func _Form2() ; audio buttons selection
GUISetState(@SW_SHOW)
EndFunc   ;==>_Form2


Func _Initilize(ByRef $English_Filipino)
$xy = 0

; if NOT FileExists ($sSrc) Then
; MsgBox (0,"","Files does not exist")
; Exit
; EndIf
; _FileReadToArray($sSrc, $avArray)

ReDim $English_Filipino[UBound($avArray)][3]
$tt = TimerInit()
For $xy = 0 To UBound($avArray) - 1 ; build English and Filipino Arrays
If StringRegExp($avArray[$xy], "(.*)\|(.*)\|(.*)") Then ; checks for 3 fields 2 x |
$StrReEx = StringRegExp($avArray[$xy], "(.*)\|(.*)\|(.*)", 1)
; msgbox(0,"",$StReEx[0])
$English_Filipino[$xy][0] = $StrReEx[0]
$English_Filipino[$xy][1] = $StrReEx[1]
$English_Filipino[$xy][2] = $StrReEx[2]

ElseIf StringRegExp($avArray[$xy], "(.*)\|(.*)") Then ; checks for 2 fields 1 x |
$StrReEx = StringRegExp($avArray[$xy], "(.*)\|(.*)", 1)
; msgbox(0,"",$StReEx[0])
$English_Filipino[$xy][0] = $StrReEx[0]
$English_Filipino[$xy][1] = $StrReEx[1]
EndIf
Next
EndFunc   ;==>_Initilize

Func _InitilizeDict()
; if NOT FileExists ($DictionaryLanguage) Then
; MsgBox (0,"","Dictionary Files do not exist")
; Exit
; EndIf
; _FileReadToArray($DictionaryLanguage, $Dictionary) ; Dictionarry for Autocomplete

_SetAutoSuggestion($Input1, $Form1, 50)
EndFunc   ;==>_InitilizeDict




Func _BuildSentence(ByRef $English_Filipino, $WordtoFindX)
_DisplayOutput()
EndFunc   ;==>_BuildSentence


Func _Findfullword(ByRef $English_Filipino, $WordtoFindX) ; find partial string non Case
_DisplayOutput()
EndFunc   ;==>_Findfullword


Func _Findpartword(ByRef $English_Filipino, $WordtoFind)
_DisplayOutput()
EndFunc   ;==>_Findpartword



Func _DisplayOutput()
GUICtrlSetData($Edit1, $WordtoFind & @CRLF)
EndFunc   ;==>_DisplayOutput

Func _StripString($stringstrip)
;
; use StrinRegExp to strip , ' ; / ( including inside ) [ includng inside ]
;
$stringstrip = StringRegExpReplace($stringstrip, " ", " ") ; strips any double spaces to a single space
$stringstrip = StringRegExpReplace($stringstrip, "([{}\^$&._%#!@=<>:;,~`'\’\*\?\/\+\|\\\\]|\-)", "") ; looks for \^$&._%#!@=<>:;,~`'’*?\ and removes them, but not ( [ ] )
$stringstrip = StringRegExpReplace($stringstrip, "\(.*\)", "") ; removes all information between ( and )
$stringstrip = StringRegExpReplace($stringstrip, "\[.*\]", "") ; removes all information between [ and ]

; msgbox(0,"",$stringstrip)
Return StringStripWS($stringstrip, 2)
EndFunc   ;==>_StripString



#region - AutoSuggestion UDF -
Func _SetAutoSuggestion($iControl, $hParent, $iHeight = 50)
$___cEdit = GUICtrlGetHandle($iControl)
Local $aPos = ControlGetPos($hParent, '', $iControl)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
$___hSuggestGUI = GUICreate('', $aPos[2] / 2, $iHeight, _
- 1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_MDICHILD), $hParent)
GUICtrlCreateList('', 0, 0, $aPos[2] / 2, $iHeight, -1) ;ControlID = 4
$hList = GUICtrlGetHandle(-1)
GUICtrlSetColor(-1, 0xFF0080)
GUICtrlSetColor(-1, 0)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISwitch($hParent)
EndFunc   ;==>_SetAutoSuggestion


Func WM_COMMAND($hWnd, $iMsg, $wParam, $hWndFrom)
Local $nCode = _WinAPI_HiWord($wParam)
If $hWnd = $___hSuggestGUI Then
Switch $nCode
Case $LBN_SELCHANGE
GUISwitch($Form1)
GUIRegisterMsg($WM_COMMAND, '')
_GUICtrlEdit_ReplaceSel($___cEdit, '')
$Caret = _GetCaretOffset()
$nWord = _GetCurrentWord()
$n = StringLen($nWord);
$Word = StringTrimLeft(_GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList)), $n)
_GUICtrlEdit_ReplaceSel($___cEdit, $Word)
_GUICtrlEdit_SetSel($___cEdit, $Caret, $Caret + StringLen($Word))
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
;Case $LBN_SETFOCUS
; $List_SelChange = True
;Case $LBN_KILLFOCUS
; $List_SelChange = False
EndSwitch
EndIf

Switch $hWndFrom
Case $___cEdit
Switch $nCode
Case $EN_CHANGE
$String = _ReturnStrings()
If $String Then
AutoSuggestionSetPos()
AutoSuggestionSetData($String)
_SuggestGUISetState()
Else
_SuggestGUISetState(@SW_HIDE)
EndIf
Case $EN_KILLFOCUS
Local $hFocus = _WinAPI_GetFocus()
If Not ($hFocus = $hList Or $hFocus = $___hSuggestGUI) Then _SuggestGUISetState(@SW_HIDE)
EndSwitch
EndSwitch
EndFunc   ;==>WM_COMMAND

Func _SuggestGUISetState($iCode = @SW_SHOWNOACTIVATE)
GUISetState($iCode, $___hSuggestGUI)
;If $iCode = @SW_HIDE Then AutoSuggestionSetData('')
EndFunc   ;==>_SuggestGUISetState

Func _ReturnStrings()
Local $sWord = _GetCurrentWord()
$cWordLen = StringLen($sWord)
Local $aRet[1] = [''], $iDimension, $iCount = 1
If Not $sWord Then Return
For $i = 0 To UBound($Dictionary) - 1
;~ _ArrayDisplay($aRet)
Switch StringCompare(StringLeft($Dictionary[$i], StringLen($sWord)), $sWord, 2)
Case 0
If $Dictionary[$i] = $sWord Then ContinueLoop
If $aRet[0] = '' Then
$aRet[0] = $Dictionary[$i]
Else
_ArrayAddEx($aRet, $Dictionary[$i], $iDimension, $iCount)
EndIf
EndSwitch
Next
ReDim $aRet[$iCount]
Return _ArrayToString($aRet)
EndFunc   ;==>_ReturnStrings

Func AutoSuggestionSetData($sData, $iReset = 1)
Local $hPrv = GUISwitch($___hSuggestGUI)
Local $ControlID = _WinAPI_GetDlgCtrlID($hList)
If $iReset Then GUICtrlSetData($ControlID, '')
GUICtrlSetData($ControlID, $sData)
GUISwitch($hPrv)
EndFunc   ;==>AutoSuggestionSetData

Func AutoSuggestionSetPos($xOffset = 10, $yOffset = 17)
Local $aPos = _GUICtrlEdit_PosFromChar($___cEdit, _GetCaretOffset() - 1)
Local $cPos = _WinAPI_GetWindowRect($___cEdit)
For $i = 1 To 2
DllStructSetData($cPos, $i, DllStructGetData($cPos, $i) + $aPos[$i - 1])
Next
WinMove($___hSuggestGUI, '', DllStructGetData($cPos, 1) + $xOffset, DllStructGetData($cPos, 2) + $yOffset)
EndFunc   ;==>AutoSuggestionSetPos

Func IsSuggestionActive($iCondition = 2)
Return BitAND(WinGetState($___hSuggestGUI, ''), $iCondition)
EndFunc   ;==>IsSuggestionActive

Func SetSel()
If IsSuggestionActive() Then

Local $i, $Max = _GUICtrlListBox_GetCount($hList)
$i = _GUICtrlListBox_GetCurSel($hList)
Switch @GUI_CtrlId
Case $iDown
If $i = $Max Then Return
_GUICtrlListBox_SetCurSel($hList, $i + 1)
Case $iUp
If $i <= 0 Then Return
_GUICtrlListBox_SetCurSel($hList, $i - 1)
EndSwitch
;Notification is not sent until clicked this is a workaround
_SendMessage($___hSuggestGUI, $WM_COMMAND, _WinAPI_MakeLong(0, $LBN_SELCHANGE), $hList)
Else
SendAccel(@GUI_CtrlId)
EndIf
EndFunc   ;==>SetSel

Func Del()
If IsSuggestionActive() Then Return _SuggestGUISetState(@SW_HIDE) = 0
;~ MsgBox(0,0,@GUI_CtrlId)
SendAccel(@GUI_CtrlId)
EndFunc   ;==>Del

Func SendAccel($ID)
Local $hCtl = _WinAPI_GetFocus()
Local $hParent = _WinAPI_GetParent($hCtl)
Local $nId = _WinAPI_GetDlgCtrlID($hCtl)
Local $2Snd

If $ID = $Left Then $2Snd = '{LEFT}'
If $ID = $Right Then $2Snd = '{RIGHT}'
If $ID = $iUp Then $2Snd = '{UP}'
If $ID = $iDown Then $2Snd = '{DOWN}'
If $ID = $Enter Then $2Snd = '{ENTER}'

GUISwitch($Form1)
GUISetAccelerators('')
ControlSend($hParent, '', $nId, $2Snd)
GUISetAccelerators($aArray)
EndFunc   ;==>SendAccel

Func Set()
If Del() Then _GUICtrlEdit_SetSel($___cEdit, -1, -1)
EndFunc   ;==>Set

Func _ArrayAddEx(ByRef $aArray, $sData, ByRef $iDimension, ByRef $iCount) ; Taken from Array.au3 and modified by guinness to reduce the use of ReDim.
If IsArray($aArray) = 0 Then
Return SetError(1, 0, -1)
EndIf
If UBound($aArray, 0) <> 1 Then
Return SetError(2, 0, -1)
EndIf
If $iCount = 0 Then
$iCount = UBound($aArray, 1)
EndIf
$iCount += 1
If ($iCount + 1) >= $iDimension Then
$iDimension = (UBound($aArray) + 1) * 2
ReDim $aArray[$iDimension]
EndIf
$aArray[$iCount - 1] = $sData
Return $iCount - 1
EndFunc   ;==>_ArrayAddEx

;From PredictText Library
Func _GetCurrentWord($_CaretIndex = -10, $cEnter = 0)
If $_CaretIndex = Default Then $_CaretIndex = -10
Local $_LineIndex
If $_CaretIndex = -10 Then $_CaretIndex = _GetCaretOffset()
If $_CaretIndex < 0 Then Return SetError(1, $_CaretIndex, -1)
Local $_Selection = _GUICtrlEdit_GetSel($___cEdit)
Switch $_Selection[0]
Case $_Selection[1]
$_LineIndex = _GUICtrlEdit_LineFromChar($___cEdit, -1)
Case Else
_GUICtrlEdit_SetSel($___cEdit, -1, -1)
$_LineIndex = _GUICtrlEdit_LineFromChar($___cEdit, -1)
_GUICtrlEdit_SetSel($___cEdit, $_Selection[0], $_Selection[1])
EndSwitch
$_LineIndex -= $cEnter
Local $_Offset = 0
For $Index = 0 To $_LineIndex - 1
$_Offset += StringLen(_GUICtrlEdit_GetLine($___cEdit, $Index)) + 2 ; 2 for Carriage Return and Line Feed
Next
Local $_LineText = _GUICtrlEdit_GetLine($___cEdit, $_LineIndex)
If $_LineText = -1 Then Return SetError(2, 0, -1)
Local $_SpaceSplit = StringSplit($_LineText, ' ', 1)
For $x = 1 To $_SpaceSplit[0]
Switch $_CaretIndex
Case $_Offset To $_Offset + StringLen($_SpaceSplit[$x])
Return SetError(0, $_Offset, $_SpaceSplit[$x])
EndSwitch
$_Offset += StringLen($_SpaceSplit[$x]) + 1
Next
Return SetError(1, 0, -1)
EndFunc   ;==>_GetCurrentWord

;From PredictText Library
Func _GetCaretOffset()
Local $_LineIndex = _GUICtrlEdit_GetSel($___cEdit)
If Not IsArray($_LineIndex) Then Return SetError(1, 0, -1)
Switch $_LineIndex[0]
Case $_LineIndex[1]
Return SetExtended(0, $_LineIndex[1])
Case Else
Local $_CoordMode = Opt('CaretCoordMode', 2)
Local $_Caret = WinGetCaretPos()
Local $_TextPos = _GUICtrlEdit_PosFromChar($___cEdit, $_LineIndex[0])
Opt('CaretCoordMode', $_CoordMode)
Return SetExtended(1, $_TextPos[0] = $_Caret[0] And $_Caret[1] = $_TextPos[1])
EndSwitch
EndFunc   ;==>_GetCaretOffset

Func OnExit()
GUIDelete($Form1)
GUIDelete($___hSuggestGUI)
Exit
EndFunc   ;==>OnExit

#endregion - AutoSuggestion UDF -

;Lifelong Loop
While 1
Sleep(10)
WEnd

Thumbs up if it helped ;)

kylomas,

I'm sure that sooner or later PhoenixXL will read this and he/she is very helpfull.

Its "He" indeed :) Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

noddle,

My framework required OnEventMode,

I just converted your Script to OnEventMode

and the Sound Button isnt organised much

I left that for you to organise

This is the code i edited, Suggests the Dictionary well

Thumbs up if it helped ;)

I tried add the extra bits for the sound "list" but I'm not having much luck, but I got the rest working

maybe I should have done the code originally using "on event" like VB or Delphi,

but I did not,

I added the "sound GUI", which builds "buttons on the fly" for what it need to show

I have hard coded an array to hold some dummy "sound files"

i added comments for where I change the code from the original one I posted earlier.

If u have some spare time PhoenixXL to add this into the code u already changed for me, it would be most appreciated

Just start it, and hit the "Sound" button

Thank you again

Nigel

$version = "75a"

#include <array.au3>
#include <file.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include 'PredictText.au3'

; this would be read from my dictonary
Dim $avArray [13] = ["crazy|baliw", "good|magandang", "morning|umaga", "kid|bata", "kids|mga bata", "good|mabait", "it's ok|okey lang", "i'm ok|okey lang ako", "money|kwarta", "to trick|atik", "eat|kain", "old|tiguwang", "flirty|igat"]

Dim $English_Filipino[1][3] ; 1 row, 3 columns
Dim $DisplayEng_Filipino[1][4] ; 1 row, 4 columns
Dim $SoundButton[1]
; would be read from my list or key words
Dim $Dictionary [13] = ["crazy", "good", "morning", "kid", "kids", "good", "it's ok", "i'm ok", "money", "to trick", "eat", "old", "flirty"] ; Dictonary for Auto Complete

;----------------------------------------------- Sound -------------------------------------------------------------------------------------Sound-------------------------------
Global $DisplayEng_Filipino[3][4] = [["english word 1","None English 1","","sound file1"],["english word 2","None English 2","","sound file2"],["english word 3","None English 3","","sound file3"]]
$Debugg=false
;----------------------------------------------- Sound -------------------------------------------------------------------------------------Sound-------------------------------

$Language = 0
$Toclear = True
$ToRank = True
$find_Any_Part_word = False
$LaungTxt = "Bisaya"
$find_Full_word = False
$find_Any_word = False
$PartAny = False
$trap = False
$BuildSentence = False
$TempToRank = False
$Drives = DriveGetDrive("ALL")
$DictionaryLanguage = "EnglishDict.txt"

if @Compiled then
$Path = @ScriptDir & "\Audio\"
Else
$Path = "H:\. My How To Docs\Coding\AutoIT Code\Bisaya\Audio\"
; $Path = "D:\CD-Burn\Apps\Coding\AutoIT Code\Bisaya\Audio\"
EndIf



; _ArrayDisplay($CmdLine)
if ($CmdLine[0] > 0) and ($CmdLine[0] < 2) Then
if StringLower($CmdLine[1]) ="tagalog" Then
$LaungTxt="Tagalog"
$sSrc = "Tagalog.txt"
ElseIf StringLower($CmdLine[1]) ="bisayan" Then
$LaungTxt="Bisaya"
$sSrc = "Bisaya.txt"
EndIf
Else
Global $Form1 = GUICreate("", 233, 186)
; Global $Button1 = GUICtrlCreateButton("Bisaya", 56, 16, 121, 41)
Global $Button2 = GUICtrlCreateButton("Tagalog", 56, 72, 121, 41)
Global $Button3 = GUICtrlCreateButton("Exit", 56, 128, 121, 41)

GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
; Case $Button1
; GUISetState(@SW_HIDE)
; $LaungTxt="Bisaya"
; $sSrc = "Bisaya.txt"
; ExitLoop
Case $Button2
GUISetState(@SW_HIDE)
$LaungTxt="Tagalog"
$sSrc = "Tagalog.txt"
ExitLoop
Case $Button3
Exit
EndSwitch
WEnd
EndIf


_Initilize($English_Filipino) ; reads database


; create the form
Global $Form1 = GUICreate("English to "& $LaungTxt& " 1." & $version & " database size - "& UBound($avArray), 600, 420,-1,-1,$WS_MINIMIZEBOX + $WS_SIZEBOX), $Form2 = 999
GUICtrlSetResizing(-1, $GUI_DOCKLEFT)

; create input
Global $Input1 = GUICtrlCreateInput("", 16, 8, 323, 21)
Local $Edit_hWnd=GUICtrlGetHandle(-1) ; 75a Preditcive text This attaches to the $Input1 = GUICtrlCreateInput("", 16, 8, 323, 21) line above
GUICtrlSetFont(-1, 11, 400, 0, "Consolas")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUISetState()

_InitilizeDict() ; Load English word list for PredictText


;----------------

; select font size
$hCombo = GUICtrlCreateCombo("10", 350, 8, 40, 20)
GUICtrlSetData(-1, "11|12|13|14|15|16|17|18|19|20")
GUICtrlSetResizing(-1, $GUI_DOCKALL)

; search & reload buttons
Global $Search = GUICtrlCreateButton("Search", 18, 38, 97, 33)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $BuildButton = GUICtrlCreateButton("Build", 32, 75, 70, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

Global $Reload = GUICtrlCreateButton("Reload", 400, 8, 55, 22)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

If $LaungTxt="Tagalog" Then
Global $Restart = GUICtrlCreateButton("Bisayan", 400, 38, 55, 22)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Else
Global $Restart = GUICtrlCreateButton("Tagalog", 400, 38, 55, 22)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
EndIf

;Global $Restart = GUICtrlCreateButton("Restart", 400, 38, 55, 22)
;GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Sound = GUICtrlCreateButton("Sound", 400, 65, 55, 22)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

$yy=36
; radio button for full or partial word search
GUIStartGroup()
Global $Radio3 = GUICtrlCreateRadio("Full", 135, $yy, 65, 18)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Radio4 = GUICtrlCreateRadio("Part Full", 135, $yy+16, 65, 18)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Radio6 = GUICtrlCreateRadio("Part Any", 135, $yy+32, 65, 18)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Radio5 = GUICtrlCreateRadio("Any", 135, $yy+48, 65, 18)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Group2 = GUICtrlCreateGroup("", 125, 26, 80, 80)
GUICtrlSetResizing(-1, $GUI_DOCKALL)


GUIStartGroup()
$Checkbox1 = GUICtrlCreateCheckbox("Clear", 224, 40, 57, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Checkbox2 = GUICtrlCreateCheckbox("Rank", 224, 59, 65, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Group3 = GUICtrlCreateGroup("", 216, 32, 81, 55)
GUICtrlSetResizing(-1, $GUI_DOCKALL)


; radio buttons for launage type to search on
GUIStartGroup()
Global $Radio1 = GUICtrlCreateRadio("English", 316, 40, 57, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Radio2 = GUICtrlCreateRadio($LaungTxt, 316, 60, 57, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
Global $Group1 = GUICtrlCreateGroup("", 308, 32, 81, 55)
GUICtrlSetResizing(-1, $GUI_DOCKALL)


; preset what is set as default
GUICtrlSetState($Checkbox1, $GUI_CHECKED)
GUICtrlSetState($Checkbox2, $GUI_CHECKED)
GUICtrlSetState($Radio1, $GUI_CHECKED)
GUICtrlSetState($Radio4, $GUI_CHECKED)

;----------------------------------------------- Sound -------------------------------------------------------------------------------------Sound-------------------------------
; GUICtrlSetState($Sound, $GUI_DISABLE)
;----------------------------------------------- Sound -------------------------------------------------------------------------------------Sound-------------------------------

; creates output area with Consolas Font
$Edit1 = GUICtrlCreateEdit("", 16, 110, 570, 275)
GUICtrlSetFont(-1, 11, 400, 0, "Consolas")
GUICtrlSetData(-1, "")
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

GUISetState(@SW_SHOW)


$WordtoFind="try these words" & @CRLF & @CRLF & "crazy, good, morning, kid, kids, good, it's ok" & @CRLF & "i'm ok, money, to trick, eat, old, flirty"
_DisplayOutput ()

;----------------------------------------------- Sound -------------------------------------------------------------------------------------Sound-------------------------------
;winsetontop("English to "& $LaungTxt,"",1)
;----------------------------------------------- Sound -------------------------------------------------------------------------------------Sound-------------------------------

While 1
$nMsg = GUIGetMsg(1)
Switch $nMsg[1]
Case $Form1
Switch $nMsg[0]
Case $GUI_EVENT_CLOSE
Exit
Case $Sound
GUISetState(@SW_DISABLE, $Form1)
_Form2()

Case $Radio1
$DictionaryLanguage = "EnglishDict.txt"
_InitilizeDict()
; MsgBox(0,"","eng")

Case $Radio2
$DictionaryLanguage = $LaungTxt & "Dict.txt"
_InitilizeDict()
; MsgBox(0,"",$LaungTxt)

Case $Search
GUICtrlSetState($Sound, $GUI_DISABLE)
$WordtoFind = StringStripWS ( StringLower (GUICtrlRead($Input1)),1)
if $WordtoFind <> "" Then
$WordtoFind = _StripString ($WordtoFind)
If BitAnd(GUICtrlRead($Radio1),$GUI_CHECKED) Then
$Language = 0
Else
$Language =1
EndIf
If BitAnd(GUICtrlRead($Radio3),$GUI_CHECKED) Then
If $Toclear then Guictrlsetdata($Edit1,"")
_Findfullword($English_Filipino,$WordtoFind)
$find_Full_word = False
ElseIf BitAnd(GUICtrlRead($Radio4),$GUI_CHECKED) Then
If $Toclear then Guictrlsetdata($Edit1,"")
$find_Any_Part_word = False
_Findpartword($English_Filipino,$WordtoFind)
ElseIf BitAnd(GUICtrlRead($Radio5),$GUI_CHECKED) Then
If $Toclear then Guictrlsetdata($Edit1,"")
$find_Any_Part_word = True
_Findpartword($English_Filipino,$WordtoFind)
$find_Any_Part_word = False
ElseIf BitAnd(GUICtrlRead($Radio6),$GUI_CHECKED) Then
If $Toclear then Guictrlsetdata($Edit1,"")
$PartAny = True
_Findfullword($English_Filipino,$WordtoFind)
; $find_Full_word = False
$PartAny = False
EndIf
EndIf
Case $BuildButton
If BitAnd(GUICtrlRead($Radio1),$GUI_CHECKED) Then
$Language = 0
Else
$Language =1
EndIf
$WordtoFind = StringStripWS ( StringLower (GUICtrlRead($Input1)),1)
If $WordtoFind <> "" Then
GUICtrlSetState($Sound, $GUI_DISABLE)
$WordtoFind = _StripString ($WordtoFind)
If $Toclear then Guictrlsetdata($Edit1,"")
$find_Full_word = True
$BuildSentence = True
$find_Any_Part_word = False
_BuildSentence($English_Filipino, $WordtoFind)
EndIf

Case $Reload
_Initilize($English_Filipino)
Case $Checkbox1
$Toclear = Not $Toclear
Case $Checkbox2
$ToRank = Not $ToRank
Case $hCombo
GUICtrlSetFont(-1,GUICtrlRead($hCombo), 400, 0, "Consolas")
Case $Restart
If $LaungTxt="Tagalog" then
Run("English-Bisaya.exe Bisayan")
Else
Run("English-Bisaya.exe Tagalog")
EndIf
sleep(500)
exit
EndSwitch

Case $Form2
Switch $nMsg[0]
Case $GUI_EVENT_CLOSE
GUIDelete($Form2)
GUISetState(@SW_ENABLE, $Form1)
GUICtrlSetState($Sound, $GUI_DISABLE)
WinActivate ("English to "& $LaungTxt,"")
Case $SoundButton[1] To $SoundButton[$SoundButton[0]]
For $_x = 1 To UBound($SoundButton)-1
If ($nMsg[0] = $SoundButton[$_x]) Then

;----------------------------------------------- Sound -------------------------------------------------------------------------------------Sound-------------------------------
msgbox(0,"",$Path & $LaungTxt &"\" & $DisplayEng_Filipino[$_x][3] & ".mp3")
;----------------------------------------------- Sound -------------------------------------------------------------------------------------Sound-------------------------------

SoundPlay ($Path & $LaungTxt &"\" & $DisplayEng_Filipino[$_x][3] & ".mp3",1)
EndIf
Next
EndSwitch
EndSwitch
WEnd

Func _Form2() ; audio buttons selection
;----------------------------------------------- Sound -------------------------------------------------------------------------------------Sound-------------------------------
For $x = 0 To UBound($DisplayEng_Filipino)-1
If $x = UBound($DisplayEng_Filipino) Then ExitLoop
If StringLen($DisplayEng_Filipino[$x][3]) < 2 Then
_ArrayDelete($DisplayEng_Filipino, $x) ; remove non audio from array
$x = $x - 1
EndIf
Next
; _ArrayDisplay ($DisplayEng_Filipino)

$temp=0
$Englen=0
If $Debugg = False Then
For $x = 1 To UBound ($DisplayEng_Filipino) -1
$temp = StringLen($DisplayEng_Filipino[$x][0] & " - " & $DisplayEng_Filipino[$x][1])
if $temp > $Englen then $Englen = $temp
Next

; if $Englen < 22 then $Englen = 22
$Form2 = GUICreate("Found Audio Clips", ($Englen*7)+35, (UBound($DisplayEng_Filipino) *28))
winsetontop("Found Audio Clip","",1)
Endif
$count = 0
For $x = 1 to UBound($DisplayEng_Filipino)-1 ; finding how many sound file exist for the search result
$count = $count +1
ReDim $SoundButton[($count+1)]
$y = ($count * 28 )+10
$SoundButton[$count] = GUICtrlCreateButton($DisplayEng_Filipino[$x][0] & " - " & $DisplayEng_Filipino[$x][1],5, $y-25, ($Englen * 7)+25, 28, 30) ; build buttons
$SoundButton[0]=$count

Next
GUISetState(@SW_SHOW)
;----------------------------------------------- Sound -------------------------------------------------------------------------------------Sound-------------------------------
EndFunc


Func _Initilize(ByRef $English_Filipino)
$xy = 0

; if NOT FileExists ($sSrc) Then
; MsgBox (0,"","Files does not exist")
; Exit
; EndIf
; _FileReadToArray($sSrc, $avArray)

ReDim $English_Filipino[UBound($avArray)][3]
$tt=TimerInit()
For $xy = 0 To UBound($avArray) - 1 ; build English and Filipino Arrays
if StringRegExp ($avArray[$xy],"(.*)\|(.*)\|(.*)") Then ; checks for 3 fields 2 x |
$StrReEx=StringRegExp ($avArray[$xy],"(.*)\|(.*)\|(.*)",1)
; msgbox(0,"",$StReEx[0])
$English_Filipino[$xy][0]=$StrReEx[0]
$English_Filipino[$xy][1]=$StrReEx[1]
$English_Filipino[$xy][2]=$StrReEx[2]

ElseIf StringRegExp ($avArray[$xy],"(.*)\|(.*)") Then ; checks for 2 fields 1 x |
$StrReEx=StringRegExp ($avArray[$xy],"(.*)\|(.*)",1)
; msgbox(0,"",$StReEx[0])
$English_Filipino[$xy][0]=$StrReEx[0]
$English_Filipino[$xy][1]=$StrReEx[1]
EndIf
Next
EndFunc

Func _InitilizeDict()
; if NOT FileExists ($DictionaryLanguage) Then
; MsgBox (0,"","Dictionary Files do not exist")
; Exit
; EndIf
; _FileReadToArray($DictionaryLanguage, $Dictionary) ; Dictionarry for Autocomplete

_RegisterPrediction($Edit_hWnd,$Dictionary,2,0)
EndFunc




Func _BuildSentence(byRef $English_Filipino, $WordtoFindX)
_DisplayOutput()
EndFunc


Func _Findfullword(ByRef $English_Filipino, $WordtoFindX) ; find partial string non Case
_DisplayOutput()
EndFunc


Func _Findpartword(ByRef $English_Filipino,$WordtoFind)
_DisplayOutput()
EndFunc



Func _DisplayOutput ()
GUICtrlSetData($Edit1, $WordtoFind & @CRLF)
EndFunc

Func _StripString ($stringstrip)
;
; use StrinRegExp to strip , ' ; / ( including inside ) [ includng inside ]
;
$stringstrip=StringRegExpReplace($stringstrip," "," ") ; strips any double spaces to a single space
$stringstrip=StringRegExpReplace($stringstrip,"([{}\^$&._%#!@=<>:;,~`'\’\*\?\/\+\|\\\\]|\-)","") ; looks for \^$&._%#!@=<>:;,~`'’*?\ and removes them, but not ( [ ] )
$stringstrip=StringRegExpReplace($stringstrip,"\(.*\)","") ; removes all information between ( and )
$stringstrip=StringRegExpReplace($stringstrip,"\[.*\]","") ; removes all information between [ and ]

; msgbox(0,"",$stringstrip)
Return StringStripWS ( $stringstrip, 2 )
EndFunc

Exit
Edited by Noddle

Share this post


Link to post
Share on other sites

Again starting from 0, i feel tedious

Never mind

I have edited the sound part as you prefered in your previous script

Hope you could reorganise it

Check back the script i wrote


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

PhoenixXL,

Thanks for sharing the 'Basic Framework' ! Very nice !

I tested it in the following Control :

Global $iEdit = GUICtrlCreateEdit('', 10, 50, 280, 100,  $ES_WANTRETURN )

It works nicely for the first line. The second line needs one more space after 'a' before the Selection List shows up, the third one needs 3 spaces ...

So I did the following :

$_Offset += StringLen(_GUICtrlEdit_GetLine($___cEdit, $Index))        ; + 2   ; 2 for Carriage Return and Line Feed

Ok now ! But of course things are going wrong when Carriage return is used.

Is there any way to use the code in both circumstances : with or without Carriage Return and Line Feed ?

Share this post


Link to post
Share on other sites

@which1,

Subclassing would be required to receive the keyevents inside an Edit control

The second line needs one more space after 'a' before the Selection List shows up, the third one needs 3 spaces ...

The selection is showed though selection is not possible.

Thats the Basic Framework ;)

This is not the center of the topic, so its better not steal the OP's subject


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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
Sign in to follow this  
Followers 0