ROT13

Here is where the magnanimous folks that create externals post them (.zip archives only please).

Re: ROT13

Postby drpitcairn » Mon Oct 21, 2013 3:01 pm

Oops! Just noticed that all the lines of output have the same remedy name starting the line. That is, just Abies canadensis, over and over.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby drpitcairn » Mon Oct 21, 2013 3:02 pm

Oops! Just noticed that all the output lines have the same remedy name starting each line. They are all Abies Canadensis, over and over.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby codegreen » Mon Oct 21, 2013 3:10 pm

With your data or the sample? The sample is just the same remedy over and over...
codegreen
 
Posts: 1543
Joined: Mon Jul 14, 2008 11:03 pm

Re: ROT13

Postby drpitcairn » Mon Oct 21, 2013 3:22 pm

I put in my full datafile. The return message says:
1 remedies consisting of 17811 lines searched, 500 results found. Elapsed time = 5 ticks.

I had searched the word "cough" which in my project brings up something like 474 lines because the first paragraph is not searched in the database but that could be readily corrected.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby codegreen » Mon Oct 21, 2013 3:28 pm

I had searched the word "cough" which in my project brings up something like 474 lines because the first paragraph is not searched in the database but that could be readily corrected.

Done.

findTerms.sp45 3.zip
(9.12 KiB) Downloaded 367 times
codegreen
 
Posts: 1543
Joined: Mon Jul 14, 2008 11:03 pm

Re: ROT13

Postby drpitcairn » Mon Oct 21, 2013 3:52 pm

Finding well but still using the same remedy name. Attaching a picture of the outcome:
output.gif
your player project
output.gif (62 KiB) Viewed 14035 times

Notice that the listing of lines all start with the same remedy name instead of the individual remedy names (will be easiest to see in the next picture of the same search in my present project):

project output.gif
my project search
project output.gif (44.56 KiB) Viewed 14035 times

Also in the output from your project it says there was only one remedy searched and actually there are 347. Maybe why they all have the same name?

Here in this code from the present project you can see what I am excluding from a search — the title of the remedy, the next paragraph that starts with "General Indications" (not all have this so it has to be identified), then the horizontal dividing line is excluded, lastly the footnotes that start with a parenthesis.

Code: Select all
-- TAKES EACH LINE OF THE REMEDY UNDER CONSIDERATION AND CHECKS IT FOR THE SEARCH WORDS.
  repeat for each line h of haystack
    put 0 into showThis
    put h into thisLineX
    if thisLineX = theTitle then next repeat
    if thisLineX starts with "GENERAL INDICATIONS" then next repeat
    if thisLineX contains "______" then next repeat
    if thisLineX starts with "(" then next repeat
    put thisLinex into thisLine
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby codegreen » Mon Oct 21, 2013 4:18 pm

Ah, the bullet delimiters I was expecting ('•') between remedies don't seem to be in your data, so the code thinks it's all one remedy.

Did I misunderstand?
codegreen
 
Posts: 1543
Joined: Mon Jul 14, 2008 11:03 pm

Re: ROT13

Postby drpitcairn » Mon Oct 21, 2013 5:06 pm

As I understand it the text document is in the userprop and when the project window opened it is loaded into a global.
Here is the script that does that:
Code: Select all
function loadAndGo
  global gRemData
  put rot13m(the remData of this proj) into gRemData
  put replace(gRemData,numtochar(10),cr) into gremdata -- replaces linefeeds with cr.
  put replace(gRemData, cr & cr & cr & cr, "•") into gremdata -- where remedy description ends and there is a blank line in between = 4 cr.
  set the linedel to "•"  -- this symbol isolates each remedy description as one (long) line.
  set the itemdel to cr  -- single cr not caught in previous replace, allows text formatting to remain intact.
  -- CR is in the original text doc and preserves formatting that is there.
  put empty into smallList
  repeat for each line lineOfData of gremdata  -- reads the first line of remedy description, the name of each remedy.
    put word 1 to 10 of item 1 of lineOfData & cr after smallList
  end repeat
  set the itemdel to tab  -- good idea to set this back to something standard instead of the odd symbol.
  set the linedel to cr  -- return to original formatting.
  put smallList into cd fld "bigList" of cd 2  -- puts the name of each remedy into the field listing.
  return the number of lines of gremdata & " lines loaded"  -- two && = space. Was a check mechanism, no function now.
