Re: Count word's occurences
Re: Count word's occurences
- Subject: Re: Count word's occurences
- From: Deivy Marck Petrescu <email@hidden>
- Date: Mon, 15 Sep 2014 15:55:16 -0400
On Sep 15, 2014, at 5:06 AM, Guido Tangorra <email@hidden> wrote:
> Hi Deivy,
> I tried your solution and it work. It's also very fast.
> But after a while it give this error:
> expected "," or "}" but found unknow token
>
> Guido.
>
>
> 2014-09-13 21:41 GMT+02:00 Deivy Petrescu <email@hidden>:
> Guido,
> I was intrigued by your question and was disappointed that there was no way to get the word count of a text being created on the fly.
> So I set up to try to find a way.
> I know you have something already working, I don’t have JSON helper and, so far, no use for it.
> Also, no TextWrangler (BBEdit).
> However, I think I came up with a way to write the new line and the numbers of times it shows up before on the fly.
> I can not comment on speed but I assume it would be much faster than the one you have since I don’t really have to count the number of occurrences of a word, however, I can not test, just speculate.
>
> I’ve used parts of Nigel’s version, I’d appreciate if you let me know it works for you.
> Thanks.
> Here is the script
>
>
> --
> Saluti,
> Guido Tangorra
Guido,
I believe you either have a double word or a word that can not be used as variable.
To fix this problem try this.
There are some explanation on the script, now it works with more complex words and key words
I dont know how long is the list that you create, but I believe it will take some time before it runs out of memory
<script>
set theDocName to "theDocName"
set lista to {}
set wordcount to {}
tell application "TextWrangler"
activate
set myDocument to make new text document with properties {name:theDocName}
set show line numbers of myDocument to false
end tell
on idle
global lista
global wordcount
tell application "JSON Helper" to set myFruit to fetch JSON from mySource
set lFruit to "|"& myFruit&"|" ---> added this line
if myFruit is in lista then
---from here change myFruit to lFruit
try
wordcount as string
on error e
set e to text (get offset of "{" in e) thru (get offset of "}" in e) of e
end try
set {wordcount, kount} to run script "set nue to " & e & "\n\t\tset nue's " & lFruit & " to nue's " & lFruit & " + 1\n\t\treturn {nue,nue's " & lFruit & " }"
else
set end of lista to lFruit
set {wordcount, kount} to {wordcount & (run script "{" & lFruit & ":1}"), 1}
end if
---from here on back to myFruit
tell application "TextWrangler"
tell text of front text window
make new line at end with data (myFruit & space & kount)
select insertion point -1
end tell
end tell
return 0.5
end idle
</script>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden