Jane Austen's peculiarity

Peter M. Brigham pmbrig at gmail.com
Sat Aug 8 23:26:23 CEST 2015


On Aug 8, 2015, at 4:51 PM, Richmond wrote:

> On 08/08/15 23:33, Peter M. Brigham wrote:
> 
> <snip>
>> Missing an "of" in the two lines above:
>>    put line textLine *of* $TEKST into line cookedLine of fld "COOKED" etc
>> Don't know if that's the problem.
> 
> <snip>
> 
>> Your script logic seems unnecessarily complex. Since it looks as if only the last occurrence is ending up in the output field, instead of using a counter to keep track of the next line in the field, you could just
>>    put cr & line textLine of $TEKST after fld "COOKED"
>> But once again, loading a line into a field repeatedly will be much slower than putting it into a variable in the repeat loop and then  putting the variable into the field just once when the repeat is done. Getting or putting something from or into a field is much slower than doing the same in a variable, so just do it once.
>> 
>> Also, I can see no reason to be loading your data into system variables, which is what "$WERBS" etc is defining. The only reason to put something into a variable beginning with "$" is if you want some other system process besides LC to be able to access the data.
>> 
>> -- Peter
>> 
>> 
> 
> Well, as per your suggestion I did this:
> 
> on mouseUp
>   put 1 into textLine
>   put fld "WERBS" into WERBS
>   put fld "TEKST" into TEKST
>   repeat until line textLine of TEKST contains "finalSolution666"
>      put textLine into fld "KOUNT"
>      put 1 into verbLine
>      repeat until line verbLine of WERBS is empty
>         put line textLine of TEKST into fld "LYNE"
>         put line verbLine of WERBS into WERB
>         put "were" && WERB into FRAZE
>         put FRAZE into fld "FRAZE"
>         if line textLine of TEKST contains FRAZE then
>            if fld "COOKED" is empty then
>               put line textLine of TEKST after fld "COOKED"
>                -- this is here so that line 1 of fld "COOKED" does not end up empty
>               else
>                  put cr & line textLine of TEKST after fld "COOKED"
>                  end if
>         end if
>         add 1 to verbLine
>      end repeat
>      add 1 to textLine
>   end repeat
> end mouseUp
> 
> but still get only the last value.

Well, your logic still makes my head hurt, too many counters. Here's what I'd do, using a variant of my original function since it appears that you want to list the lines the relevant phrases occur in, not just the isolated phrases.

function findWere pText
  -- returns a comma-delim list of all the line offsets matching "were *ed"
  --    or "were" && <a word in your preterite list>.
  put fld "WERBS" into pretList
  put wordOffsets("were", pText, true) into offList
  repeat for each item w in offList
     put word w+1 of pText into testWord
     if testWord ends with "ed" or testWord is among the words of pretList then
        put (the number of lines of word 1 to w of pText) & comma after outList
     end if
  end repeat
  return char 1 to -2 of outList
end if

then:

on mouseup
  put fld "TEKXT" into tText
  put findWere(tText) into linesList
  repeat for each item i in linesList
    put line i of tText & cr after relevantLines
  end repeat
  put char 1 to -2 of relevantLines into fld "COOKED"
end mouseup

Untested, but you get the idea.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig




More information about the use-livecode mailing list