end loadAndGo

I don't fully understand it but have assumed this loading occurs only once when the project opened. I see that each remedy and its description is isolated by this use of a bullet and then treated as one line. Then I have assumed that the lines (sublines?) of data are separated by a cr. Once this is done then the remedy name is harvested through a repeat loop by taking the first 10 words of the first item, first line and creating a list. Then the list of remedy names is put into a scrolling field for access by the user.
I have assumed this was done as an easy way to get the remedy names because it appears the data in the global is then returned to the usual formatting without use of bullets.
Does this make any sense to you?
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby codegreen » Mon Oct 21, 2013 5:47 pm

Okay then, try this one...

findTerms.sp45 4.zip
(10.21 KiB) Downloaded 336 times
codegreen
 
Posts: 1543
Joined: Mon Jul 14, 2008 11:03 pm

Re: ROT13

Postby drpitcairn » Mon Oct 21, 2013 6:28 pm

I am afraid is basically the same, the remedy name the first one, repeated. Still treating the database as one remedy as well.
last try.png
last results
last try.png (41.34 KiB) Viewed 14019 times
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby codegreen » Mon Oct 21, 2013 6:36 pm

Okay, here's a version that generates its own sample data with four returns between logical 'lines'. Let me know if it works for you too, and how the generated data differs (structurally) from yours...

findTerms.sp45 5.zip
(10.21 KiB) Downloaded 342 times
codegreen
 
Posts: 1543
Joined: Mon Jul 14, 2008 11:03 pm

Re: ROT13

Postby drpitcairn » Mon Oct 21, 2013 6:47 pm

I am sorry to say identical to the last one. I am sorry this is so frustrating.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby codegreen » Mon Oct 21, 2013 7:38 pm

Something funny's goin' on here.

Here is my latest, and what it looks like when I generate some dummy data then search it:

Screen shot 2013-10-21 at 11.46.35 PM.png
Screen shot 2013-10-21 at 11.46.35 PM.png (170.93 KiB) Viewed 14010 times

findTerms.sp45 6.zip
(10.28 KiB) Downloaded 378 times

Are you saying you see something different?
codegreen
 
Posts: 1543
Joined: Mon Jul 14, 2008 11:03 pm

Re: ROT13

Postby drpitcairn » Mon Oct 21, 2013 8:02 pm

I don't understand either. If I generate your data into the field I get the same results as you. If I put my text data into the field then I am back to the outcome of not having the proper remedy name for each entry. Here is the picture:
6 try.gif
Try no. 6
6 try.gif (51.56 KiB) Viewed 14010 times

All I can think of is that somehow my text file is different. I have been using the external source file for the text entry. Maybe the file in the userprop is somewhat different (though it looks the same to the eye), maybe different limiters?
Here is a bigger sample, showing the first 3 remedies. I am putting it in as code so can be easily selected.

Code: Select all
Abies Canadensis
COMMON NAME: HEMLOCK SPRUCE
GENERAL INDICATIONS: Mucous membranes are affected by Abies-c. and gastric symptoms are most marked, and a catarrhal condition of the stomach is produced. There are peculiar cravings and chilly sensations that are very characteristic, especially for women with uterine displacement, probably due to defective nutrition with debility. Respiration and heart action labored. Wants to lie down all the time; skin cold and clammy, hands cold; very faint. Right lung and liver feel small and hard. Gleet. [Br.]
_____________________________________
Cravings (1) for coarse foods, meats, pickles, radish, turnips, etc. [Br.]
The most characteristic symptoms seem to be craving for meat, pickles and other coarse food, a gnawing, hungry, faint feeling at the epigastrium [G.]
Great appetite; canine hunger far beyond one's capacity for digestion [Br.]
Burning in stomach.
Gnawing, faint, hungry feeling (2) at epigastrium [Br.]
Flatulent distension of stomach and abdomen, with severe palpitation; flatulence disturbs heart's action.
Prolapsus uterus and other displacements, tendency to; due to debility and general defective nutrition (Alet., Calc-p., Caul., Helon., Lac-d., Nat-m.) [F.]
Prostration, patients want to lie down all the time [Br.]
CHILLINESS very characteristic.
Feels as if the top of the head congested, with faintness [Al.]
DOSAGE: 1st to 3rd potency.
_____________________________________
(1) Craving refers to an abnormal desire, not a nutritional need but an unusual desire to take in these foods.
(2) A hungry feeling may be one that arises even though enough food has been taken in.

