Jump to content

Recommended Posts

Posted

hi,

i have a pseudo script ready and i need to complete it to make it a full program

it's supposed to be a word frequency counter. the idea is based on an online Word Frequency Counter

at  https://www.browserling.com/tools/word-frequency

 

#Region INCLUDE
#include <GuiConstantsEx.au3>
#EndRegion INCLUDE

#Region GUI
GUICreate("Word Frequency Count", 400, 420)
GUISetIcon(@SystemDir & "\mstsc.exe", 0)
#EndRegion GUI

#Region EDIT
GUICtrlCreateEdit(@CRLF & "", 10, 10, 370, 360)
GUICtrlSetTip(-1, '#Region EDIT')
#EndRegion EDIT

#Region BUTTON
GUICtrlCreateButton("Find frequency", 280, 375, 100, 30)
GUICtrlSetTip(-1, '#Region BUTTON')
#EndRegion BUTTON

#Region GUI MESSAGE LOOP
GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

GUIDelete()
#EndRegion GUI MESSAGE LOOP

 

 

 

 

Posted

This is far from perfect (mostly, you need to work on getting rid of excess spaces), but it may give you some ideas:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <string.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 625, 376)
$Edit1 = GUICtrlCreateEdit("", 8, 24, 409, 289, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "Geology is an Earth science concerned with the solid Earth, the rocks of which it is composed, and the processes by which they change over time. ")
$List1 = GUICtrlCreateList("", 440, 24, 161, 279)
$Button1 = GUICtrlCreateButton("Go", 480, 336, 75, 25, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Input Text", 8, 0, 52, 17)
$Label2 = GUICtrlCreateLabel("Word Frequency", 440, 0, 83, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $sTextRead = GUICtrlRead($Edit1)
            _Frequency($sTextRead)
    EndSwitch
WEnd

Func _Frequency($sTextRead)
    $aStringToArray = StringSplit($sTextRead, " ")
    $aUniqueWords = _ArrayUnique($aStringToArray, 0, 1)

    For $i = 1 To $aUniqueWords[0]
        $aNumResults = _ArrayFindAll($aStringToArray, $aUniqueWords[$i])
        $aUniqueWords[$i] &= " - " & UBound($aNumResults)
        GUICtrlSetData($List1, $aUniqueWords[$i])
    Next
EndFunc

 

Posted (edited)

An other flavour...

#Include <Array.au3>

$s = "Geology is an Earth science concerned with the solid Earth, the rocks of which it is composed, and the processes by which they change over time."

Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3)
_ArrayColInsert($w, 1)
For $i = 0 to UBound($w)-1
   StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0])
   $w[$i][1] = @extended
Next
_ArraySort($w, 1, 0, 0, 1)
_ArrayDisplay($w)

 

Edited by mikell
options...
Posted

@abberration
The regex is for fun and not a difficult one, the important thing inside is the use of \b (word boundary) so "the" is not matched in "they"
The @extended feature of StringReplace and SRER is pretty useful indeed to get a number of replacements/occurences
BTW depending on which characters "words" may contain, your solution can be better - or the regex needs modifications :) 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...