It is currently Mon, 27 Jun 2022 12:00:49 GMT



 
Author Message
 String matching algorythm
I'm looking to avoid re-inventing the wheel and I need a good string
matching algorythm that takes into account positioning of each
character in the string. Ideally, I would pass in 2 strings and
get returned a percentage match value. Anybody have one of these
handy?  Thanks.

--
Mark S. Winsor
wm...@pvar.com



 Sat, 07 Feb 1998 03:00:00 GMT   
 String matching algorythm
jmaxw...@csugrad.cs.vt.edu (Jon A. Maxwell) wrote:

It may be that you have correctly interpreted 'what the guy wants'.
Had the original poster written something like 'the relative positioning of...",
I would have interpreted as you did. As posted, I envisioned a solution similar
to that proposed by the first follow-up. I guess it just goes to show ya'
there's no requirement like a precise requirement.

GV



 Sun, 08 Feb 1998 03:00:00 GMT   
 String matching algorythm
In article <41cq84$...@canton.charm.net>, wm...@pvar.com (Mark S. Winsor)says...

Let me attempt to write one below:

/* Uncompiled and thus Untested Code */
void vStringMatchRatio(char *pch1, char *pch2, int *piLenTested, int *piMatchCount)
{
for (*piLenTested = *piMatchCount = 0; ('\0' != *pch1) && ('\0' != *pch2); pch1++, pch2++,
*piLenTested++)
  *piMatchCount += (*pch1 == *pch2);

From your program call this one like this

#include "string.h"
CallerFunction()
{
int iT, iM;
char ach1[512], ach2[512];
...
...
...
strcpy(ach1, "The Funny Match Ratio, Why would one do this ?");
strcpy(ahc2, "the funny match ratio");

vStringMatchRatio(ah1, ach2, &iT, & iM);
And you should get iT = 21 and iM = 17.

Hope that helps. I wonder if this has any practical use at all!
--
MAG
/* ********************************************************
To understand recursion one must first understand recursion
******************************************************** */



 Sun, 08 Feb 1998 03:00:00 GMT   
 String matching algorythm
] In article <41cq84$...@canton.charm.net>, wm...@pvar.com (Mark S. Winsor)says...
] >I'm looking to avoid re-inventing the wheel and I need a good string
] >matching algorythm that takes into account positioning of each
] >character in the string. Ideally, I would pass in 2 strings and
] >get returned a percentage match value. Anybody have one of these
] >handy?  Thanks.

] void vStringMatchRatio(char *pch1, char *pch2, int *piLenTested, int *piMatchCount)
                   ^^^^^ (It doesn't return a ratio)
Are you a PASCAL->C guy?  You should return the ratio instead of void.

Only problem with your code is that it didn't do what the guy asked for:
"takes into account posisioning of each character in the string".  So from
your code the strings "fabcde" and "abcdef" would be 0% similar; what the
guy wants is something that can take those strings and return 79% similar or
something like that.

] Hope that helps. I wonder if this has any practical use at all!

I wonder if you have any imagination (at all)!  A simple real-world example
is the internet games chart.  You send in votes and give it the game's
assigned code so it knows which game you mean, but for new games that don't
have an assigned code yet, you just send the title.  Poor guy running it has
to go through these new game votes and manually figure out which codes they
are supposed to be.  It would be a great help for him if the computer
figured out the most likely answer and he just had to say 'Y' if it is
right.  Like this:

Sombody sends in "magic carpet", which is correct.  Other people send in
"magic carpit", "magic capret" and "magic karpet".  Such a string comparison
function could easily be used to match them to the correct one.

You can also use it in a shell, for 'cd'ing:  if a directory is close to the
name you typed in, it can go ahead and cd there or ask you if you really
meant such and such.  A great help for dyslexic people ;)

] /* ********************************************************
] To understand recursion one must first understand recursion
] ******************************************************** */

Cute.  Recursion Rocks.

--
     thur  Mail Address: LordArt...@vt.edu or jmaxw...@vt.edu
  n  r    
  a JAMax  "Satire is a sort of glass, wherein beholders do
  h o   w  generally discover everybody's face but their own."
  tan lle        --Jonathan Swift



 Sun, 08 Feb 1998 03:00:00 GMT   
 
   [ 4 post ] 

Similar Threads

1. netfilter string match

2. Matching strings with regular expressions

3. Unix - Matching data string from 2 files

4. Append string to each line if it matches a pattern

5. Search for best matched portion of a string

6. XPosting: Search for best matched string

7. rm Non-Matching string

8. Regular expression: matching one string and not the other

9. bourne shell string matching??

10. deleting text after string match


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software