Abies Nigra
COMMON NAME: BLACK SPRUCE
GENERAL INDICATIONS: A powerful and long-acting remedy, in various forms of disease, whenever the characteristic stomach symptoms are present. Most of the symptoms are associated with the gastric disturbances. IN DYSPEPTIC TROUBLES OF THE AGED, with functional heart symptoms; also after tea or tobacco. CONSTIPATION. Pain in external meatus. [Br.]
_____________________________________
Total loss of appetite in the morning, but great craving for food at noon and night [G.]
SENSATION AS OF A PAINFUL LUMP, FEELING LIKE A HARD BOILED EGG (or some undigestible substance) LODGING AT CARDIA (1) (Puls., Chin. - is a little higher up) [F.]
DISTRESSING CONSTRICTION IN EPIGASTRIUM, just above the pit of the stomach, < when debilitated (everything seems as if knotted up)
Pain in stomach always comes on after eating [G.]
Dyspeptic (2) troubles of the aged, with functional heart symptoms; also after tea or tobacco [Br.]
Low spiritedness, hypochondriasis and constipation, incident to dyspepsia [F.]
Dyspnea, < lying down.
Cough followed by waterbrash [Br.]
Heart's action heavy and slow; tachycardia, bradycardia.
AGGRAVATION: After eating.
COMPARE: Bry; Chin, Kali-c., Nux-v., Puls., Sabin., Thuj.
DOSAGE: 1st to 30th potency.
_____________________________________
(1) Cardia is the anatomical term for the part of the stomach attached to the esophagus.
(2) Dyspepsia can be defined as painful, difficult, or disturbed digestion, which may be accompanied by symptoms such as nausea and vomiting, heartburn, bloating, and stomach discomfort.

Abrotanum
COMMON NAME: SOUTHERN WOOD
GENERAL INDICATIONS: A very useful remedy in MARASMUS, especially of lower extremities only, yet with good appetite. METASTASIS. Rheumatism following checked diarrhea. Ill effects of suppressed conditions especially in gouty subjects. Tuberculous peritonitis. EXUDATIVE PLEURISY and other exudative processes. After operation upon the chest for hydrothorax or empyema, a pressing sensation remains. Aggravation of hemorrhoids when rheumatism improves. Nosebleed and hydrocele in boys. Great weakness after influenza (Kali-p.) [Br.]
_____________________________________
Marasmus (1) of children, with marked emaciation, especially of legs (lod., Sanic., Tub.; with emaciation of neck - Nat-m., Sanic.)
It is found peculiarly adapted to children with marasmus, worms, etc., though adults require its use often [G.]
The skin is flabby and hangs loose in folds [A.]
The child is cross and depressed [G.]
RAVENOUS HUNGER; LOSING FLESH WHILE EATING WELL (lod., Nat-m., Sanic., Tub.) [A.]
Alternate diarrhea and rheumatism (metastatic (2) rheumatism) [N.]
Alternate constipation and diarrhea; lienteria (3) (Aloe., Nux-v., Podo., Sulph.) [A.]
Epistaxis, hydrocele or emaciation of little boys [G.]
Numb, weak, tremulous and paretic [B.]
MARASMUS OF LOWER EXTREMITIES ONLY (Am-m., Arg-n.) [A.]
Rheumatism of heart [K.]
Nightly backache [B.]
Child is ill-natured, irritable, cross and despondent; violent, inhuman, would like to do something cruel [A.]
BLOATED ABDOMEN [B.]
Face old, pale, wrinkled (Arg-n., Lyc., Op.) [A.]
Darting or twitching sensation in either or both ovaries [G.]
In marasmus, head weak, cannot hold it up (Aeth.)
Cutting pains in stomach, gnawing, burning [G.]
Painful contractions of the limbs from cramps or following colic [A.]
Vomits much offensive fluid [B.]
Rheumatism, for the excessive pain before the swelling commences; from suddenly checked diarrhea or other secretions; alternates with hemorrhoids, with dysentery [A.]
Great weakness and prostration after influenza [G.]
Gout, joints stiff, swollen, with pricking sensation; wrists and ankle joints painful and inflamed [A.]
Very lame and sore all over (Arn., Bapt., Pyrog., Rhus-t.) [A.]
Blood and moisture oozing from the navel of newborn children [G.]
Itching chilblains (4) (Agar.) [A.]
Distended veins on forehead [B.]
Great weakness and prostration and a kind of hectic fever (5) with children; unable to stand [A.]
AGGRAVATION: In cold air or from getting wet; from checked secretions; in fogs; during night.
AMELIORATION: From loose stool; from motion.
RELATIONSHIP: After Hepar in furuncle; after Acon. and Bry. in pleurisy, when a pressing sensation remains in the affected side, impeding respiration.
DOSAGE: 3rd to 30th or higher potencies.
_____________________________________
(1) Marasmus is chronic wasting of body tissues, especially in young children, commonly due to prolonged dietary deficiency of protein and calories.
(2) Metastatic did not refer to cancer, but that the condition would extend from one location to another.
(3) Lienteria is a variety of diarrhea in which food is excreted either partially or wholly undigested.
(4) Chilblains is a condition of erythema, itching, and burning, especially of the dorsa (3) of the fingers and toes, and of the heels, nose, and ears caused by vascular constriction on exposure to extreme cold (usually associated with high humidity); lesions can be single or multiple, and can become blistered and ulcerated.
(5) Hectic fever is recurring fever with sweating, chills, and flushing.

