actorid.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 List::Util qw(max);
use URI::Escape;
use Data::Dumper;
require "/vhome/lombardinetworks.net/htdocs/bin/helper.pl";
# generate several external search queries
sub info_links {
$querykey=$_[0];
$querykey=~s/"//g;
$safekey=uri_escape($querykey);
$nonblankkey=$querykey;
$nonblankkey=~s/ /_/g;
$safenonblankkey=uri_escape($nonblankkey);
return "Search info at <a href=\"http://en.wikipedia.org/w/index.php?search=$safekey\">Wikipedia</a>, ".
"<a href=\"http://dbpedia.org/page/$safenonblankkey\">dbpedia</a>, ".
"<a href=\"http://www.viaf.org/viaf/search?query=local.names+all+%22$safekey%22&sortKeys=holdingscount&recordSchema=BriefVIAF\">viaf.org</a>, ".
"<a href=\"https://opencorporates.com/companies?q=$safekey\">Open Corporates Companies</a>, ".
"<a href=\"https://opencorporates.com/officers?q=$safekey\">Open Corporates Officers</a>, ".
"<a href=\"https://www.google.com/search?q=$safekey\">Google</a>, ".
"images at <a href=\"https://commons.wikimedia.org/wiki/$safenonblankkey\">Wikimedia Commons images</a>, ".
"<a href=\"https://www.google.com/search?q=$safekey&tbm=isch\">Google images</a>\n";
}
# load data
&loadWorkIds();
&load_actorids();
&load_aliases();
&load_networks();
# Licence texts
$licence_snippet=&read_file("/vhome/lombardinetworks.net/htdocs/include/cc-by-sa-nc-4.0.html");
$licence_comment=&read_file("/vhome/lombardinetworks.net/htdocs/include/cc-by-sa-nc-4.0.xml");
# HTML stuff
$top_area=&read_inc_file("top-area");
$frame_before_title=&read_inc_file("frame-before-title");
$frame_before=&read_inc_file("frame-before");
$frame_after=&read_inc_file("frame-after");
# merge aliased entries
foreach $key ( keys %alias) {
$cast{$alias{$key}}.=" | ".$cast{$key};
delete $cast{$key};
}
# next possible id (they are not neccessarily continuously used...
$nextid = (max values %actorid) +1;
# where to store info about an actor
$actors="/vhome/lombardinetworks.net/htdocs/actor/";
# Generate index.html in respective directory
foreach $key ( keys %cast) {
# if it is a new actor, we take the next free id
if (!(exists $actorid{$key})) {
$actorid{$key}=$nextid;
print $nextid."\n";
# create dir with name actorid
mkdir($actors.$nextid);
$nextid++;
}
# get the id (old or new one)
$id=$actorid{$key};
# generate page
open(O,">",$actors.$id."/index.html");
# write info
print O $licence_comment.$frame_before_title.
"<title>Mark Lombardi Networks - $key</title>".
$frame_before.
"<h3>$key</h3><p>(preliminary unstable) Actor URI: ".
&uri_for_actor($id)."</p>\n".
"<h4>Appears in</h4><ul>";
# get appearances as array of titles
@network=split('\|',$cast{$key});
foreach $n (@network) {
# remove whitespace at beginning and end
$n =~ s/^\s+|\s+$//g;
}
# print as list
# iterate through all networks in which the actor appears, sorted by name
foreach $n (sort {&linktext_of_network($a) cmp &linktext_of_network($b)} @network) {
print O "<li>$n<br />As related to";
$snip=&read_file(&dir_of_network(&id_from_link_to_network($n))."/$id.inc");
print O "$snip</li>\n";
}
# links for search
print O "</ul><br /><h4>More Information on $key</h4>".&info_links($key);
# Info on aliases
$alias_info="";
# collect aliases
foreach $akey ( keys %alias) {
if ($alias{$akey} eq $key) {
$alias_info.="<li>".$akey."<br />".&info_links($akey)."</li>\n";
}
}
# Emit aliases if any
if (length($alias_info)!=0) {
print O "<p></p><h4>Also appears as:</h4><ul>$alias_info</ul>\n";
}
# close page and proceed
print O "</ul>".$frame_after;
#<br />".$licence_snippet."</div></body></html>\n";
close O;
$id++;
}
# store the actorids array
open(O,">","actorids");
print O Dumper(\%actorid);
close(O);