Subject. A code outline for the query option.

Input: a list of words to search for. Example: [‘blue’,’green’]. Plus, a maximum allowed distance, say 6.

As a side note: another proposal: distance should be minimally increased if two concepts appear apart from another in some considerable fashion.

The query algorithm will run like this:

a for loop on each term in the query list

begin with blue. blue is appended to the currentlocation list [0,’blue’,0]. The first number is always the distance from “home”. When it exceeds the maximum, the location should then backtrack. The second number indicates “where we left off.”
blue entry is found as matrix row #40 (starting at 0): [‘blue’,’whale’,4]
the curloc is updated [0,’blue’,41,4,’whale’,0]. Note that if the result is identical to the immediately previous word (a “pingback” in a sense), it will be discarded, while if it is identical to a word before the immediately previous word, or to a word in the results list, it will be noted but NOT searched (treated as though it were a dead-end). If this rule is not implemented, the search will take infinitely long due to a circular loop. While this happens in humans (causing headaches), it is not permissible in a computer.
now we search for whale (always search for end-2) on range 0 (always last) thru end of matrix. Suppose we turn up dolphin(2) @ 64.

curloc is now [0,’blue’,41,4,’whale’,65,6,’dolphin’,0]

Now the algorithm should determine that the maximum has been reached. This is one “escape” situation, the other being when a word has been exhausted (search returns -1).

Both escape situations yield the following results:

a. write the last word to the results file.

b. delete the last three entries in curloc.

Now we resume searching under whale, starting @65.

Alright, so this goes on for awhile, and we end up with this hypothetical “search result,” quotes omitted for convenience. Note that in the real thing, there *will* be alphabetical sorting, unlike what you see here.
[blue,whale,dolphin,mammal,ocean,animal,ocean,sea,fish,whale,sky,clouds,birds,sun,bleu,
French,cheese,France,blue-green,peacock,green-blue,turquoise,color,yellow,red,orange,violet,
purple,green,blah blah blah]

The task now is to find out which words appear most often. One way to do this is the make the results list into a results dictionary that keeps personal tally values associated with the word keys.

Leave a Reply