Other than the first line, the name of the remedy, the search excludes what is above the top horizontal line and excludes any footnotes below the bottom horizontal line.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby codegreen » Mon Oct 21, 2013 8:10 pm

Your database has only two returns between logical items, not four.

Try this one instead:

findTerms.sp45 7.zip
(10.34 KiB) Downloaded 379 times
codegreen
 
Posts: 1543
Joined: Mon Jul 14, 2008 11:03 pm

Re: ROT13

Postby drpitcairn » Tue Oct 22, 2013 7:53 am

Mark,
Works perfectly. A thing of beauty!

However, I am left with some confusion. This morning I did a little script that puts the text database, from the userprop into the card field which holds the results, to see how it compared with the external text file that I have been sending you. As you saw in my last post, the text from the external file, copied and pasted, looks pretty much like text in a book, with paragraphs and occasional empty lines between. However, when I put the userprop text file to where it can be viewed in the card field it looks different, with extra empty lines throughout (as you can see in the text copied here). I also marked in red the beginning of the next remedy and there does not appear to be an extra spacing there to delineate the beginning of a new remedy description. So how does the script know?

Abies Canadensis

COMMON NAME: HEMLOCK SPRUCE

GENERAL INDICATIONS: Mucous membranes are affected by Abies-c. and gastric symptoms are most marked, and a catarrhal condition of the stomach is produced. There are peculiar cravings and chilly sensations that are very characteristic, especially for women with uterine displacement, probably due to defective nutrition with debility. Respiration and heart action labored. Wants to lie down all the time; skin cold and clammy, hands cold; very faint. Right lung and liver feel small and hard. Gleet. [Br.]

_____________________________________

Cravings (1) for coarse foods, meats, pickles, radish, turnips, etc. [Br.]

The most characteristic symptoms seem to be craving for meat, pickles and other coarse food, a gnawing, hungry, faint feeling at the epigastrium [G.]

Great appetite; canine hunger far beyond one's capacity for digestion [Br.]

Burning in stomach.

Gnawing, faint, hungry feeling (2) at epigastrium [Br.]

Flatulent distension of stomach and abdomen, with severe palpitation; flatulence disturbs heart's action.

Prolapsus uterus and other displacements, tendency to; due to debility and general defective nutrition (Alet., Calc-p., Caul., Helon., Lac-d., Nat-m.) [F.]

Prostration, patients want to lie down all the time [Br.]

CHILLINESS very characteristic.

Feels as if the top of the head congested, with faintness [Al.]

DOSAGE: 1st to 3rd potency.

_____________________________________

(1) Craving refers to an abnormal desire, not a nutritional need but an unusual desire to take in these foods.

(2) A hungry feeling may be one that arises even though enough food has been taken in.•Abies Nigra

COMMON NAME: BLACK SPRUCE

GENERAL INDICATIONS: A powerful and long-acting remedy, in various forms of disease, whenever the characteristic stomach symptoms are present. Most of the symptoms are associated with the gastric disturbances. IN DYSPEPTIC TROUBLES OF THE AGED, with functional heart symptoms; also after tea or tobacco. CONSTIPATION. Pain in external meatus. [Br.]

