Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
String Search Algorithms
Message
 
 
To
30/11/2001 09:10:37
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00587899
Message ID:
00588100
Views:
31
>>>>Hi All
>>>>
>>>>i was wondering, does anyone know where one could get a utility that compares two strings (a+b) and returns a percentage match
>>>>
>>>>Eg A = "JOE BLOGGS HOUSE"
>>>> B = "My Friend Joe Bloggs Lives In a huge House Down the Road"
>>>>
>>>>The utility would return a percentage figure of a match say 80% as it found "Joe Bloggs" and "House" in the sentence
>>>>
>>>>
>>>>Thanks
>>>>Mark
>>>
>>>Mark,
>>>
>>>Interesting... You would be looking for the percentage of matching words, right? I know that Nadya has a word parser as part of a larger process she has posted. I'll look in my libraries and see if I can find it. With that you could use something like AT to determine the matches in the strings. I might be slow though depending on the volume of what you're doing. There also may be an easier way...
>>>
>>>Renoir
>>
>>Renoir,
>>
>>I think you would usually want to use alines() for parsing.
>
>Nadya may do just that; haven't gotten to her code yet.
>
>R

Hi Renoir,

What exactly you're referring to? aparser routine? Well, we have two simple routines:
*!******************************************************************************
FUNCTION aparser
     *  Description.......: Function parses a text string into an array.  
     *                    : Each element of the array contains one word...
     *  Calling Samples...: dimension laWords[1]
     *                    : lcWordString = "Some text string"
     *                    : lnWords = aparser(@laWords, lcWordString)
     *  Parameter List....: paWords, pcWordString, pcDelimiter
     ********************************************************************
     lparameter paWords, pcWordString, pcDelimiter
     local lnWords, lni
     external array paWords

     if not "FOXTOOLS.FLL" $ set("library")
          set library to foxtools.fll additive
     endif

     pcDelimiter = iif(empty(pcDelimiter), space(1), pcDelimiter)

     lnWords = Words(pcWordString, pcDelimiter)

    IF lnWords>0 && Not empty string 
          dimension paWords[lnWords]

          for lni = 1 to lnWords
               paWords[lni] = WordNum(pcWordString, lni, pcDelimiter) && Array of words
          endfor
     ELSE
         dimension paWords[1] && For empty string lnWords=0
         paWords[1]=""
     ENDIF         
     return lnWords
*!******************************************************************************
function aparser1
*  Description.......: Function parses a text string into an array.
*                    : Each element of the array contains one word...
*  Calling Samples...: dimension laWords[1]
*                    : lcWordString = "Some text string"
*                    : lnWords = aparser1(@laWords, lcWordString)
*  Parameter List....: taWords, tcWordString, tcDelimiter
********************************************************************
lparameter taWords, tcWordString, tcDelimiter
local lnWords, lni
external array taWords
if vartype(m.tcWordString)"C"
   return .f. && First and second parameters are required
endif
if vartype(m.tcDelimiter)'C'
     tcDelimiter=space(1) && Default delimiter
endif
* Idea of Charlie Schreiner  #011905
*!* Now put each element in an array.
lnWords=alines(taWords, strtran(m.tcWordString, m.tcDelimiter, chr(13)))
return m.lnWords
Then you can use loop through first array (smaller string) and ascan in the bigger array. However, there could be more efficient ways of doing it, like WSH, for example. I would start from reading Ed Rauh & George Tasker articles in wfug, then check links in those articles...

I also designed user interface for our Search Criteria form. However, it's very complicated application with lots of classes and layers. This application returns where condition as a string along with JOIN conditions and FIELD_LIST...

Forgot to mention, that Cetin Basoz has List2Array.fll, which has the same functionality of parsing string into array, but it's written in C++.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform