Word counter crashing LiveCode?

Paul Dupuis paul at researchware.com
Sat Aug 25 07:10:14 EDT 2018


If you are LC 7 or higher, use trueWord chunk type vs word. See trueWord
in the dictionary. Also suggest using an array as in:

-- tText contains the text

local tWordArray
repeat for each trueWord tWord in tText
  add 1 to tWordArray[tWord]
end repeat

-- the keys of tWordArray are you unique words in tText. The values of
this array are you counts of how many occurrences
-- to convert the array to a list

combine tWordArray using cr and comma -- tText is now a list of the
form: word,count<cr>






On 8/25/2018 6:25 AM, Keith Clarke via use-livecode wrote:
> Folks,
> I’m working on a simple utility to count the most popular words in a text file but my current code runs for a while & then causes LiveCode to crash.
>
> It runs fine when I merely extract a list of unique words that are not in a ‘NoiseWords’ list but when I attempt to add a word count as the second item on the line it crashes after.
>
>    repeat for each word tWord in tSource 
>       
>       # remove noisewords
>       if tWord is among the lines of tNoiseWords then
>          next repeat
>       else
>          
>          #Process words 
>          if tWord is among the lines of tWords then
>             put lineOffset( tWord, tWords ) into tLine
>             
>             if offset(comma, line tLine of tWords) > 0 then
>                add 1 to item 2 of line tLine of tWords
>             else 
>                put comma & 2 after line tLine of tWords
>             end if
>             
>             next repeat
>          else
>             put tWord & comma & "1" & cr after tWords
>          end if
>          
>       end if
>       
>    end repeat
>  
> I’m no developer so I may be using the wrong technique completely, so would welcome any steer.
>
> Thanks in advance.
> Keith
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode






More information about the use-livecode mailing list