_____________________________________

Total loss of appetite in the morning, but great craving for food at noon and night [G.]


So I am thinking that what you have written in these projects you have sent may not apply to the text in the project itself. I don't know why it is different and why there are these lines:
Code: Select all
put replace(gremData, cr & cr & cr & cr, "•") into gremData -- where remedy description ends and there is a blank line in between = 4 cr.
  set the linedel to "•"  -- this symbol isolates each remedy description as one (long) line.
  set the itemdel to cr  -- single cr not caught in previous replace, allows text formatting to remain intact.
  -- CR is in the original text doc and preserves formatting that is there.

The way the data is put into the userprop looks very straight forward to me. This script imports the data from the external file and puts it into the userprop. Here is the script:
Code: Select all
on reloadData
  -- THIS NEXT SEGMENT ESTABLISHES THE FILE PATH TO THE PROJECT LOCATION, WHERE THE TEXT FILE WILL ALSO BE FOUND
  set cursor to busy
  get projectpath(this proj)
  put "rl.txt" after it  -- puts in the text file name.
  put it into theRemedyFile
  open file theRemedyFile
  read from file theRemedyFile until eof
  put it into theData
  close file theRemedyFile
  if theData is empty then
    answer "I couldn't load the data. Check to make sure the rl.txt file exists"
    exit to supercard
  end if
  set the remData of this project to rot13m(theData)
  answer "Successfully Loaded: " & cr & theRemedyFile
  get loadAndGo()
end reloadData

But the function "get loadAndGo()" may be changing it as I am showing in the text file I put in above.
Here is the script again, that puts the text stored in the userprop into a global for use while the project is open.
Code: Select all
function loadAndGo
global gremData
put rot13m(the remData of this proj) into gRemData
put replace(gremData,numtochar(10),cr) into gremData -- replaces linefeeds with cr.
put replace(gremData, cr & cr & cr & cr, "•") into gremData -- where remedy description ends and there is a blank line in between = 4 cr.
set the linedel to "•"  -- this symbol isolates each remedy description as one (long) line.
set the itemdel to cr  -- single cr not caught in previous replace, allows text formatting to remain intact.
-- CR is in the original text doc and preserves formatting that is there.
put empty into smallList
repeat for each line lineOfData of gremData  -- reads the first line of remedy description, the name of each remedy.
put word 1 to 10 of item 1 of lineOfData & cr after smallList
end repeat
set the itemdel to tab  -- good idea to set this back to something standard instead of the odd symbol.
set the linedel to cr  -- return to original formatting.
put smallList into cd fld "bigList" of cd 2  -- puts the name of each remedy into the field listing.
return the number of lines of gremData & " lines loaded"  -- two && = space. Was a check mechanism, no function now.
end loadAndGo

Anyway, do you think this is a factor to consider here? Should I be changing the way the userprop text loads into the global?
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby drpitcairn » Tue Oct 22, 2013 9:08 am

I have been studying the loadAndGo script more. Seems to me that what you have written, assuming a layout like the text I copied to you, is the preferred organization and that I should change this loadAndGo script to have an output that looks like normal text, with each remedy separated by one blank line (2 cr). What you think? A little afraid to mess with it so far.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby drpitcairn » Tue Oct 22, 2013 11:11 am

OK, I may have found the factor. The external text file is one made by BBEdit. Going back to that app and checking the settings, I find that the line breaks are Unix rather than CR. I bet this is why the handling of the text file by the loadAndGo script is done that way. Make any sense?

linefeeds.png
linefeed in BBEdit
linefeeds.png (63.28 KiB) Viewed 13971 times
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby drpitcairn » Tue Oct 22, 2013 12:01 pm

Leaving the BBEdit file the way it is, but changing the loadAndGo script a little changes the global text output to look normal, without extra blank lines.

function loadAndGo
global gRemData
set cursor to busy
put rot13m(the remData of this proj) into gRemData

repeat 10 times
delete last line of gRemData
end repeat

-- put replace(gRemData,numtochar(10),cr) into gremdata -- replaces linefeeds with cr.
put replace(gRemData, cr & cr & cr & cr, "•") into gremdata -- where remedy description ends and there is a blank line in between = 4 cr.

set the linedel to "•" -- this symbol isolates each remedy description as one (long) line.
set the itemdel to cr -- single cr not caught in previous replace, allows text formatting to remain intact.
-- CR is in the original text doc and preserves formatting that is there.
put empty into smallList

