resource() public method

Get the resource with given URI. $uri may be abbreviated to "namespace:value".
public resource ( $uri ) : Graphite_Resource
return Graphite_Resource
<?php

include_once "arc/ARC2.php";
include_once "Graphite.php";
$graph = new Graphite();
$uri = "http://data.ordnancesurvey.co.uk/id/postcodeunit/SO171BJ";
$graph->load($uri);
print $graph->resource($uri)->dump();
//print $graph->resource( $uri )->dumpText();
Example #2
0
<?php

include_once "arc/ARC2.php";
include_once "Graphite.php";
$graph = new Graphite();
$graph->ns("uosbuilding", "http://id.southampton.ac.uk/building/");
$graph->load("uosbuilding:32");
print $graph->resource("uosbuilding:32")->label();
Example #3
0
    $rdfuri = "";
    preg_match("/<link(?=[^>]*RDF\\/XML[^>]*>)([^<]*)>/", $objsrc, $matches);
    preg_match("/href=\"([^\"]*)\"/", $matches[1], $matches);
    $rdfuri = $matches[1];
    $uri = preg_replace("/rdf/", "id", $rdfuri);
    $rdf = file_get_contents($rdfuri);
    $g->addRDFXML("", $rdf);
} else {
    //	// unrecognised type - die
    //	die ("Unrecognised object");
    // Assume RDFXML 'till i work out how to do this properly >__<
    $g->addRDFXML("", $objsrc);
    $rdf = $objsrc;
}
// general stuff
$gres = $g->resource($uri);
$gres->loadSameAs();
$gnames = $gres->all("foaf:name");
$label = "";
foreach ($gnames as $gname) {
    $name = $gname->toString();
    if (preg_match("/^\\s*\$/", $name) == 0) {
        $label = $name;
        break;
    }
}
if ($label == "") {
    $label = "No name found";
}
//uri==uri
$gsameaslist = $gres->all("owl:sameAs");
Example #4
0
<?php

require_once "../arc/ARC2.php";
require_once "../Graphite.php";
$graph = new Graphite();
$graph->load("http://id.ecs.soton.ac.uk/person/1248");
$me = $graph->resource("http://id.ecs.soton.ac.uk/person/1248");
print "<h1>" . $me->prettyLink() . "</h1>";
print "<p>default, built-in icons.</p>";
print "<div>" . $me->get("foaf:mbox")->prettyLink() . "</div>";
print "<div>" . $me->get("foaf:phone")->prettyLink() . "</div>";
print "<h1>" . $me->prettyLink() . "</h1>";
print '<p>The following icons by <a href="http://p.yusukekamiyamane.com/">Yusuke Kamiyamane</a>. All rights reserved. Licensed under a <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 License</a>.</p>';
$graph->mailtoIcon("icons/mail.png");
$graph->telIcon("icons/telephone-handset.png");
print "<div>" . $me->get("foaf:mbox")->prettyLink() . "</div>";
print "<div>" . $me->get("foaf:phone")->prettyLink() . "</div>";
Example #5
0
<?php

