Compare strings that doesn't match 100%

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
aka_eu
Forum Newbie
Posts: 9
Joined: Wed Sep 28, 2005 10:13 am

Compare strings that doesn't match 100%

Post by aka_eu »

Hy to all,

I want to implement a small application for me, for odds comparison but unfortunately I got a dead end.

I succeeded to import the games and odds from all the bookmakers that is interesting me, but now I have some problem finding the same game on 5 bookmakers.

The problem is that they don't have all the same name for a team.

For example : Fc Koln (from Germany) can be find as : Koln or Coblenza.

And now I don;t know how to handle is the best manner the problem.

Can someone suggest me how to think this problem ? I was thinking on some AI or maybe to have some mysql tables for to write all the possibilities for a team (this will be do only the first time)
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Regular expressions may be an answer or if you are searching a database look up full text searching for the relevent database.

Without being a bit more specific (e.g code example) it's hard to be any more precise.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Compare strings that doesn't match 100%

Post by Christopher »

aka_eu wrote:For example : Fc Koln (from Germany) can be find as : Koln or Coblenza.
You could use regular expressions and do something like:

Code: Select all

$bookmaker_name = 'Fc Koln';
$regex = '/(Koln|Coblenza)/';     // match 'Koln' or 'Coblenza'
if (preg_match($pattern, $bookmaker_name)) {
     // match found
} else {
     // no match
}
(#10850)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$bookmaker_name = 'Fc Koln';
$regex = '/(Koln|Coblenza)/';     // match 'Koln' or 'Coblenza'
if (preg_match($pattern, $bookmaker_name)) {
     // match found
} else {
     // no match
}
Adding to arborints suggestion, you could do a preg_replace() to add AKA's to the groups aliases

Code: Select all

$bookmaker_name = 'Fc Koln';
preg_replace('/(Koln|Coblenza)/', '$1 (a.k.a. '. $bookmaker_name.')', $source);
aka_eu
Forum Newbie
Posts: 9
Joined: Wed Sep 28, 2005 10:13 am

Post by aka_eu »

Yes of course that I understand that solution but the problem is that I don't have to know each time how the team will be wrote. For example maybe sometime a bookmaker instead of Fc Koln will write Fc Kon , so I was thing as something like AI algorithm that will understand himself when it will meat Fc Kon that is about Fc Koln
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

FULL TEXT comparison in the database? similar_text() on the PHP side?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Well you could make the system "teachable" if you had it print out the name when it could not find a match. Then you could enter the new match to be added to the possible names for that team. So the system would "learn" (in a simple way).
(#10850)
Post Reply