repeat for each line lineOfData of gremdata -- reads the first line of remedy description, the name of each remedy.
put word 1 to 10 of item 1 of lineOfData & cr after smallList
end repeat

set the itemdel to tab -- good idea to set this back to something standard instead of the odd symbol.
set the linedel to cr -- return to original formatting.

put smallList into cd fld "bigList" of cd 2 -- puts the name of each remedy into the field listing.

set the textStyle of cd fld 6 to plain
put gRemData into cd fld 6

end loadAndGo
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby codegreen » Tue Oct 22, 2013 1:11 pm

As long as your code already generates a list of remedies with bullets in between, it doesn't matter (for this purpose) what the source format is.

The project contains an external which replaces the findTerms handler in that earlier script (though unlike the scripted version it accepts the quoted form of the search terms directly).

Here's another update which hones the code further.

findTerms.sp45 8.zip
(10.44 KiB) Downloaded 386 times

All that's left of the script (after the timing code is removed) is this:

Code: Select all
on searchNow
  global gremData, theResults
  put empty into searchTerms
  put empty into theResults
  lock screen
  select empty
  put empty into cd fld "searchresults"
  put empty into cd fld "remedynumber"
 
  get cd fld "Search"
  repeat while last char of it is space
    delete last char of it
  end repeat
 
  repeat for each word aTerm of it
    if aTerm starts with quote and not (aTerm ends with quote) then
      answer "Enclose your word with quotes at start and end of word."
      exit script
    else if aTerm starts with "[" and not (aTerm ends with "]") then
      answer "To search for authors put brackets around the name, like this - [A.]."
      exit script
    else put replace(aTerm, space, "") & space after searchTerms
  end repeat
 
  delete last char of searchTerms
  if searchTerms is empty then
    answer "Please enter terms to search for."
    exit script
  end if
 
  set the linedel to "•" 
  repeat for each line aRemedy of gremData
    get findTerms(searchTerms, aRemedy)
    if it is not empty then put it after theResults
  end repeat
 
  if theResults is empty then put "Sorry, no results found" into theResults
  put empty into cd fld "storage"
  put theResults into cd fld "searchResults"
  makeitnice
  unlock screen
end searchNow

which seems a lot less gruesome to me... ;-)

At this point a progress bar is probably superfluous, since it more than doubles how long the operation takes.

Please compare the output with your original and verify that they're the same (or if they're not, let me know what's different).

-Mark
codegreen
 
Posts: 1543
Joined: Mon Jul 14, 2008 11:03 pm

Re: ROT13

Postby drpitcairn » Tue Oct 22, 2013 1:37 pm

Mark,
It works fine. I have done several searches, with and without quotes, and it finds accurately compared to my project. Of course is super fast, actually shocking compared to what I had before.
Yes, the simpler script is MUCH less gruesome.
I am quite impressed.

I have been working on the text file import and then export to the global. Have simplified it a little and seems to work fine. Still has the bullets in it to separate remedies so should be OK.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby codegreen » Wed Oct 23, 2013 12:57 am

This build sucks the outer loop of the search into the external as well. Percentage-wise it's significantly faster, but we're already well past 'seemingly instantaneous'. It does simplify the script further though:

Code: Select all
on searchNow
  lock screen
  select empty
  put empty into cd fld "searchresults"
  put empty into cd fld "remedynumber"
 
  get word 1 to (the num of words of cd fld "Search") of cd fld "Search"
  if it is empty then inputError "Please enter one or more words to search for."
 
  put empty into searchTerms
  repeat for each word aTerm of it
    if aTerm starts with quote and not (aTerm ends with quote) then ¬
      inputError "Enclose your word with quotes at start and end of word."
    if aTerm starts with "[" and not (aTerm ends with "]") then ¬
      inputError "To search for an author put brackets around their name." ¬
      & cr & cr & "For example: [A.]."
    put replace(aTerm, space, "") & space after searchTerms
  end repeat
  delete last char of searchTerms
 
  global gRemData
  get findTerms(searchTerms, gRemData)
  if it is empty then get "Sorry, no results found"
 
  put it into cd fld "searchResults"
  makeitnice
  put empty into cd fld "storage" -- Doesn't this belong somewhere else?
  unlock screen
end searchNow

