neighbors.pl


# This work is licensed under the Creative Commons
# Attribution-ShareAlike 3.0 Unported License. To view a copy of this
# license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send
# a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042,
# USA. 
# Reference: http://www.lombardinetworks.net
# (C) Robert Tolksdorf, http://www.robert-tolksdorf.de
use Graph::Directed;

require "/vhome/lombardinetworks.net/htdocs/bin/helper.pl";

&loadWorkIds();
&load_actorids;
&load_aliases();

sub extract_neighbors {
    # the argument is the id of the network
    $network=$_[0];
    # make directory (fails if it already exists, we do not care)
    mkdir(&dir_of_network($network));
    # read the network
    $g=&read_network_as_graph($network);
    # for all nodes
    foreach $v ($g->vertices) {
	my @name = ();
	my $type = {};
	# iterate through the neigbors, store the normalized names
	foreach $w ($g->neighbors($v)) {
	    # store the normalized name (for sorting later)
	    push @name, &normalized_name($g->get_vertex_attribute($w,"name"));
	    # try $v->$w edge
	    $edge_type=$g->get_edge_attribute($v,$w,"type");
	    # try $w->$v if necessary
	    if ($edge_type eq "") {
		$edge_type=$g->get_edge_attribute($w,$v,"type");
	    }
	    # strip the URL from type
	    $edge_type =~ /http:\/\/www.lombardinetworks.net\/lombardi.owl\#(.*)/;
	    $short_edge_type=$1;
	    # store the type of the edge, hashed by normalized name
	    $type{&normalized_name($g->get_vertex_attribute($w,"name"))}=$short_edge_type;
	}
	# sort names
	@name = sort @name;
	# make html ul for all neighbors
	$snip="<ul>\n";
	foreach $n (@name) {
	    $snip.="<li>".&link_to_actor($n).
		" (".$type{$n}.")</li>\n";
	}
	$snip.="</ul>\n";
	# Write this out for inclusion on actor pages
	&write_file(&dir_of_network($network).$actorid{&normalized_name($g->get_vertex_attribute($v,"name"))}.".inc",$snip);
    }
}

# process all networks
foreach $key (keys %idwork) {
    &extract_neighbors($key);
}