Matching filenames with typos

  • Thread starter Peter v.d. Berger
  • Start date
P

Peter v.d. Berger

Hello,

I'm working on a script that can place results of soccergames from different
seasons in a row, to see the history of the game.
I've gattered a lot of scores from different websites on a FreeBSD
webserver. The scores are all placed in a directory with the season as name,
and the names of the team as the filename.
So for example results of the game 'AC Milan - Ajax' are in different files
for different seasons:

../0405/AC Milan - Ajax.txt
../0304/AC Milan - Ajax.txt
../0203/AC Milan - Ajax.txt
(team names seperated with '-')

My script creates an HTML-page with an overview of the results of al
seasons.
The problem is that I gathered the names of the teams for the results from
different websites, and some websites will use 'AC Milan', others just
'Milan'
Some websites use the name 'Ajax', others 'Ajax FC', others 'Ajax
Amsterdam'.
Since I gathered results of hundreds of teams, in tenthousands of results,
renaming all the files is not an option.
Is there a way to improve the matching of these files, with the knowledge
that:

- two or three character strings can be left out (like FC, Utd.)
- make a match when, for example, two out of three names in the filename
match
(like: the game 'name1 name2 - name3' matches both 'name1 - name 3', and
'name2 - name3')

I hope i could make my question clear, and someone can help me.

Thanks!
 
J

Jim Gibson

Peter v.d. Berger said:
Hello,

I'm working on a script that can place results of soccergames from different
seasons in a row, to see the history of the game.
I've gattered a lot of scores from different websites on a FreeBSD
webserver. The scores are all placed in a directory with the season as name,
and the names of the team as the filename.
So for example results of the game 'AC Milan - Ajax' are in different files
for different seasons:

./0405/AC Milan - Ajax.txt
./0304/AC Milan - Ajax.txt
./0203/AC Milan - Ajax.txt
(team names seperated with '-')

My script creates an HTML-page with an overview of the results of al
seasons.
The problem is that I gathered the names of the teams for the results from
different websites, and some websites will use 'AC Milan', others just
'Milan'
Some websites use the name 'Ajax', others 'Ajax FC', others 'Ajax
Amsterdam'.
Since I gathered results of hundreds of teams, in tenthousands of results,
renaming all the files is not an option.
Is there a way to improve the matching of these files, with the knowledge
that:

- two or three character strings can be left out (like FC, Utd.)
- make a match when, for example, two out of three names in the filename
match
(like: the game 'name1 name2 - name3' matches both 'name1 - name 3', and
'name2 - name3')

I hope i could make my question clear, and someone can help me.

Create an array of unique team names and use a regular expression to
test if each name occurs in the file name. Generate a new name that
contains the two team names and either use that name as a key or rename
the old file to the new name. Example (untested):

my $name = 'AC Milan - Ajax FC';
my @teams = qw( Ajax Milan );

my $newname = '';
for my $team ( @teams ) {
if( $name =~ /$team/i ) {
$newname .= $team;
}
}
print "New name is '$newname'\n";

should produce

New name is 'AjaxMilan'

FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top