示例#1
0
 public function __construct()
 {
     $viewData = new stdClass();
     $viewData->title = 'Nagf - wmflabs';
     $viewData->status = null;
     $viewData->project = null;
     $viewData->hosts = null;
     $viewData->hostGraphsConfig = $this->getHostGraphsConfig();
     if (isset($_GET['project'])) {
         $project = $_GET['project'];
         $hosts = Graphite::getHostsForProject($project);
         if ($hosts) {
             $viewData->project = $project;
             $viewData->hosts = $hosts;
         } else {
             $viewData->title = 'Project not found - Nagf';
             $viewData->status = array(404, 'Project not found');
         }
     }
     // NB: Keywords must be compatible with Graphites "from" param (See NagfView::getProjectPage)
     $ranges = array('day', 'week', 'month', 'year');
     // Filter out invalid ranges and ensure we have at least one of them selected
     $cookieRange = isset($_COOKIE['nagf-range']) ? explode('!', $_COOKIE['nagf-range']) : array();
     $checked = array_intersect($ranges, $cookieRange) ?: array('day');
     $viewData->ranges = array();
     foreach ($ranges as $range) {
         $viewData->ranges[$range] = in_array($range, $checked);
     }
     $this->view = new NagfView($viewData);
 }
示例#2
0
 /**
  * @return string HTML
  */
 public function getProjectMenu()
 {
     $data = $this->data;
     $projects = Graphite::getProjects();
     return '<select name="project" required class="form-control nagf-select-project">' . '<option value="" disabled>Select project</option>' . implode('', array_map(function ($project) use($data) {
         return '<option' . ($project === $data->project ? ' selected' : '') . '>' . htmlspecialchars($project) . '</option>';
     }, $projects)) . '</select>';
 }
 public function getTree($node, $ontology)
 {
     $filename = getcwd() . "/cache/onto-" . urlencode($ontology->url) . ".json";
     if (is_readable($filename)) {
         return json_decode(file_get_contents($filename));
     }
     $count = new PrefixCounter($ontology->prefix);
     $graph = new Graphite();
     $xml = simplexml_load_file($ontology->url);
     foreach ($xml->getNamespaces(true) as $prefix => $uri) {
         $graph->ns($prefix, stripslashes($uri));
     }
     $graph->load($ontology->url);
     $classes = $graph->allOfType("owl:Class");
     $classes = $classes->append($graph->allOfType("rdfs:Class"));
     $toplevel = $classes->except($classes->all("-rdfs:subClassOf"));
     $json = array();
     foreach ($toplevel as $class) {
         $uri = $graph->shrinkUri($class);
         $children = Ontology::getChildren($graph, $class, $count);
         $count->step();
         $json[] = array("id" => $count->value(), "text" => $uri, "iconCls" => "class", "children" => $children, "leaf" => empty($children));
     }
     file_put_contents($filename, json_encode($json));
     return $json;
 }
示例#4
0
文件: Box.php 项目: molovo/graphite
 /**
  * Add a margin around the content.
  *
  * @param string $content The content, without margin
  *
  * @return array The content, with margin
  */
 private function addMargin(array $content = [])
 {
     // Add a blank line at the top and bottom of the content
     // for each line of padding
     $size = 0;
     while ($size++ < $this->styles['marginY']) {
         array_unshift($content, '');
         array_push($content, '');
     }
     // Add whitespace at either of end of each line
     // to create the horizontal padding
     $pad = $this->graphite->repeat(' ', $this->styles['marginX']);
     foreach ($content as $i => $line) {
         $content[$i] = $pad . $line . $pad;
     }
     return $content;
 }
示例#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;
    }
示例#6
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>";
示例#7
0
/**
 * Return a common graph, defined here and shared across dashboards
 */
