#!/usr/bin/perl use CGI; require "/gh/src/ghlib.pl"; $movie_rx = "Top/Arts/Movies/Titles/./.+"; $celeb_rx = "Top/Arts/Celebrities/./.+"; $opt = shift; if ( $opt eq "-compile" ) { compile(); } else { $query = new CGI; find_index( $opt or $query->param( "who" ) ); } sub compile { my $hash = load_from_rdf(); compute_distances( $hash, "Bacon,_Kevin" ); write_hash( $hash ); } sub find_index { my ( $who ) = @_; my $hash = load_hash(); page_head( "kbacon" ); print "
\n";
if ( $who eq "" ) {
srand( time() ^ ($$ + ($$ << 15)));
$who = (keys %{$hash->{celebs}})[rand(scalar( keys %{$hash->{celebs}}))];
}
if ( $hash->{celebs}->{$who} eq "" ) {
print "I don't know $who!\n";
page_tail();
return;
}
if ( $hash->{dist}->{$who} eq "" ) {
print "Not connected!\n";
page_tail();
return;
}
$showwho = $who;
$showwho =~ s/^(.*),_(.*)$/\2 \1/;
$showwho =~ s/_/ /g;
print "$showwho was in ";
while( $who ) {
( $who, $mov ) = split /:/, $hash->{back}->{$who};
$showwho = $who;
$showwho =~ s/^(.*),_(.*)$/\2 \1/;
$showwho =~ s/_/ /g;
$mov =~ s,^.*/(?=[^/]+$),,;
$mov =~ s/_/ /g;
last if ( $who eq "Bacon,_Kevin" );
print "\"$mov\"\n with $showwho who was in "
}
print "\"$mov\"\n with Kevin Bacon\n";
print "\n";
page_tail();
}
sub load_hash {
my $ret;
open TXT, "kbacon.db";
while(