Beispiel #1
0
 /**
  * Gets data types in range of the property.
  *
  * @param string $uri
  *   URI of the resource (eg: schema:name).
  *
  * @return null|array
  *   Array containing URIs of the datatype, if not null.
  */
 public function getRangeDataTypes($uri) {
   if (empty($uri)) {
     drupal_set_message($this->t("Invalid URI"));
     return NULL;
   }
   $range_datatypes = $this->graph->allResources($uri, "schema:rangeIncludes");
   if (!empty($range_datatypes)) {
     $range_datatype_uris = array();
     foreach ($range_datatypes as $type) {
       array_push($range_datatype_uris, $type->getUri());
     }
     return $range_datatype_uris;
   }
   return NULL;
 }
Beispiel #2
0
$graph = new EasyRdf_Graph("http://localhost/lod/tcmdemoen.rdf");
$graph->load();
echo "The count is: " . $graph->countTriples();
$data = $graph->serialise('ntriples');
if (!is_scalar($data)) {
    $data = var_export($data, true);
}
//print htmlspecialchars($data);
//$me = $graph->resource('http://www.example.com/Huperzia_Serrata');
$me = $graph->resource('http://www.example.com/fourGentlemenDecoction');
echo "<p>http://www.example.com/Huperzia_Serrata 的标签是: " . $me->get('rdfs:label') . "</p>";
echo "<p>http://www.example.com/Huperzia_Serrata 的中文标签是: " . $me->label('zh') . "</p>";
echo "<p>http://www.example.com/Huperzia_Serrata 的英文标签是: " . $me->label('en') . "</p>";
$hasMinister = $graph->resource('http://www.example.com/hasMinister');
echo "<p>http://www.example.com/hasMinister 的标签是: " . $hasMinister->get('rdfs:label') . "</p>";
$graph->allResources($me, $hasMinister);
foreach ($me->all($hasMinister) as $type) {
    echo 'start';
    $label = $type->label('zh');
    if (!$label) {
        $label = $type->getUri();
    }
    if ($type->isBnode()) {
        echo "<li>{$label}</li>";
    } else {
        echo "<li>" . link_to_self($label, 'uri=' . urlencode($friend)) . "</li>";
    }
}
foreach ($me->toArray() as $type => $value) {
    echo $type . ':' . $value;
}