nother newbie question this time re foundChunk
Mike Bonner
bonnmike at gmail.com
Wed Mar 23 05:51:49 EDT 2011
If you know the number of words in the field:
put the number of words in field "narrative" into tWords
and you know the location of the found word:
put the number of words in (char 1 to (word 4 of tfound)) in field
"narrative" into tFoundWord
-- didn't try it, check syntax
then you should be able to grab the number of words you want directly. Will
still need to make sure the word location isn't too close to the beginning
or end of the text, but if you wanted 5 words on either side of the found
word you could do:
put word (tFoundWord - 5) to (tFoundWord + 5) of field "narrative" &
the short ID of this card & cr &cr after tFoundList
There is probably a better way, but this should work. Again, untested but I
think other than lacking the checks for too close to the start or end to get
5 words on either side, it should be close to what you want.
Oh, and if there is a lot in your narrative field, it might not hurt to do
the word counting stuff against a variable instead for speed purposes:
put field "narrative" into tNarrative
do your find as normal, but change to:
put the number of words in tNarrative into tWords
as well as:
put the number of words in (char 1 to (word 4 of tfound)) in tNarrative
into tFoundWord
and:
put word (tFoundWord - 5) to (tFoundWord + 5) of tNarrative & the short ID
of this card & cr &cr after tFoundList
On Wed, Mar 23, 2011 at 12:25 AM, Timothy Miller <
gandalf at doctortimothymiller.com> wrote:
> Hi again.
>
> I'm working on an indexing script.
> The relevant portion of my script so far: (it works thanks to you guys)
>
> repeat until the shiftKey is down
> set cursor to busy
> put the number of this card into firstNum
> find tTempSearch in field "narrative"
> put the foundChunk into tFound
> put the result into tResult
> put the number of this card into secNum
> if word 2 of tFound > 30 then subtract 30 from word 2 of tFound
> add 30 to word 4 of tFound
> put value(tFound) && "Card ID" & the short ID of this card & cr & cr
> after tFoundList
> if tresult = "not found" then exit repeat
> if firstnum > secnum then exit repeat
> end repeat
>
> At the climax of the script, variable tFoundList gets put into a (cleverly
> clickable) field on the index card. I can see thirty characters before and
> after the word or string I searched for, so I can see the searched-for word
> in context. This will be a more useful index, for my purpose.
>
> The trouble is, I end up with fragmentary words in my index field. They
> look crappy and they're distracting.
>
> I'm trying to figure out a way to end up with a consecutive sequence of
> whole words in each line of the index field.
>
> I'm hoping there's a function that works with the "find" command to return
> something like "word 88 of field 1" As far as I can tell, nothing like that
> exists. If it did, I could put it into a variable, manipulate it until it
> looks like "word 78 to 98 of field 1" and then get its value.
>
> If that isn't possible, I guess I will have to get the foundChunk and mess
> with it, to count backward and forward until I encounter " " or cr
> characters. This will be slow, and it will take me forever to script, though
> I am capable of getting it right in the end, howsoever kludgily.
>
> I tried "the foundText" but as far as I can tell, it returns value(the
> foundChunk). Not what I need. I tried "find word" but the foundChunk still
> returns characters, not words.
>
> Am I missing anything?
>
> Thanks again,
>
> Tim (the perpetual newbie)
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
More information about the use-livecode
mailing list