string similarity comparison

This is a discussion on string similarity comparison within the PHP Language forums, part of the PHP Programming Forums category; I'm looking for a method to compare two strings and grade them for similarity. My idea is to strip ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-23-2005
Bosconian
 
Posts: n/a
Default string similarity comparison

I'm looking for a method to compare two strings and grade them for
similarity.

My idea is to strip out common words and punctuation and create a checksum
of each remaining string. I would then compare the checksums and if they are
close then there's a potential match (to be judged by user interaction.)

Can someone suggest an existing function or class to perform such a task?

Thanks!


Reply With Quote
  #2 (permalink)  
Old 04-23-2005
Nicholas Sherlock
 
Posts: n/a
Default Re: string similarity comparison

Bosconian wrote:
> I'm looking for a method to compare two strings and grade them for
> similarity.


http://docs.php.net/en/function.levenshtein.html

or

http://docs.php.net/en/function.similar-text.html

Cheers,
Nhcholas Sherlock
Reply With Quote
  #3 (permalink)  
Old 04-23-2005
Bosconian
 
Posts: n/a
Default Re: string similarity comparison

"Nicholas Sherlock" <n_sherlock@hotmail.com> wrote in message
news:d4cpp0$1jc$1@lust.ihug.co.nz...
> Bosconian wrote:
> > I'm looking for a method to compare two strings and grade them for
> > similarity.

>
> http://docs.php.net/en/function.levenshtein.html
>
> or
>
> http://docs.php.net/en/function.similar-text.html
>
> Cheers,
> Nhcholas Sherlock


Nhcholas, I'm embarrassed to say that I didn't check php.net before posting
my message. Shame on me, but thanks for the tip!


Reply With Quote
  #4 (permalink)  
Old 04-23-2005
Bosconian
 
Posts: n/a
Default Re: string similarity comparison

BTW, would you happen to know if this can be done at the query level?

"Nicholas Sherlock" <n_sherlock@hotmail.com> wrote in message
news:d4cpp0$1jc$1@lust.ihug.co.nz...
> Bosconian wrote:
> > I'm looking for a method to compare two strings and grade them for
> > similarity.

>
> http://docs.php.net/en/function.levenshtein.html
>
> or
>
> http://docs.php.net/en/function.similar-text.html
>
> Cheers,
> Nhcholas Sherlock



Reply With Quote
  #5 (permalink)  
Old 04-23-2005
Bosconian
 
Posts: n/a
Default Re: string similarity comparison

"Nicholas Sherlock" <n_sherlock@hotmail.com> wrote in message
news:d4cpp0$1jc$1@lust.ihug.co.nz...
> Bosconian wrote:
> > I'm looking for a method to compare two strings and grade them for
> > similarity.

>
> http://docs.php.net/en/function.levenshtein.html
>
> or
>
> http://docs.php.net/en/function.similar-text.html
>
> Cheers,
> Nhcholas Sherlock


BTW, would you happen to know if this can be done at the query level?


Reply With Quote
  #6 (permalink)  
Old 04-24-2005
Nicholas Sherlock
 
Posts: n/a
Default Re: string similarity comparison

Bosconian wrote:
> "Nicholas Sherlock" <n_sherlock@hotmail.com> wrote in message
> news:d4cpp0$1jc$1@lust.ihug.co.nz...
>
>>Bosconian wrote:
>>
>>>I'm looking for a method to compare two strings and grade them for
>>>similarity.

>>
>>http://docs.php.net/en/function.levenshtein.html
>>
>>or
>>
>>http://docs.php.net/en/function.similar-text.html

>
>
> BTW, would you happen to know if this can be done at the query level?


Ah, do you want to something like this made up query:

SELECT * FROM mytable WHERE text IS SORT OF SIMILAR TO $mysearch ?

If so, you can't do this with PHP functions. You may be able to find an
add-on for your database server which will add functionality like this,
but I don't think that it comes standard with any databases.

Cheers,
Nicholas Sherlock
Reply With Quote
  #7 (permalink)  
Old 04-24-2005
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: string similarity comparison

Nicholas Sherlock wrote:
> Bosconian wrote:

<snip>
> >>http://docs.php.net/en/function.similar-text.html

> > BTW, would you happen to know if this can be done at the query

level?
> Ah, do you want to something like this made up query:
>
> SELECT * FROM mytable WHERE text IS SORT OF SIMILAR TO $mysearch ?
>
> If so, you can't do this with PHP functions. You may be able to find

an
> add-on for your database server which will add functionality like

this,
> but I don't think that it comes standard with any databases.


Though MySQL supports user defined functions, in SQLite, it is easy
AFAIK (never tried); you can mix PHP user functions with query
<http://in2.php.net/sqlite>


--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Reply With Quote
  #8 (permalink)  
Old 04-24-2005
Ewoud Dronkert
 
Posts: n/a
Default Re: string similarity comparison

R. Rajesh Jeba Anbiah wrote:
> <http://in2.php.net/sqlite>


To avoid having everyone over for a party at _your_ local server, you
should trim your url: <http://php.net/sqlite> (it then jumps to a local
server appropriate for the visitor).


--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Reply With Quote
  #9 (permalink)  
Old 04-24-2005
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default [OT] Re: string similarity comparison

Ewoud Dronkert wrote:
> R. Rajesh Jeba Anbiah wrote:
> > <http://in2.php.net/sqlite>

>
> To avoid having everyone over for a party at _your_ local server, you


> should trim your url: <http://php.net/sqlite> (it then jumps to a

local
> server appropriate for the visitor).


Oh, yes.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Reply With Quote
  #10 (permalink)  
Old 04-25-2005
Chung Leong
 
Posts: n/a
Default Re: [OT] string similarity comparison

"Ewoud Dronkert" <firstname@lastname.net.invalid> wrote in message
news:426b606b$0$187$e4fe514c@dreader4.news.xs4all. nl...
> R. Rajesh Jeba Anbiah wrote:
> > <http://in2.php.net/sqlite>

>
> To avoid having everyone over for a party at _your_ local server, you
> should trim your url: <http://php.net/sqlite> (it then jumps to a local
> server appropriate for the visitor).
>
>
> --
> Firefox Web Browser - Rediscover the web - http://getffox.com/
> Thunderbird E-mail and Newsgroups - http://gettbird.com/


I usually use the server in Finland. Less traffic than the stateside
servers.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:15 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0