function getCommonGraph($type, $params = array())
{
    $title = isset($params['title']) ? $params['title'] : $type;
    if (isset($params['title_prefix'])) {
        $title = $params['title_prefix'] . $title;
    }
    if (isset($params['title_suffix'])) {
        $title = $title . $params['title_suffix'];
    }
    $base = $params['server'];
    $site = isset($params['site']) ? $params['site'] : null;
    $width = isset($params['width ']) ? $params['width '] : 380;
    $height = isset($params['height']) ? $params['height'] : 220;
    // Server
    switch (strtolower($type)) {
        case "apache":
            return Graphite::inst()->setTitle($title)->addMetric('alias(secondYAxis(divideSeries(' . $base . '.memory.rss.apache,' . $base . '.apache.process-count)),"Memory per process")', '#0000ff')->addMetric('alias(' . $base . '.apache.workers.busy,"Busy Workers")', '#00cc00')->addMetric('alias(' . $base . '.apache.process-count,"All Workers")', '#cc00cc')->setSize($width, $height);
        case "mysql":
            return Graphite::inst()->setTitle($title)->addMetric('alias(derivative(' . $base . '.mysql.queries.select),"Read Queries / min")')->addMetric('alias(secondYAxis(derivative(sumSeries(' . $base . '.mysql.queries.update,' . $base . '.mysql.queries.delete,' . $base . '.mysql.queries.insert))),"Write Queries / min")')->setSize($width, $height);
        case "load average":
            return Graphite::inst()->setTitle($title)->addMetric('lineWidth(movingAverage(' . $base . '.loadavg.1min,10),3)', '#dddddd')->addMetric($base . '.loadavg.1min', '#00cc00')->hideLegend(true)->setSize($width, $height);
        case "cpu usage":
            return Graphite::inst()->setTitle($title)->addMetric('alias(divideSeries(derivative(' . $base . '.cpu.non-nice),derivative(' . $base . '.cpu.total)),"User")', '#0000cc')->addMetric('alias(divideSeries(derivative(' . $base . '.cpu.io-wait),derivative(' . $base . '.cpu.total)),"I/O wait")', '#770000')->addMetric('alias(divideSeries(derivative(sumSeries(' . $base . '.cpu.system,' . $base . '.cpu.stolen,' . $base . '.cpu.irg,' . $base . '.cpu.soft-irq)),derivative(' . $base . '.cpu.total)),"system")', '#cc00cc')->addMetric('alias(divideSeries(derivative(' . $base . '.cpu.nice),derivative(' . $base . '.cpu.total)),"Nice")', '#00cc00')->displayStacked(true)->setYMax(1)->setSize($width, $height);
        case "memory free":
            return Graphite::inst()->setTitle($title)->addMetric('alias(' . $base . '.memory.free,"Free")', '#00cc00')->addMetric('alias(' . $base . '.memory.buffer,"Buffer")', '#00cccc')->addMetric('alias(' . $base . '.memory.swap-cache,"Swap Cache")', '#000077')->displayStacked(true)->setSize($width, $height);
        case "physical memory used":
            $graph = Graphite::inst()->setTitle($title)->displayStacked(true)->setSize($width, $height);
            foreach (array('apache', 'nginx', 'varnish', 'mysql', 'postgres', 'solr', 'php', 'java', 'exim', 'console', 'ssh', 'other') as $rssMetric) {
                $graph->addMetric('alias(' . $base . '.memory.rss.' . $rssMetric . ',"' . $rssMetric . '")');
            }
            return $graph;
        case "swapping":
            return Graphite::inst()->setTitle($title)->addMetric('alias(derivative(' . $base . '.memory.swapped-in),"Swap In")', '#00cc00')->addMetric('alias(derivative(' . $base . '.memory.swapped-out),"Swap Out")', '#cc00cc')->setSize($width, $height);
        case "apc":
            return Graphite::inst()->setTitle($title)->addMetric('alias(' . $base . '.php.apc.cache-misses,"Cache misses (spikes OK)")')->addMetric('alias(secondYAxis(' . $base . '.php.apc.free-mem),"Free APC memory")')->setSize($width, $height);
            // Site-specific
        // Site-specific
        case "requests":
            return Graphite::inst()->setTitle($site)->addMetric('alias(' . $base . '.apache.' . $site . '.request.req_per_min,"Requests per min")', '#00cc00')->addMetric('alias(secondYAxis(' . $base . '.apache.' . $site . '.request.time_95),"Response time (95th percentile)")', '#cc0000')->addMetric('alias(secondYAxis(' . $base . '.apache.' . $site . '.request.time_avg),"Response time (avg)")', '#aa5500')->setSize($width, $height);
        case "% by http code":
            return Graphite::inst()->setTitle($site)->addMetric('alias(secondYAxis(drawAsInfinite(' . $base . '.apache.' . $site . '.status.http_5xx)),"5xx error occurred")', '#0000FF')->addMetric('alias(scale(divideSeries(' . $base . '.apache.' . $site . '.status.http_3xx,' . $base . '.apache.' . $site . '.request.req_per_min),100),"3xx (%)")', '#cc0000')->addMetric('alias(scale(divideSeries(' . $base . '.apache.' . $site . '.status.http_4xx,' . $base . '.apache.' . $site . '.request.req_per_min),100),"4xx (%)")', '#00cc00')->addMetric('alias(scale(divideSeries(' . $base . '.apache.' . $site . '.status.http_5xx,' . $base . '.apache.' . $site . '.request.req_per_min),100),"5xx (%)")', '#0000cc')->setSize($width, $height);
    }
}
示例#8
0
<?php

