On 10/08/15 22:19, hh wrote:
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
_______________________________________________


I am achieving what I initially set out to achieve, and with far less code than yours, so have no intention
of changing anything.

I, also, am a lucky sort of chap insofar as I don't really mind that much if my stack takes 3 days to work its way through a corpus . . . I can go and do some teaching, read a book, cook some food, go for a bike ride, talk to my wife,
play with my cats, and so on.

That has ALWAYS been my approach to programming for one simple reason: working every holiday for very many years indeed on a farm
on an island I had to sort out broken bailers, tractors and so on.

Now "proper" spares had to come, on a ferry, at a vast transportation overhead, from the mainland of Scotland. We could not afford that, so we fossicked (lovely verb) for whatever would do the job in the 'graveyard' of broken tractors, cars, stuff we had picked up from the local dump, and so on. Every single time we got our accursed bailer to bail the straw and the hay, we got the cotter pins we needed to connect the tractor to the plough, harrow, muck-spreader or whatever; never very elegant, but they worked. In fact my younger son was on that farm just 8 days ago and was shown some of my repair work by the farmer's son (the farmer is long dead); still functional after 25 years.

I have, just, worked out a way to colourise the items I want, and while, churning through some socking great corpus that would take days, I only need it to colourise the sentences the previous routine has extracted, so that won't take that long.

You, if it really seems such a good idea (and is it?) are more than welcome to download my stack

https://www.dropbox.com/sh/ja47l87gg87sn0q/AAAIj99kEQVOb8ev3jz8C5ORa?dl=0 File: TA.zip

and mess around with the script to your heart's content.

AND, while we are talking about time-consuming exercises: having put 4 hours of work into the thing, that seems, already, a bit more than the thing deserves as I am not interested in winning the Tour de France, simply extracting some data from a million word corpus with absolutely no deadline at all unless I choose to impose one. The results MAY get rolled into a paper my wife and I are THINKING of writing for an
academic conference . . . .

Almost ALL the stacks I have thrown out into the public domain in the last 6 months have come back to me with comments about how my code is clunky, inefficient, and so forth; and I would not doubt for a minute that that is probably true.

HOWEVER, as far as I am concerned there is one enormous advantage about my code above thine, or anybody else's; while thy code and the code of many others is probably more efficient, more clever and gets things done more quickly, I don't understand the finer points of it, while I understand how my code works 100% because it was written by me, follows my logic, and does what I require it to do.

It is always entertaining and instructive to see how people react to my code, and I often learn a lot from their reactions (not least about human psychology), including new coding tricks - but there always come a point where the burden of having to plough through other people's code (reflecting the way their minds work) feels like too much in comparison from anything I might learn from it.

-----------------------------------

I also suspect that very many people share my interest in getting "the job done" rather than producing posh code.

RunRev claim, on their website, that one can learn to code quickly. With Livecode one can learn how to code RELATIVELY quickly, up to a certain point; and many people who are not programmers qua programmers should be attracted by that because they have probably
got other things to do other than JUST program.

I am, at least to a certain extent, one of those people, as computer programming is not the hinge on which my life rotates (and this became extremely clear just recently when I spent 3 weeks driving round Europe without access to any programming facilities at all), and that is why I may come across as a bit "rude and crude" to other programmers: mainly because I have evry little patience with reducing 25 lines
of code to 10 if it will take 12 hours to do that.

The cow has a breach-presentation calf inside it which will kill her and the calf within half an hour, to hell with calling the vet, I'm going to get my right arm up inside her and manipulate the calf so that it is facing head forwards: whether I do that the way posh younger sons of the aristocracy learn how to with their rubber gloves off at agricultural school
or not I just don't care: I am trying to save 2 lives, however I do it.

------------------------------------

I apologise if that comes across as a rant (well . . . it IS a rant), but it is something that I feel quite strongly about, and fell needs to be said
as a necessary corrective, from time to time.

-----------------------------------

One of the things I DO LOVE about LiveCode is that there is room for "Farmer Richmond" as well as all the "Real Coders", and I do think that that is something that Runtime Revolution would do well to tak more tent of in their advertising.

Richmond.

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to