Dynamic Records?? (or other alternatives)
Dynamic Records?? (or other alternatives)
- Subject: Dynamic Records?? (or other alternatives)
- From: Greg Back <email@hidden>
- Date: Tue, 27 Nov 2001 17:15:19 -0500
Hi all-
I have set out on my first really helpful applescript, not like the
pointless scripts i have been writing. Essentially, it will work on the text
on the clipboard and provide a word-count feature, counting the total number
of words and providing a separate count for each individual word (i.e. have
the output be "2 occurence(s) of 'Applescript', 1 occurence of 'Script'", or
the like). So far, I have the following script:
======================================================================
set theText to the clipboard
set finallist to {}
--store, set TIDS
set {oldtids, text item delimiters} to {text item delimiters, " "}
set wrdlist to the text items of theText
set wrdcount to count wrdlist
repeat with wrd in wrdlist
if wrd is not in finallist then
set end of finallist to wrd
else
--somehow signify that there are more than one of this word
end if
end repeat
set diffWrdCount to count finallist
--somehow set commonword to word with the highest count
--sort wrdlist according to which words have the highest occurences
set commonword to "the"
display dialog "There are " & diffWrdCount & " different words out of
[NO-BREAK]" & wrdcount & " words on the clipboard. The most common
[NO-BREAK]word is \"" & commonword & "\"."
--restore TIDS
set text item delimiters to oldtids
======================================================================
[formatted using ScriptToEmail - gentle relief for mailing list pains]
[
http://files.macscripter.net/ScriptBuilders/ScriptTools/ScriptToEmail.hqx]
======================================================================
My first general question is :
1) Is there already a utility out there that can do this? No use in
re-inventing the wheel. Even if there is, i still want to do this using
Applescript, if only for the exercise.
The main reason for my post is:
2) Can you create a record during the running of a script, such as
set wrdz to {"applescript":2 , "script":1}
adding a new entry for each new word the script encounters. Or are records
not the way to do this? Or do I need to go about the entire process a
different way. From what I can tell, you have to define everything in the
record before it is run. Am i wrong?
Other issues i have to deal with in writing this script:
3) A word at the end of a sentence, or right before a comma, will be treated
differently by the script. A possible workaround might be (in
pseudo-script):
set badchars to (every item of ".,!?()") as list --Others?
if any character of wrd is in badchars then
--somehow take it off
Is there any way to do this without stepping through each character using
TIDs?
4) I also need to figure out how to return the result to the user, but I
haven't decided how (new text file, on clipboard, series of dialogs, etc.).
This also depends on how the data is stored at the end of the script. I
figure i'll cross this bridge when i get to it, but i am bringing it up now.
Any suggestions?
Thanks for taking the time to read such a long post!!, and Thanks in Advance
Greg Back