Identifying occurences of specified text in one substack and report to another substack
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Identifying occurences of specified text in one substack and report to another substack
I am working to transform a process where results were delivered to an external file to a format were results now instead shall come to another substack
Briefly: 2 substacks:
a) "Phenomenalog", accumulating daycards, with textfield, for users diary notes
b) "Parsings" with two fields :
i) "searching" & ii) "occurrences"
The handler "phenoparse" is placed in the script of stack "Phenomenalog".
It permits user to specify a search-term and shall then scan the texts of all daycards identifying lines where the specified word(s) /name/number appears and report them
as ocurrences on a new card in the "Parsings" stack.
I attach the script of the handler in the hope that someone can suggest how to repair it.
< on phenoparse
global phenodate,cue,start,hitcard
ask "Which word shall be searched?"
if it is empty then
exit phenoparse
else
put it into cue
end if
ask "How many lines before ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into avant
ask "How many lines after ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into apres
open stack "Parsings"
new card
open field "searchings"
put "Parsed for" && cue && phenodate after field "searchings"of stack "Parsings"
close stack "Parsings"
go first card of stack "Phenomenalog"
find string cue in field "TextField"
if the result is "not found" then
answer "Cannot find this word"
exit phenoparse
else
put short name of this card && the foundchunk into start
put short name of this card into hitcard
put "<p>" & start & hitcard &"</p>" into field “occurrences” of last card of stack "Parsings"
put "<p>" & short name of this card & "</p>" into field “occurrences” of last card of stack "Parsings"
-- put the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" after field “occurrences” of stack pParsings
end if
repeat
set cursor to busy
find string cue in field "TextField"
if short name of this card && the foundchunk is start then
exit repeat
end if
if short name of this card is not hitcard then
put short name of this card into hitcard
put "<p> ----------------------</p>" after field “occurrences” of stack “Parsings”
put "<p>" & short name of this card & "</p>" after field “occurrences” of stack “Parsings”
end if
put the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" after field “occurrences” of stack “Parsings”
end repeat
go last card
put return & phenodate && the time && "Parsed:" && cue after field "TextField"
show stack "Parsings"
end phenoparse />
Briefly: 2 substacks:
a) "Phenomenalog", accumulating daycards, with textfield, for users diary notes
b) "Parsings" with two fields :
i) "searching" & ii) "occurrences"
The handler "phenoparse" is placed in the script of stack "Phenomenalog".
It permits user to specify a search-term and shall then scan the texts of all daycards identifying lines where the specified word(s) /name/number appears and report them
as ocurrences on a new card in the "Parsings" stack.
I attach the script of the handler in the hope that someone can suggest how to repair it.
< on phenoparse
global phenodate,cue,start,hitcard
ask "Which word shall be searched?"
if it is empty then
exit phenoparse
else
put it into cue
end if
ask "How many lines before ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into avant
ask "How many lines after ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into apres
open stack "Parsings"
new card
open field "searchings"
put "Parsed for" && cue && phenodate after field "searchings"of stack "Parsings"
close stack "Parsings"
go first card of stack "Phenomenalog"
find string cue in field "TextField"
if the result is "not found" then
answer "Cannot find this word"
exit phenoparse
else
put short name of this card && the foundchunk into start
put short name of this card into hitcard
put "<p>" & start & hitcard &"</p>" into field “occurrences” of last card of stack "Parsings"
put "<p>" & short name of this card & "</p>" into field “occurrences” of last card of stack "Parsings"
-- put the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" after field “occurrences” of stack pParsings
end if
repeat
set cursor to busy
find string cue in field "TextField"
if short name of this card && the foundchunk is start then
exit repeat
end if
if short name of this card is not hitcard then
put short name of this card into hitcard
put "<p> ----------------------</p>" after field “occurrences” of stack “Parsings”
put "<p>" & short name of this card & "</p>" after field “occurrences” of stack “Parsings”
end if
put the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" after field “occurrences” of stack “Parsings”
end repeat
go last card
put return & phenodate && the time && "Parsed:" && cue after field "TextField"
show stack "Parsings"
end phenoparse />
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Identifying occurences of specified text in one substack and report to another substack
Hi again.
This is the same as your post in the "Experienced Developers" pane, no?
I wrote there, though you never commented if I was anywhere near the problem:
This is the same as your post in the "Experienced Developers" pane, no?
I wrote there, though you never commented if I was anywhere near the problem:
Hi,
Please, please frame code offerings within the code tags (</>). It makes it much easier to see what is going on.
I glanced at your handler. Is this correct?See the line properly "tagged"? And does this make sense?Code: Select all
if short name of this card && the foundchunk is start then
Craig
Re: Identifying occurences of specified text in one substack and report to another substack
I tried to give a more precise title to the topic and a clearer description of the setup. Also the version of the script was slightly modified. I am too ignorant to find help in Your question about a single line in the handler .
I hope you or other visitors could suggest ways to elaborate the script to avoid error(s?)
I hope you or other visitors could suggest ways to elaborate the script to avoid error(s?)
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Identifying occurences of specified text in one substack and report to another substack
Kresten,
The line I mentioned is about 75% down the handler. I only glanced at your code, and wanted to make sure this line, which seems just a little odd, was what you meant.
Was an error thrown, or did the handler just not work?
In any case, in the future, do place code in code brackets.
Craig
The line I mentioned is about 75% down the handler. I only glanced at your code, and wanted to make sure this line, which seems just a little odd, was what you meant.
Was an error thrown, or did the handler just not work?
In any case, in the future, do place code in code brackets.
Craig
Re: Identifying occurences of specified text in one substack and report to another substack
Hi again kresten
In case you aren't sure what Craig means by putting your above code into a code block, look at the top of your post with the code in it for this pencil (right hand side) After you click on that, highlight all your code in the post, and click on the button that looks like [</>] - ...and you'll wind up with something like this once you click on "submit"
It will make your posts with long runs of code in them easier for everyone else to read.
As far as the code you posted goes, I'm not sure why you have this arrow in the first line -
In case you aren't sure what Craig means by putting your above code into a code block, look at the top of your post with the code in it for this pencil (right hand side) After you click on that, highlight all your code in the post, and click on the button that looks like [</>] - ...and you'll wind up with something like this once you click on "submit"
Code: Select all
< on phenoparse
global phenodate,cue,start,hitcard
ask "Which word shall be searched?"
if it is empty then
exit phenoparse
else
put it into cue
end if
ask "How many lines before ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into avant
ask "How many lines after ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into apres
open stack "Parsings"
new card
open field "searchings"
put "Parsed for" && cue && phenodate after field "searchings"of stack "Parsings"
close stack "Parsings"
go first card of stack "Phenomenalog"
find string cue in field "TextField"
if the result is "not found" then
answer "Cannot find this word"
exit phenoparse
else
put short name of this card && the foundchunk into start
put short name of this card into hitcard
put "<p>" & start & hitcard &"</p>" into field “occurrences” of last card of stack "Parsings"
put "<p>" & short name of this card & "</p>" into field “occurrences” of last card of stack "Parsings"
-- put the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" after field “occurrences” of stack pParsings
end if
repeat
set cursor to busy
find string cue in field "TextField"
if short name of this card && the foundchunk is start then
exit repeat
end if
if short name of this card is not hitcard then
put short name of this card into hitcard
put "<p> ----------------------</p>" after field “occurrences” of stack “Parsings”
put "<p>" & short name of this card & "</p>" after field “occurrences” of stack “Parsings”
end if
put the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" after field “occurrences” of stack “Parsings”
end repeat
go last card
put return & phenodate && the time && "Parsed:" && cue after field "TextField"
show stack "Parsings"
end phenoparse />
It will make your posts with long runs of code in them easier for everyone else to read.
As far as the code you posted goes, I'm not sure why you have this arrow in the first line -
or this in the last line< on phenoparse
Since they are outside the actual handler, though, I'm not sure they affect it either, just was puzzling to look at.end phenoparse />
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Identifying occurences of specified text in one substack and report to another substack
Bogs.
My code block icon looks like this: </>
Is this a Mac thing?
Craig
My code block icon looks like this: </>
Is this a Mac thing?
Craig
Re: Identifying occurences of specified text in one substack and report to another substack
Hi Dunbarx and bogs
I have been away for some days, now trying to understand your advices.
the line "if short name of this card && the foundchunk is start then" was meant to put an end to the scanning when the first occurrence is re-met
I have been away for some days, now trying to understand your advices.
the line "if short name of this card && the foundchunk is start then" was meant to put an end to the scanning when the first occurrence is re-met
Code: Select all
on phenoparse
global phenodate,cue,start,hitcard
ask "Which word shall be searched?"
if it is empty then
exit phenoparse
else
put it into cue
end if
ask "How many lines before ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into avant
ask "How many lines after ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into apres
open stack "Parsings"
new card
open field "searchings"
put "Parsed for" && cue && phenodate after field "searchings"
lock screen
set lockmessages to true
go first card of stack "Phenomenalog"
find string cue in field "TextField"
if the result is "not found" then
answer "Cannot find this word"
exit phenoparse
else
put short name of this card && the foundchunk into start
put short name of this card into hitcard
close stack "Parsings"
put "<p>" & start & hitcard "</p>" after field “occasions” of stack “Parsings”
put "<p>" & short name of this card & "</p>" after field “occasions”of stack Parsings
end if
repeat
set cursor to busy
find string cue in field "TextField"
if short name of this card && the foundchunk is start then
exit repeat
end if
if short name of this card is not hitcard then
put short name of this card into hitcard
put "<p> ----------------------</p>" after field “occasions” of stack “Parsings”
put "<p>" & short name of this card & "</p>" after field “occasions” of stack “Parsings”
end if
end repeat
go last card
put return & phenodate && the time && "Parsed:" && cue after field "TextField"
show stack "Parsings"
end phenoparse
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Identifying occurences of specified text in one substack and report to another substack
Hi.
It would concatenate two strings. So if the short name of the card is "myData", and the foundChunk is
"char 37 to 43 of field 10" then you would be saying:
Do you see? This string looks odd to me, though no error would be thrown.
Using the foundChunk is itself an issue; it is fragile. You must always save it the instant you have it, because it will be discarded by LC if you do almost anything else subsequently. That is for later, though.
But is that what you had in mind? I bet not.
Craig
It is just an odd construction, and I wanted to make sure it was what you intended. The line of code is in and of itself sound."if short name of this card && the foundchunk is start then
It would concatenate two strings. So if the short name of the card is "myData", and the foundChunk is
"char 37 to 43 of field 10" then you would be saying:
Code: Select all
if "myData char 37 to 43 of field 10" = start then...
Using the foundChunk is itself an issue; it is fragile. You must always save it the instant you have it, because it will be discarded by LC if you do almost anything else subsequently. That is for later, though.
But is that what you had in mind? I bet not.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Identifying occurences of specified text in one substack and report to another substack
Please note that "start" is a reserved word.
Using it as variable name may create problems in some situations.
Using it as variable name may create problems in some situations.
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Identifying occurences of specified text in one substack and report to another substack
Hermann is correct.
You can use a reserved word like "start":
But just don't. And you do not want to have to look up each word when you are writing your code to make sure it is not reserved, so get into the habit of using variable names like "tStart" or "inTheBeginning".
But we still have issues with your code, no?
Craig
You can use a reserved word like "start":
Code: Select all
on mouseUp
put "XYZ" into start
if start = "XYZ" then answer char 2 of start
end mouseUp
But we still have issues with your code, no?
Craig
Re: Identifying occurences of specified text in one substack and report to another substack
Well, you just need to look at your script (hit TAB from time to time if neccessary)!
All reserved words are somehow colorized, aren't they?
All reserved words are somehow colorized, aren't they?
Re: Identifying occurences of specified text in one substack and report to another substack
While I absolutely agree with starting variables with anything that indicates their scope, you can certainly find out if a word is reserved or not far easier than looking it up manually.
Note the picture below - Words that are reserved such as commands, functions, keywords, etc will usually tip you they are reserved by either their color or/and font style (bold, italic, etc), so right off the bat you know it is reserved.
Messages are not colored or styled, but if you click on the 'Documentation' tab at the bottom of the editor, you will see if it is a message as soon as you finish typing.
But Craig is dead on with his suggestion, until you get to tExt for a variable
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Identifying occurences of specified text in one substack and report to another substack
Bogs.
I have NEVER ever written this before. I hope you are gratified and impressed. You wrote:
LOL
Craig
I have NEVER ever written this before. I hope you are gratified and impressed. You wrote:
OK, ready?until you get to tExt for a variable
LOL
Craig
Re: Identifying occurences of specified text in one substack and report to another substack
I am impressed, even though it isn't mine
I got it reading the archive mailing lists, either from Jacque, or someone else responding to her. It was funny enough to stick with me for the last year +