include_once "Graphite.php";
include_once "arc/ARC2.php";
$rdf = $_REQUEST['rdf'];
$objuri = $_REQUEST['uri'];
$g = new Graphite(array('ecs' => 'http://rdf.ecs.soton.ac.uk/ontology/ecs#', 'eprel' => 'http://eprints.org/relation/', 'foaf' => 'http://xmlns.com/foaf/0.1/'));
if (is_array($rdf)) {
    foreach ($rdf as $r) {
        $g->addRDFXML("", $r);
    }
} else {
    $g->addRDFXML("", $rdf);
}
$gobj = $g->resource($objuri);
$gobj->loadSameAs();
$tags = array("foaf:img", "foaf:depiction", "eprel:haspreviewThumbnailVersion", "eprel:hasfullsizeThumbnailVersion");
$ret = "";
foreach ($tags as $tag) {
    $gpics = $gobj->all($tag);
    foreach ($gpics as $gpic) {
        if ($gpic->toString() == "[NULL]") {
            continue;
        }
        $atts = getimagesize($gpic->toString());
        if ($atts[0] < 100 || $atts[1] < 100) {
            continue;
        }
        $ret = $gpic->toString();
        break 2;
    }
Example #6
0
    $str = "";
    foreach ($reslist as $res) {
        $str .= renderResource($res, $intype);
        $count++;
    }
    if (preg_match("/^\\s*\$/", $str) == 0) {
        $html .= '<span class="header" id="' . $intype . '">' . $types[$intype]['srp'] . '</span>';
        echo '<li><a href="#' . $intype . '">' . $types[$intype]['srp'] . '</a></li>';
        $html .= $str;
    }
    unset($reslist);
}
echo '</ul>';
echo '<div class="header">';
$title = $g->primaryTopic()->label();
if (gettype($res = $g->resource($source)->get("foaf:primaryTopic")) == "string") {
    echo $res;
} else {
    echo $res->label();
}
echo '</div>';
echo '<div class="padding">';
echo $html;
echo ob_get_clean();
function renderResource($gRes, $type)
{
    // 		$node = new DOMNode('div');
    // 		$node->setAttribute('class', 'section');
    // 		$node->setAttribute('res', $gRes->toString());
    // 		$node->setAttribute('emph', 'major');
    $relations = array("dct:creator" => array('text' => "Has creator: ", 'type' => "person"), "-dct:creator" => array('text' => "Is creator of: ", 'type' => "paper"), "ecs:memberOf" => array('text' => "Is member of: ", 'type' => "project"), "-ecs:memberOf" => array('text' => "Has member: ", 'type' => "person"), "dct:hasPart" => array('text' => "Has part: ", 'type' => "none"), "rdfs:seeAlso" => array('text' => "Has link to: ", 'type' => "none"));
Example #7
0
<?php

include_once "arc/ARC2.php";
include_once "Graphite.php";
$graph = new Graphite();
$graph->load("http://id.southampton.ac.uk/");
print $graph->resource("http://id.southampton.ac.uk/")->get("foaf:name");
Example #8
0
 static function processSouthamptonURI($uri)
 {
     $graph = new Graphite();
     $graph->load('file:/home/opendatamap/isleofwight.rdf');
     $res = $graph->resource($uri);
     echo "<div id='content'>";
     $name = $res->getString('rdfs:label');
     $icon = $res->getString('http://purl.org/openorg/mapIcon');
     echo "<h2><img class='icon' src='" . ($icon != "" ? $icon : "img/blackness.png") . "' />" . $name;
     echo "</h2>";
     if ($res->has('foaf:phone')) {
         $phone = $res->getString('foaf:phone');
         if (substr($phone, 0, 8) == 'tel:+442') {
             echo '(0' . substr($phone, 7, 2) . ') ' . substr($phone, 9, 4) . ' ' . substr($phone, 13);
         } elseif (substr($phone, 0, 7) == 'tel:+44') {
             echo '(0' . substr($phone, 7, 4) . ') ' . substr($phone, 11, 3) . ' ' . substr($phone, 14);
         } else {
             echo substr($phone, 4);
         }
         //foreach($res->all('foaf:phone') as $phone)
         //	echo $phone.'<br/>';
     }
     $allpos = array();
     foreach ($res->all('-http://purl.org/goodrelations/v1#availableAtOrFrom') as $offering) {
         foreach ($offering->all('http://purl.org/goodrelations/v1#includes') as $include) {
             if ($include->isType('http://purl.org/goodrelations/v1#ProductOrServicesSomeInstancesPlaceholder')) {
                 $p['label'] = $include->getString('rdfs:label');
                 $allpos[] = $p;
             }
         }
     }
     if (count($allpos) == 0) {
         foreach ($res->all('-http://purl.org/goodrelations/v1#availableAtOrFrom') as $offering) {
             foreach ($offering->all('http://purl.org/goodrelations/v1#includes') as $include) {
                 if ($include->isType('http://purl.org/goodrelations/v1#ProductOrService')) {
                     $p['label'] = $include->getString('rdfs:label');
                     $allpos[] = $p;
                 }
             }
         }
     }
     /*
     $allpos = sparql_get(self::$endpoint, "
     PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
     PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
     PREFIX spacerel: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/>
     PREFIX org: <http://www.w3.org/ns/org#>
     PREFIX gr: <http://purl.org/goodrelations/v1#>
     
     SELECT DISTINCT ?label WHERE {
     	?o gr:availableAtOrFrom <$uri> .
     	?o gr:includes ?ps .
     	?ps a gr:ProductOrServicesSomeInstancesPlaceholder .
     	?ps rdfs:label ?label .
     } ORDER BY ?label 
     ");
     
     if(count($allpos) == 0)
     {
     	$allpos = sparql_get(self::$endpoint, "
     	PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
     	PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
     	PREFIX spacerel: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/>
     	PREFIX org: <http://www.w3.org/ns/org#>
     	PREFIX gr: <http://purl.org/goodrelations/v1#>
     
     	SELECT DISTINCT ?label WHERE {
     		?o gr:availableAtOrFrom <$uri> .
     		?o gr:includes ?ps .
     		?ps a gr:ProductOrService .
     		?ps rdfs:label ?label .
     	} ORDER BY ?label 
     	");
     }
     */
     self::processOffers($allpos);
     $allopen = array();
     foreach ($res->all('http://purl.org/goodrelations/v1#hasOpeningHoursSpecification') as $time) {
         if ($time->has('http://purl.org/goodrelations/v1#validFrom')) {
             $open['start'] = $time->getString('http://purl.org/goodrelations/v1#validFrom');
         } else {
             $open['start'] = null;
         }
         if ($time->has('http://purl.org/goodrelations/v1#validThrough')) {
             $open['end'] = $time->getString('http://purl.org/goodrelations/v1#validThrough');
         } else {
             $open['end'] = null;
         }
         $open['day'] = $time->getString('http://purl.org/goodrelations/v1#hasOpeningHoursDayOfWeek');
         $open['opens'] = $time->getString('http://purl.org/goodrelations/v1#opens');
         $open['closes'] = $time->getString('http://purl.org/goodrelations/v1#closes');
         $allopen[] = $open;
     }
     /*
     $allopen = sparql_get(self::$endpoint, "
     PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
     PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
     PREFIX spacerel: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/>
     PREFIX org: <http://www.w3.org/ns/org#>
     PREFIX gr: <http://purl.org/goodrelations/v1#>
     
     SELECT DISTINCT * WHERE {
     	<$uri> gr:hasOpeningHoursSpecification ?time .
     	OPTIONAL { ?time gr:validFrom ?start . }
     	OPTIONAL { ?time gr:validThrough ?end . }
     	?time gr:hasOpeningHoursDayOfWeek ?day .
     	?time gr:opens ?opens .
     	?time gr:closes ?closes .
     } ORDER BY ?start ?end ?day ?opens ?closes
     ");
     */
     self::processOpeningTimes($allopen);
     if (substr($uri, 0, strlen('http://id.sown.org.uk/')) == 'http://id.sown.org.uk/') {
         self::processSownURI($uri);
     }
     echo "</div>";
     return true;
 }
Example #9
0
<?php

require_once "../arc/ARC2.php";
require_once "../Graphite.php";
$graph = new Graphite();
$graph->ns("sr", "http://data.ordnancesurvey.co.uk/ontology/spatialrelations/");
$rd = $graph->resource("http://id.southampton.ac.uk/building/32")->prepareDescription();
$rd->addRoute('*');
$rd->addRoute('*/rdfs:label');
$rd->addRoute('*/rdf:type');
$rd->addRoute('-sr:within/rdf:type');
$rd->addRoute('-sr:within/rdfs:label');
$n = $rd->loadSPARQL("http://sparql.data.southampton.ac.uk/");
$rd->handleFormat("json");
Example #10
0
<?php

include_once "arc/ARC2.php";
include_once "Graphite.php";
$person_uri = "http://eprints.ecs.soton.ac.uk/id/person/ext-1248";
$graph = new Graphite();
# this must be a directory the webserver can write to.
//$graph->cacheDir( "/usr/local/apache/sites/ecs.soton.ac.uk/graphite/htdocs/cache" );
$graph->cacheDir("/tmp/");
$graph->load($person_uri);
$person = $graph->resource($person_uri);
print "<h3>" . $person->link() . "</h3>";
# Show sameAs properties
foreach ($person->all("owl:sameAs") as $sameas) {
    print "<div>sameAs: " . $sameas->link() . "</div>";
}
showPersonInfo("Before", $person);
# follow the sameAs links and load them into our graph
$person->loadSameAs();
showPersonInfo("After", $person);
function showPersonInfo($title, $person)
{
    print "<h4>{$title}</h4>";
    print "<div><b>name:</b> " . $person->all("foaf:name")->join(", ") . "</div>";
    print "<div><b>phone:</b> " . $person->all("foaf:phone")->prettyLink()->join(", ") . "</div>";
    print "<div><b>homepage:</b> " . $person->all("foaf:homepage")->link()->join(", ") . "</div>";
}
Example #11
0
if (is_null($_REQUEST['URI'])) {
    die("");
}
$uri = $_REQUEST['URI'];
$uri = preg_replace("/^(?!http:\\/\\/)/", "http://", $uri);
$objsrc = file_get_contents($uri);
$regex = '/"([^"]*\\.rdf)"/';
preg_match($regex, $objsrc, $regResults);
$objuri = preg_replace("/\\/(?=\\d+\\/)/", "/id/eprint/", $uri);
$objuri = preg_replace("/\\/(?!.)/", "", $objuri);
$rdf = file_get_contents($regResults[1]);
include_once "../Graphite.php";
include_once "../arc/ARC2.php";
$g = new Graphite();
$g->addRDFXML("", $rdf);
$label = $g->resource($objuri)->get("dct:title")->toString();
$gauths = $g->resource($objuri)->all("dct:creator");
$otherlinks = array();
foreach ($gauths as $gauth) {
    $otherlinks[] = array('uri' => $gauth->uri, 'type' => 'person', 'rel' => 'http://purl.org/dc/terms/creator', 'inv' => false, 'shim' => "shims/Person.php");
}
$gsameaslist = $g->resource($objuri)->all("owl:sameAs");
$sameas = array();
foreach ($gsameaslist as $gsameas) {
    $sameas[] = $gsameas->uri;
}
$sameas[] = $objuri;
$rdfarr = array();
$rdfarr[] = $rdf;
// code to get edshare data
// as GET : www.edshare.soton.ac.uk/cgi/repostats/view?output=Counter&datasetid=eprint_downloads&objectid=7332
<?php

include_once "arc/ARC2.php";
include_once "Graphite.php";
$graph = new Graphite();
$graph->ns("org", "http://www.w3.org/ns/org#");
$uri = "http://id.southampton.ac.uk/org/F2";
$graph->load($uri);
print $graph->resource($uri)->all("org:hasSubOrganization")->sort("rdfs:label")->getString("rdfs:label")->join(", ") . ".\n";