Text Field "Statistics" script
Brian Yennie
briany at qldlearning.com
Wed Jun 14 18:41:16 EDT 2006
Here are some rough ideas to get you started.
> 1. Total number of words in the text field
put the number of words in fld "myField" into numWords
>
> 2. Total number of Paragraphs in the text field
You would have to define what constitutes a paragraph, but, for example:
## <carriage return> means new paragraph
put 0 into paragraphCount
repeat for each char c in fld "myField"
if (c = cr) then add 1 to paragraphCount
end repeat
For more complicated definitions of "paragraph" you might use offset()
to search for certain character sequences.
>
> 3. Total number of Sentences in the text field
Similar to #2, except maybe with a list of sentence-ending punctuation:
put 0 into sentenceCount
repeat for each char c in fld "myField"
if (c is in "?!.") then add 1 to sentenceCount
end repeat
> 4. Total number of sentences per paragraph
Combination of #2 and #3 might work... something like:
## initialize
put 0 into paragraphCount
put 0 into sentenceCount
put empty into sentenceCounts
repeat for each char c in fld "myField"
## new paragraph: store the sentence count from the last one
if (c = cr) then
put sentenceCount into line paragraphCount of sentenceCounts
add 1 to paragraphCount
put 0 into sentenceCount
end if
if (c is in "?!.") then add 1 to sentenceCount
end repeat
answer sentenceCounts ## displays counts one per line for each paragraph
> 5. Average number of words in a sentence
Something like #3, except try tracking your current position. Each time
you finish a sentence, use a chunk expression like:
put the number of words in char (sentenceStart) to (sentenceEnd) into
numWords
> 6. Total number of passive verbs (this one would be probably
> involve a
> small database/flat file to search and compare through?)
Try "repeat for each word" and lookup the words...
>
> Ideas and help are greatly appreciated. Since I don’t know much about
> the coding
> language yet, the more specific the better. Thank you all!
Hope that gives you a head start. I think you'll find if you get a
little further along, you can come back and gets lots more help here!
- Brian
More information about the use-livecode
mailing list