if (is_null($_REQUEST['URI'])) {
    die("no URI");
}
$uri = $_REQUEST['URI'];
$rdf = "";
$uri = trim($uri);
$uri = preg_replace("/^(?!http:\\/\\/)/", "http://", $uri);
$objsrc = file_get_contents($uri);
include_once "../Graphite.php";
include_once "../arc/ARC2.php";
$g = new Graphite();
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mimetype = $finfo->buffer($objsrc);
if ($mimetype == "application/RDF+XML") {
    $g->addRDFXML("", $objsrc);
    $rdf = $objsrc;
} elseif ($mimetype == "text/turtle") {
    $g->addTurtle("", $objsrc);
    $rdf = $objsrc;
} elseif ($mimetype == "text/html") {
    $rdfuri = "";
    preg_match("/<a(?=[^>]*rdf[^>]*>)([^<]*)>/", $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
示例#9
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");
示例#10
0
 /**
  * Create a new resource list with containing only the resources which are in $resourcelist but not in the list being passed in. Only returns one instance of each resource no matter how many duplicates   were in either list.
  *
  * $new_resourcelist = $resourcelist->except( $resource );
  * $new_resourcelist = $resourcelist->except( *resource list* );
  */
 function except()
 {
     $args = func_get_args();
     if (isset($args[0]) && $args[0] instanceof Graphite_ResourceList) {
         $args = $args[0];
     }
     if (isset($args[0]) && is_array($args[0])) {
         $args = func_get_arg(0);
     }
     $list = new Graphite_ResourceList($this->g, array());
     $exclude = array();
     foreach ($args as $arg) {
         if (!$arg instanceof Graphite_Resource) {
             $arg = $this->g->resource($arg);
         }
         $exclude[Graphite::asString($arg)] = 1;
     }
     foreach ($this as $arg) {
         if (!$arg instanceof Graphite_Resource) {
             $arg = $this->g->resource($arg);
         }
         if (isset($exclude[Graphite::asString($arg)])) {
             continue;
         }
         $list[] = $arg;
     }
     return $list;
 }
示例#11
0
 function __toString()
 {
     return isset($this->triple["v"]) ? Graphite::asString($this->triple['v']) : "";
 }
示例#12
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>";
}
示例#13
0
# Generalize meeeee
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;
<?php

header("Content-Type:application/json");
include_once "arc2/ARC2.php";
include_once "arc2/Graphite.php";
$URL = $_GET['url'];
$CLASS = $_GET['class'];
$filename = getcwd() . "/cache/inst-" . urlencode($CLASS) . "-" . urlencode($URL) . ".json";
if (is_readable($filename)) {
    print file_get_contents($filename);
    return;
}
$graph = new Graphite();
$xml = simplexml_load_file($URL);
foreach ($xml->getNamespaces(true) as $prefix => $uri) {
    $graph->ns($prefix, stripslashes($uri));
}
$graph->load($URL);
$properties = array();
if (array_key_exists('properties', $_REQUEST)) {
    $PROPS = $_GET['properties'];
    $properties = explode(",", $PROPS);
}
// Here, we grab a List of all of this type of class
$resources = $graph->allOfType($CLASS);
$json = array();
foreach ($resources as $instance) {
    $suri = $graph->shrinkURI(trim($instance));
    $add = array("id" => $suri);
    foreach ($properties as $prop) {
        $propname = trim($prop);
示例#15
0
 protected function parsePropertyArg($arg)
 {
     if (is_a($arg, "Graphite_Resource")) {
         if (is_a($arg, "Graphite_InverseRelation")) {
             return array("op", Graphite::asString($arg));
         }
         return array("sp", Graphite::asString($arg));
     }
     $set = "sp";
     if (substr($arg, 0, 1) == "-") {
         $set = "op";
         $arg = substr($arg, 1);
     }
     return array($set, $this->g->expandURI("{$arg}"));
 }
示例#16
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;
 }
示例#17
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");
示例#18
0
#!/usr/bin/php
<?php 
# this is intended to be run on the command-line, but you could run it
# via the web if you wanted.
# you'll need to change all the paths.
require_once "../arc/ARC2.php";
require_once "../Graphite.php";
$graph = new Graphite();
$graph->ns("foo", "http://example.org/foons/");
$graph->load("mydata.rdf");
$graph->freeze("mydata.rdf.graphite");
# to use this graph from a script, use
# $graph = Graphite::thaw( "mydata.rdf.graphite" );
示例#19
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();
示例#20
0
 /**
  * Translate a URI from the short form to any long version known.
  * IE:  foaf:knows => http://xmlns.com/foaf/0.1/knows
  * also expands "a" => http://www.w3.org/1999/02/22-rdf-syntax-ns#type
  */
 public function expandURI($uri)
 {
     # allow "a" as even shorter cut for rdf:type. This doesn't get applied
     # in inverse if you use shrinkURI
     if ($uri == "a") {
         return "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
     }
     if (preg_match('/:/', Graphite::asString($uri))) {
         list($ns, $tag) = preg_split("/:/", Graphite::asString($uri), 2);
         if (isset($this->ns[$ns])) {
             return $this->ns[$ns] . $tag;
         }
     }
     return Graphite::asString($uri);
 }
示例#21
0
<?php

if (is_null($_REQUEST['URI'])) {
    die("no URI");
}
$uri = $_REQUEST['URI'];
$rdf = "";
$uri = preg_replace("/^(?!http:\\/\\/)/", "http://", $uri);
$objsrc = file_get_contents($uri);
include_once "../Graphite.php";
include_once "../arc/ARC2.php";
$g = new Graphite();
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mimetype = $finfo->buffer($objsrc);
if ($mimetype == "application/RDF+XML") {
    $g->addRDFXML("", $objsrc);
    $rdf = $objsrc;
} elseif ($mimetype == "text/turtle") {
    $g->addTurtle("", $objsrc);
    $rdf = $objsrc;
} elseif ($mimetype == "text/html") {
    //Try to get RDFXML link in the link section in the head
    //	$rdfuri = "";
    //	$model = str_get_html($objsrc);
    //
    //	foreach( $model->find('head',0)->find('link') as $link ){
    //	if ($link->type == 'application/rdf+xml'){
    //	$rdfuri = $link->href;
    //	$rdf = file_get_contents($rdfuri);
    //	$uri = preg_replace("/rdf/","id", $rdfuri);
    //	$g->addRDFXML("", $rdf);
示例#22
0
<div class="enc">
<?php 
//{
$nsArr = array('epid' => 'http://eprints.soton.ac.uk/id/', 'dc' => 'http://purl.org/dc/elements/1.1/', 'geo' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', 'bibo' => 'http://purl.org/ontology/bibo/', 'owl' => 'http://www.w3.org/2002/07/owl#', 'void' => 'http://rdfs.org/ns/void#', 'event' => 'http://purl.org/NET/c4dm/event.owl#', 'skos' => 'http://www.w3.org/2004/02/skos/core#', 'xsd' => 'http://www.w3.org/2001/XMLSchema#', 'cc' => 'http://creativecommons.org/ns#', 'ep' => 'http://eprints.org/ontology/', 'foaf' => 'http://xmlns.com/foaf/0.1/', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'eprel' => 'http://eprints.org/relation/', 'dct' => 'http://purl.org/dc/terms/', 'ecs' => 'http://rdf.ecs.soton.ac.uk/ontology/ecs#');
//}
$taginterest = array('rdf:type' => 1, 'owl:sameAs' => 1, 'rdfs:seeAlso' => 1, 'foaf:family_name' => 0, 'foaf:name' => 0, 'foaf:givenname' => 0, 'foaf:depiction' => 1, 'foaf:img' => 1, 'foaf:mbox' => 1, 'ecs:hasBiography' => 1, 'dct:title' => 1, 'foaf:primaryTopic' => 1, 'dct:date' => 1, 'bibo:abstract' => 1, 'bibo:status' => 1, 'dct:hasPart' => 1);
//}
$taglistlist = array('person' => array(0 => 'rdf:type', 'owl:sameAs', 'rdfs:seeAlso', 'foaf:family_name', 'foaf:name', 'foaf:givenname', 'foaf:depiction', 'foaf:img', 'foaf:mbox', 'ecs:hasBiography'), 'article' => array(0 => 'rdf:type', 'owl:sameAs', 'rdfs:seeAlso', 'dct:title', 'foaf:primaryTopic', 'dct:date', 'bibo:abstract', 'bibo:status', 'dct:hasPart'), 'project' => array(0 => 'rdf:type', 'owl:sameAs', 'rdfs:seeAlso', 'foaf:primaryTopic', 'dct:description', 'dct:title', 'ecs:hasTheme', 'dct:hasPart'), 'avdoc' => array(0 => 'rdf:type', 'owl:sameAs', 'rdfs:seeAlso', 'dct:hasPart', 'foaf:primaryTopic', 'foaf:img'), 'conference' => array(0 => 'rdf:type', 'owl:sameAs', 'rdfs:seeAlso', 'foaf:primaryTopic', 'dct:date'), 'seminar' => array(0 => 'rdf:type', 'owl:sameAs', 'rdfs:seeAlso', 'foaf:primaryTopic', 'dct:date'));
//}
$types = array('person' => array('sr' => 'Person', 'srp' => "People", 'tags' => array(0 => 'foaf:Person', 'ecs:Person')), 'paper' => array('sr' => 'Article', 'srp' => "Articles", 'tags' => array(0 => 'bibo:Article', 'bibo:AcademicArticle')), 'project' => array('sr' => 'Project', 'srp' => "Projects", 'tags' => array(0 => 'foaf:Project')), 'avdoc' => array('sr' => 'AV Document', 'srp' => "AV documents", 'tags' => array(0 => '')), 'conference' => array('sr' => 'Conference', 'srp' => "Conferences", 'tags' => array(0 => 'bibo:Conference')));
// }
$strings = array('person' => array('short' => '', 'long' => ''), 'article' => array('short' => '', 'long' => ''), 'project' => array('short' => '', 'long' => ''));
//}
require_once "Graphite.php";
require_once "arc/ARC2.php";
$g = new Graphite($nsArr);
// 	if (!is_null($url = $_GET['url'])) $g->load($url);
// 	elseif (!is_null($_REQUEST['rdf'])) foreach ($_REQUEST['rdf'] as $rdf) $g->loadRDFXML($rdf);
//  	else {
// 		echo 'document.write("Not RDF");';
// 	}
$source = "file:///var/www/d-ROC/results2.rdf";
// 	$source = "http://id.ecs.soton.ac.uk/person/1615";
$g->load($source);
echo '<ul class="floatingLinks">';
$struct = array();
$html = "";
foreach ($types as $intype => $array) {
    foreach ($array['tags'] as $type) {
        if (is_null($reslist)) {
            $reslist = $g->allOfType($type);
<?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();
示例#24
0
<?php

include_once "../arc/ARC2.php";
include_once "../Graphite.php";
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
$map = array("http://purl.org/dc/terms/creator" => "Creator", "http://purl.org/dc/terms/created" => "Date created", "http://purl.org/dc/terms/visits" => "Visits", "http://purl.org/dc/terms/established" => "Established", "http://purl.org/dc/terms/version" => "Version", "http://purl.org/ontology/bibo/presentedAt" => "Presented at", "http://purl.org/ontology/bibo/contributor" => "Contributor", "http://purl.org/dc/terms/analyser" => "Analyser", "http://eprints.org/ontology/downloads" => "Downloads", "http://purl.org/dc/terms/sampleSize" => "Sample size");
$uri = "http://id.ecs.soton.ac.uk/project/644";
$rdfuri = "../results.rdf";
$graph = new Graphite();
$graph->ns("eprel", "http://eprints.org/relation/");
$graph->ns("ecs", "http://rdf.ecs.soton.ac.uk/ontology/ecs#");
$graph->load($rdfuri);
// attempt to get a value from a resource
// it will return the first non-null valued element from the array, or if none can be found return the placeholder
function get_from_rdf($resource, $element_order_array, $placeholder)
{
    global $graph;
    foreach ($element_order_array as $element) {
        $value = $graph->resource($resource)->get($element);
        if ($value != "[NULL]") {
            return htmlspecialchars_decode($value);
        }
    }
    return $placeholder;
}
// get the text for the head title
function main_head()
{
    global $uri;
    global $graph;
示例#25
0
 function _toSPARQL($tree, $suffix, $in_dangler = null, $sparqlprefix = "")
 {
     $bits = array();
     if (!isset($in_dangler)) {
         $in_dangler = "<" . Graphite::asString($this->resource) . ">";
     }
     $i = 0;
     foreach ($tree as $dir => $routes) {
         if (sizeof($routes) == 0) {
             continue;
         }
         $pres = array();
         if (isset($routes["*"])) {
             $sub = "?s" . $suffix . "_" . $i;
             $pre = "?p" . $suffix . "_" . $i;
             $obj = "?o" . $suffix . "_" . $i;
             if ($dir == "+") {
                 $out_dangler = $obj;
                 $sub = $in_dangler;
             } else {
                 $out_dangler = $sub;
                 $obj = $in_dangler;
             }
             $construct = "{$sub} {$pre} {$obj} . ";
             $where = "{$sparqlprefix} {$sub} {$pre} {$obj} .";
             if (isset($routes["*"])) {
                 $bits_from_routes = $this->_toSPARQL($routes["*"], $suffix . "_" . $i, $out_dangler, "");
                 $i++;
                 foreach ($bits_from_routes as $bit) {
                     $construct .= $bit["construct"];
                     $where .= " OPTIONAL { " . $bit["where"] . " }";
                 }
             }
             $bits[] = array("where" => $where, "construct" => $construct);
             foreach ($routes as $pred => $route) {
                 if ($pred == "*") {
                     continue;
                 }
                 $pre = "<" . $this->graph->expandURI($pred) . ">";
                 $bits_from_routes = $this->_toSPARQL($route, $suffix . "_" . $i, $out_dangler, "{$sparqlprefix} {$sub} {$pre} {$obj} .");
                 $i++;
                 foreach ($bits_from_routes as $bit) {
                     $bits[] = $bit;
                 }
             }
         } else {
             foreach (array_keys($routes) as $pred) {
                 $sub = "?s" . $suffix . "_" . $i;
                 $pre = "<" . $this->graph->expandURI($pred) . ">";
                 $obj = "?o" . $suffix . "_" . $i;
                 if ($dir == "+") {
                     $out_dangler = $obj;
                     $sub = $in_dangler;
                 } else {
                     $out_dangler = $sub;
                     $obj = $in_dangler;
                 }
                 $bits_from_routes = $this->_toSPARQL($routes[$pred], $suffix . "_" . $i, $out_dangler, "");
                 $i++;
                 $construct = "{$sub} {$pre} {$obj} . ";
                 $where = "{$sparqlprefix} {$sub} {$pre} {$obj} .";
                 foreach ($bits_from_routes as $bit) {
                     $construct .= $bit["construct"];
                     $where .= " OPTIONAL { " . $bit["where"] . " }";
                 }
                 $bits[] = array("where" => $where, "construct" => $construct);
             }
         }
     }
     return $bits;
 }
示例#26
0
<?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";