on inputError errMsg
  alert stop "Invalid Search Term" explain errMsg
  exit to supercard
end inputError

findTerms.sp45 9.zip
(10.69 KiB) Downloaded 381 times

HTH,
-Mark
codegreen
 
Posts: 1543
Joined: Mon Jul 14, 2008 11:03 pm

Re: ROT13

Postby drpitcairn » Wed Oct 23, 2013 9:01 am

Mark,
I compared FindTerms9 with the project at my end and so far the output is identical. The quote function is reliable.

I put the search script that you provided in this past post, into my project, had to tweak it a little as I have changed some names. It runs really fast but we are back to the output lines all having the same remedy name, that of the first remedy. See the picture.

same remedy.gif
project output with new script
same remedy.gif (56.75 KiB) Viewed 13948 times


Here is the script you provided with my alterations.
Code: Select all
on searchNow
  global theResults, tfieldName, searchTerms
  put the secs into startTime
  lock screen
  select empty
  put empty into cd fld "searchresults"
  put empty into cd fld "remedynumber"
 
  get word 1 to (the num of words of cd fld "Search") of cd fld "Search"
  if it is empty then inputError "Please enter one or more words to search for."
 
  put empty into searchTerms
  repeat for each word aTerm of it
    if aTerm starts with quote and not (aTerm ends with quote) then ¬
      inputError "Enclose your word with quotes at start and end of word."
    if aTerm starts with "[" and not (aTerm ends with "]") then ¬
      inputError "To search for an author put brackets around their name." ¬
      & cr & cr & "For example: [A.]."
    put replace(aTerm, space, "") & space after searchTerms
  end repeat
  delete last char of searchTerms
 
  global gRemData
 
  get findTerms(searchTerms, gRemData)
 
  if it is empty then get "Sorry, no results found"
  put it into cd fld "searchResults"
  set the scroll of cd fld "searchresults" to 0
  put the num of lines in cd fld "searchresults" into cd fld "remedynumber"
 
  formatFieldResults
 
  put empty into cd fld "storage" -- Doesn't this belong somewhere else?
  click at 1000,1000
  put the secs into stopTime
  put "The time was "&(stopTime-startTime)&" seconds."
end searchNow

on inputError errMsg
  alert stop "Invalid Search Term" explain errMsg
  exit to supercard
end inputError


Here is the FindTerms script:
Code: Select all
function findTerms searchTerms, remedyData
  enum upperCaseA = charToNum("A"), upperCaseZ = charToNum("Z")
 
  put empty into theResults
  put line 1 of remedyData into remedyName  -- LINE 1 IS THE NAME OF THE REMEDY.
 
  repeat for each line aLine of remedyData
    enum hitCount = 0
    if aLine = remedyName then next repeat
    if aLine starts with "GENERAL INDICATIONS" then next repeat
    if aLine contains "______" then next repeat
    if aLine starts with "(" then next repeat
   
    --    put stripChars(".,;:()!", aLine) into thisLine
    put stripChars(":()-", aLine) into thisLine
   
    repeat for each word theTerm of searchTerms
      get charToNum(theTerm)
      if it ≥ upperCaseA and it ≤ upperCaseZ then  -- RESTRICTS TO JUST UPPER CASE LETTERS? QUOTE PROCESSING?
        if char 1 of chunkOffset(lower(theTerm), lower(thisLine), 0, ¬
          cr & space, false, false, true) ≠ 0 then
          add 1 to hitCount
        end if
      else if space & theTerm is in space & thisLine then add 1 to hitCount  -- THE SPACE IDENTIFIES IT AS A WORD.
      else exit repeat
    end repeat
   
    if hitCount = the number of words of searchTerms  -- STOPS THE SEARCH WHEN ALL THE SEARCH WORDS HAVE BEEN FOUND.
    then put remedyName & ":" & tab & replace(aLine, ":", " -") & cr after theResults
  end repeat
 
  return theResults
end findTerms


So far I can't see why the remedy name the same in each line. Have gone over the scripts several times but don't see it.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: ROT13

Postby codegreen » Wed Oct 23, 2013 9:17 am

You still need something like this:

Code: Select all
  set the linedel to "•" 
  repeat for each line aRemedy of gremData
    get findTerms(searchTerms, aRemedy)
    if it is not empty then put it after theResults
  end repeat

