Jane Austen's peculiarity

hh hh at livecode.org
Mon Aug 10 15:19:14 EDT 2015


Hi all,

Richmond, you could give this a try in your fine prepared stack:

The following uses
= an array [one of the proposals above]
= trueWords [one of the proposals, needs LC 7]
= multichar-itemDelimiters [one of the proposals above, needs LC 7]

It outputs for each of your 6 opening words
"were ,was ,is ,are ,has ,have ".
the frequency counts of words 1 and lists the item numbers of these
occurences, for each of the 6 words as itemdelimiter (actually word & space).

For example in fld "COOKED were" (by script created) we get:

were by        3 122 375 413

what means there are 3 occurrences of "were by" and these
are at trueword 1 of items 122, 375 and 413 if "were " is
the itemdelimiter.
[Use of trueWord collects for example "by " and "by? " and "by, " and "by! "
in one categorie "by".]

*** This takes < 1 sec, in sum for all 6 opening words from above! ***
*** So this is TMHO a true demo of the power of some LC 7 features ***

A click on a line of one of the 6 output fields colourizes (yellow backColour)
exactly the occurrences in fld "TEKST" and cycles finding these by hitting the
enterKey.

What to do?
[1} Make a new button with the following script part 1.
[2] Add the last part of the script to your card script part 2.
Have fun, it takes 5 minutes to test all this with your stack ...

Hermann

## part 1 for button
on mouseUp
 put the millisecs into strt
 put "started : " & the long time into fld "STARTT"
 put empty into fld "STOPT"
 lock screen; lock messages --> speeds up
 set cursor to watch
 put 1 into KTEKST; put 1 into KCOOK
 put fld "WERBS" into WERBS; delete last line of WERBS
 put fld "TEKST" into TEKST
 delete char 1 to offset("PRIDE AND PREJUDICE",TEKST)-1 of TEKST
 --> watch the space after each item, no space before each item
 put "were ,was ,is ,are ,has ,have " into openings
 -- start be lazy
 if there is no fld "STOPT2" then
   clone fld "STOPT"
   set name of last fld to "STOPT2"
   set left of fld "STOPT2" to the left of fld "STOPT"
   set top of fld "STOPT2" to the 40+the top of fld "STOPT"
 end if
 repeat with j=1 to 6
   put ("COOKED" && word 1 of item j of openings) into F
   if there is no field F then
     clone fld "Cooked"
     set name of last fld to F
     set rect of fld F to (0,0,275,150)
     set topleft of fld F to \
           (item j of "95,95,380,380,670,670", item j of "590,740,590,740,590,740")
     set tabstops of fld F to 128
   end if
 end repeat
 -- end be lazy
 repeat for each item W in openings
   put ("COOKED" && word 1 of W) into F
   put empty into RM; put empty into RM1
   set itemdelimiter to W; put TEKST into TEKST2
   delete item 1 of TEKST2; put 1 into X
   repeat for each item I in TEKST2
     put W & trueword 1 of I into Y --> important is "trueword", compare to "word"
     add 1 to word 1 of RM[Y]
     add 1 to X; put space & X after RM[Y] 
   end repeat
   -- write these 'keys' at top
   repeat for each line L in WERBS
     put RM[W & L] into wL
     if wL is empty then put 0 into wL
     put cr & W & L & tab & wL after RM1
   end repeat
   combine RM by cr and tab
   put W & ": diff cases" & tab & (the number of lines of RM) & \
         cr & RM1 & cr&cr & RM into fld F
   set textstyle of line 1 of fld F to "bold"
   set textstyle of line 3 to 2+(the num of lines of WERBS) of fld F to "italic"
   set hilitedLines of fld F to 1
   set itemdelimiter to comma
 end repeat
 put "finished : " & the long time into fld "STOPT"
 put (the short name of me)&": "&(the millisecs - strt)&" ms" into fld "STOPT2"
 unlock screen; unlock messages
end mouseUp

## part 2 for card script
local toFind

on mouseUp
 if "cooked " is in the short name of the target then
   set cursor to watch; lock screen; lock messages
   put length(fld "TEKST") into L
   set textcolor of char 1 to L of fld "TEKST" to "0,0,0"
   set backColor of char 1 to L of fld "TEKST" to "255,255,255"
   put the value of the clickline into cL
   colorWords cL
   unlock screen; unlock messages
 end if
end mouseUp

on colorWords x
 set itemdel to tab
 put item 2 of x into wrds
 put 1 + word 1 of wrds into N
 set itemdel to ((trueword 1 of x) & space)
 repeat with j=2 to N
   set backcolor of trueword 1 of item (word j of wrds) of fld "TEKST" to "255,255,0"
 end repeat
 put "find whole" && quote & (trueword 1 to 2 of x) & quote && \
       "in fld" && quote & "TEKST" & quote into toFind
 select before trueword 1 of item (word N of wrds) of fld "TEKST" -- the last hit
 set itemdel to comma
 do toFind
end colorWords

on enterinField
 do toFind
end enterinField

-- end of scripts



More information about the use-livecode mailing list