Skip to content

Instantly share code, notes, and snippets.

@piroyon
Last active December 19, 2015 00:09
Show Gist options
  • Save piroyon/5866403 to your computer and use it in GitHub Desktop.
Save piroyon/5866403 to your computer and use it in GitHub Desktop.
Write to your Triple Store URL(line 20). Change file name to a part of URI. Put it on +execCGI directory. ex: http://mbgd.genome.ad.jp/rdf/gene/eco:B0002 "gene" is this script file!
#!/usr/bin/perl
use URI::Escape;
use WWW::Curl::Easy;
use CGI;
$q = CGI->new();
$url = $q->url;
$curl = WWW::Curl::Easy->new();
print "Content-type: text/html \n\n";
if($ENV{PATH_INFO}) {
$pathInfo = $ENV{PATH_INFO};
$pathInfo =~ s/^\///;
$query = $pathInfo;
}
$url .= '/' . $query;
$triplestore = 'http://sparql.nibb.ac.jp/sparql?query=';
$spql = '
SELECT ?subject ?predicate ?object
WHERE {{
<' . $url . '> ?predicate ?object }
union {
?subject ?predicate <' . $url . '> }
}';
$curl->setopt(CURLOPT_HTTPHEADER,['accept:text/html']);
$curl->setopt(CURLOPT_URL, $triplestore.uri_escape($spql));
my $write_data = '';
open(FH, "+>", \$write_data);
$curl->setopt(CURLOPT_WRITEDATA,FH);
print '<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">';
print '<head></head>';
print '<body>';
my $retcode = $curl->perform;
seek(FH, 0, 0);
while(<FH>) {
if (/<td><\/td>/) {
my $res = "<td><font color=\"#c0c0c0\">$url</font></td>";
print $res;
} else {
print;
}
}
if ($retcode != 0) {
print "<h4>Sparql error</h4>";
}
print '</body>';
print '</html>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment