Searching for a word when it's more than one word

Mark Waddingham mark at livecode.com
Sat Sep 1 07:05:07 EDT 2018


On 2018-09-01 12:50, Richmond Mathewson via use-livecode wrote:
> Yup: indeed: fairly coarse.
> 
> However, see my next posting re "Ruyton of the Eleven Towns"
> 
> that should make some folk feel that they need a set of sewing needles
> rather than "just" a silver teaspoon.

I think you'll find my 'silver teaspoon' approach (as you put it) deals 
with all those cases :D

Interestingly, as I said, the multi-word match problem can be reduced to 
your 'shovel' - with pre and post processing.

Let's say that the phrase list is:

   Ruyton of the Eleven Towns
   East Hartfordshire
   Colchester
   Chester

First create a mapping from phrase words to individual characters (the 
choice of character is arbitrary):

   Ruyton <-> A
   of <-> B
   the <-> C
   Eleven <-> D
   Towns <-> E
   East <-> F
   Hartfordshire <-> G
   Colchester <-> H
   Chester <-> I

Now iterate through the source text, generating an output source text 
consisting of words from the new alphabet, and a 'unknown' letter '*'. 
For example:

   The man from Ruyton of the Eleven Towns, who is of the order of 
shovels, travelled from Chester to Colchester via the towns in East 
Hartfordshire

Would become:

   C**ABCDE**BC*B***I*H**E*FG

The original phrase list is processed similarly to give:

   ABCDE
   FG
   H
   I

Searching the transformed source text using your algorithm with the list 
of transformed phrases would give the correct set of found phrases as 
required by the original problem.

Warmest Regards,

Mark.

-- 
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps




More information about the use-livecode mailing list