because (unlike the latest XFcn used in that project) the script version of findTerms currently doesn't include the outermost 'for each remedy' search loop (but instead is called within it).
codegreen
 
Posts: 1543
Joined: Mon Jul 14, 2008 11:03 pm

Re: ROT13

Postby drpitcairn » Wed Oct 23, 2013 2:58 pm

Mark,
For some reason I had a lot of trouble getting the script to work but finally....
Here is how it ended up that functioned properly. I had to add in some other lines from the prior script as well. I will mark them in red.

on searchNow
global theResults, tfieldName, searchTerms
set cursor to watch
put "searchresults" into tfieldName
put the secs into startTime

put empty into cd fld "searchresults"
put empty into cd fld "remedynumber"
put empty into searchTerms

get word 1 to (the num of words of cd fld "Search") of cd fld "Search"
if it is empty then inputError "Please enter one or more words to search for."

repeat for each word aTerm of it
if aTerm starts with quote and not (aTerm ends with quote) then inputError "Enclose your word with quotes at start and end of word."
if aTerm starts with "[" and not (aTerm ends with "]") then inputError "To search for an author put brackets around their name." ¬
& cr & cr & "For example: [A.]."
put replace(aTerm, space, "") & space after searchTerms
end repeat
delete last char of searchTerms
--
global gRemData
set the linedel to "•"

-- CHECK EACH REMEDY DATA SEQUENTIALLY
put empty into theResults
repeat for each line aRemedy of gremData
put stripEmptyLines(aRemedy) into aRemedy
get findTerms(searchTerms, aRemedy) --THE FUNCTION FOR FINDING.
if it is not empty then put it after theResults
end repeat

if theResults is empty then
put "Sorry, no results found." into theResults
put "0" into cd fld "remedynumber"
end if

put replace(theResults,tab,space) into theResults
put theResults into cd fld "searchResults"
set the linedel to cr --SETS THE END OF LINE BACK TO CR.
set the itemdel to ":" -- SEPARATES ITEMS WITH THE COLON CHARACTER.

set the scroll of cd fld "searchresults" to 0
get the num of lines in cd fld "searchresults"
put it into cd fld "remedynumber"
put empty into cd fld "storage"
click at 1000,1000

put the secs into stopTime
put "The time was "&(stopTime-startTime)&" seconds."

formatFieldResults

end searchNow


However, the script is very fast on my computer. If I search for the word "red" which finds 302 lines, the time on my computer is 1 second. Of course on the player proj. you sent the time is 48 milliseconds. Shall we say a little faster?

Back to the project, the slow part is formatting the search results field now, which with this search for "red" takes an additional 6 seconds. The script for formatting is:

Code: Select all
on formatFieldResults
  global searchTerms, tfieldName
  put the secs into startTime
  set the textstyle of cd fld tfieldName to plain
  put cd fld tfieldName into textListing
  put the num of lines in textListing into totalLineNum
 
  put empty into searchLine
  put searchTerms into wordsToMark
  if last char of wordsToMark is space then delete last char of wordsToMark
  set itemdel to ":"
  local m
  repeat for each line lineToFormat of textListing
    add 1 to m
    set the textstyle of item 1 of line m of cd fld tfieldName to bold
    put lineToFormat into searchLine
    repeat with w = 1 to the number of words in searchLine
      if word w of searchLine starts with "(" then
        if chartonum(char 2 of word w of searchLine) < 58 then set textsize of word w of line m of cd fld tfieldName to 12
      end if
      repeat with x = 1 to the num of words in wordsToMark
        put word x of wordsToMark into wordToFind
        if word w of item 2 of searchLine starts with wordToFind then set the textcolor of word w of item 2 of line m of cd fld tfieldName to 34
      end repeat
    end repeat
  end repeat
  put the secs into stopTime
  put "The time was "&(stopTime-startTime)&" seconds."
end formatFieldResults


And I have worked with it over and over to make it faster.

I do have another question, as I realize there is some confusion in my head about what we are doing. When you send me a player project to try out, does that contain the script you post with it? That I am to try in my project? Or does it contain an external that you are developing? I realize that the "search now" script has become very fast without adding in any other externals to the project.
I ask partly because the player proj. you sent can search for quotes very nicely but my project cannot do that yet, at least with the script the way it is now.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

PreviousNext

Return to XCmds, XFcns, and XRtns

Who is online

Users browsing this forum: No registered users and 1 guest

cron