Jump to content

create a Word Frequency Counter


Recommended Posts

i have a script that counts the word frequency and displays it in an array table

 

i need it to write the results in a text file instead of an array table

 

here's the script

 

#Include <Array.au3>
#Include <Debug.au3>
#include <Constants.au3>
#include <AutoItConstants.au3>

Example()

Func Example()
$s = FileRead("2.txt")
ProgressOn ( "Word Frequency", "Counting", "Loading", Default, Default, 18 )
Local $w = StringRegExp($s, "(?s)(\b[[:alpha:]]{2,}\b)", 3)
_ArrayColInsert($w, 1)
For $i = 0 to UBound($w)-1
   ProgressSet (( $i/(UBound($w) - 1)) * 100, "processed", "word frequency" )
   StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0])
   $w[$i][1] = @extended
Next
ProgressSet(100, "Done", "Complete")
_ArraySort($w, 1, 0, 0, 1)
_DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)
; _DebugArrayDisplay($w, "Title", "|0:1")
; _DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)
$sMessage = ""
SplashTextOn("Counting words", $sMessage, -1, -1, -1, -1, $DLG_TEXTLEFT, "")
For $i = 1 To 0
    $sMessage = $sMessage & $i & @CRLF
Next
ProgressOff()
EndFunc   ;==>Example

 

Link to comment
Share on other sites

Link to comment
Share on other sites

1 hour ago, JLogan3o13 said:

So look at FileWrite/FileWriteLine/_FileWriteFromArray in the help file?

Sorry to bother, 

I'm not a programmer so it's very difficult to create to me. It requires a lot of edits.

 

Plz help 

Link to comment
Share on other sites

  • Moderators

@vinnyMS This forum is dedicated to people who want to learn/improve at AutoIt scripting; it is not a place where you put in an order and someone just barfs up the code for you. If we did that, you'd never understand when you ran into a problem, or attempted to update the code ;)

Take a look at the sections I suggested in the help file. Each has great examples that you can try out on your own. Once you have done so, if you're running into issues, post what you have tried and we will gladly steer you in the right direction.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

4 hours ago, vinnyMS said:

I'm not a programmer so it's very difficult to create to me. It requires a lot of edits.

Why not use a program to do the counting? I am sure there are many available.

But if you are doing this to learn programming then you should indeed follow JLogan's advice and start learning the language, you can use the help file and maybe some youtube videos :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

14 hours ago, vinnyMS said:

I have a script that counts the word frequency and displays it in an array table.

Where did you get that script from? (-:

Quote

I need it to write the results in a text file instead of an array table.

I'm not a programmer either, so how about this:

#Include <Array.au3>

$s = FileRead ("2.txt")
Local $w = StringRegExp ($s, "(?s)(\b[[:alpha:]]{2,}\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)
$z1 = _ArrayToString ($w, @TAB, -1, -1, @CRLF, -1, -1)
FileWrite ("2_output1.txt", $z1)

$z2 = StringSplit ($z1, @CRLF, 1)
$z3 = _ArrayUnique ($z2)
$z4 = _ArrayToString ($z3, @CRLF)
FileWrite ("2_output2.txt", $z4)

(which is basically your script, with some stuff removed and some stuff added.)

Edited by leuce
Link to comment
Share on other sites

I hate homework and interview coding, there isn't much of a difference between both, they want some arbitrary twisted thing done instead of something practical. If I was good at those I would be doing math or spell bee competitions :P

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

1 hour ago, JockoDundee said:

Not the first time VinnyMS has been hit with such an allegation :)

 

 

Not exactly homework

 

That script was to use to extract text from hundreds of files and create a text list based on file content. Then the text extracted was to be replaced with text in another language. Extracted as Chinese and replaced by English. This way I could translate all those files by replacing the text from Chinese to English 

This other script is to create lists of top frequency to again replace from numbers to words. I work a lot with text file editing. I have all sort of ideas about programs

Link to comment
Share on other sites

On 7/20/2021 at 10:11 PM, vinnyMS said:

I have a script that counts the word frequency and displays it in an array table.

I need it to write the results in a text file instead of an array table.

and

10 hours ago, vinnyMS said:

It's for reading EEG in plain text.

Screenshot_5.png.564b542d9ed727eb2404b1844abd3c15.png.9ccd14507967cfddd80c47400b961f3c.png

Okay... erm... err... no, I don't see how you get from post #1 to post #2.

Link to comment
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
 Share

  • Recently Browsing   0 members

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