2007-12-18 00:22:51 +00:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
use DBI;
|
|
|
|
|
|
|
|
$database = 'yolanda';
|
|
|
|
$dbhost = 'localhost';
|
|
|
|
$dbuser = 'root';
|
|
|
|
$dbpass = '';
|
|
|
|
|
|
|
|
$dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass);
|
|
|
|
|
|
|
|
$sth = $dbh->prepare("select subject from videos");
|
|
|
|
$sth->execute();
|
2008-04-04 09:16:55 +00:00
|
|
|
#cycle through all video subjects
|
2007-12-18 00:22:51 +00:00
|
|
|
while(($subject) = $sth->fetchrow_array())
|
|
|
|
{
|
2008-02-14 22:35:25 +00:00
|
|
|
@subject = split(' ', $subject);
|
2008-04-04 09:16:55 +00:00
|
|
|
#cycle through all tags of video
|
2008-02-14 22:35:25 +00:00
|
|
|
foreach my $val (@subject)
|
|
|
|
{
|
2008-04-04 09:16:55 +00:00
|
|
|
#strip whitespaces
|
2008-02-14 22:35:25 +00:00
|
|
|
$val =~ s/^\s*(.*?)\s*$/$1/;
|
2008-04-09 13:23:12 +00:00
|
|
|
if(length($val) >= 3)
|
2008-02-14 22:35:25 +00:00
|
|
|
{
|
2008-04-06 21:10:55 +00:00
|
|
|
%hash->{$val}++;
|
2008-02-14 22:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-18 00:22:51 +00:00
|
|
|
}
|
|
|
|
$sth->finish();
|
|
|
|
|
2008-04-04 09:16:55 +00:00
|
|
|
#sort by count
|
2007-12-18 00:22:51 +00:00
|
|
|
@sorted = sort {$hash{$b} cmp $hash{$a}} keys %hash;
|
|
|
|
|
|
|
|
$dbh->do("delete from tagcloud");
|
|
|
|
$sth = $dbh->prepare("insert into tagcloud (text, count) values (?, ?)");
|
2008-04-04 09:16:55 +00:00
|
|
|
#insert first 20 tags into tagcloud table
|
2007-12-18 00:22:51 +00:00
|
|
|
for($i=0;$i<20 and $i<=$#sorted;$i++)
|
|
|
|
{
|
2008-02-14 22:35:25 +00:00
|
|
|
$sth->execute( $sorted[$i], %hash->{$sorted[$i]} );
|
2007-12-18 00:22:51 +00:00
|
|
|
}
|