예제 #1
0
 /**
  * @author "Lionel Lecaque, <*****@*****.**>"
  * @param string $namespace
  * @param string $data xml content
  */
 public function createModel($namespace, $data)
 {
     $modelId = $this->getModelId($namespace);
     if ($modelId === false) {
         common_Logger::d('modelId not found, need to add namespace ' . $namespace);
         $this->addNewModel($namespace);
         //TODO bad way, need to find better
         $modelId = $this->getModelId($namespace);
     }
     $modelDefinition = new EasyRdf_Graph($namespace);
     if (is_file($data)) {
         $modelDefinition->parseFile($data);
     } else {
         $modelDefinition->parse($data);
     }
     $graph = $modelDefinition->toRdfPhp();
     $resources = $modelDefinition->resources();
     $format = EasyRdf_Format::getFormat('php');
     $data = $modelDefinition->serialise($format);
     foreach ($data as $subjectUri => $propertiesValues) {
         foreach ($propertiesValues as $prop => $values) {
             foreach ($values as $k => $v) {
                 $this->addStatement($modelId, $subjectUri, $prop, $v['value'], isset($v['lang']) ? $v['lang'] : null);
             }
         }
     }
     return true;
 }
예제 #2
0
  /**
   * Identifies all types and properties of the graph separately.
   */
  private function iterateGraph() {
    $resource_list = $this->graph->resources();

    foreach ($resource_list as $value) {
      if ($value->prefix() !== "schema") {
        continue;
      }
      if ($value->isA("rdf:Property") || $value->isA("rdfs:Property")) {
        $this->addProperties($value);
      }
      else {
        $this->addType($value);
      }
    }
  }
예제 #3
0
 public function queryWorldCatFromOCLC()
 {
     $oclc = (string) (int) $this->OCLC;
     $url = 'http://www.worldcat.org/oclc/' . $oclc;
     $rdf = new EasyRdf_Graph($url . '.rdf');
     $rdf->load();
     $resources = $rdf->resources();
     $book = $resources[$url];
     //Core info
     $this->Title = (string) $book->getLiteral('schema:name');
     $publisherData = $book->get('schema:publisher');
     if ($publisherData) {
         $this->Publisher = (string) $publisherData->get('schema:name');
     }
     //Publishing date
     $date = (string) $book->getLiteral('schema:datePublished');
     if (strlen($date) == 4) {
         $this->YYYY = $date;
     } else {
         echo '<div class="alert-box">Publishing date: ', $date, " / check the template, the code doesn't know how to parse this format and only made a guess. ", '<a href="" class="close">&times;</a></div>';
         $date = date_parse($date);
         $this->YYYY = $date['year'];
         $this->MM = $date['month'];
         $this->DD = $date['day'];
     }
     //Authors
     $this->Authors = [];
     //TODO: look type mapping
     $contributors = $book->allResources('schema:contributor');
     foreach ($contributors as $contributor) {
         $this->Authors[] = [(string) $contributor->get('schema:givenName'), (string) $contributor->get('schema:familyName')];
     }
     //Kludge for library:placeOfPublication
     //We have generally two links, one for the city, one for the country.
     //Only the city has a schema:name, the country is only a reference.
     $rdf_content = file_get_contents($url . '.rdf');
     if (preg_match_all('@<library:placeOfPublication rdf:resource="(.*)"/>@', $rdf_content, $matches)) {
         foreach ($matches[1] as $place) {
             if ($cityCandidate = (string) $resources[$place]->get('schema:name')) {
                 $this->Place = $cityCandidate;
                 break;
             }
         }
     }
 }
예제 #4
0
 /**
  * Imports the rdf file into the selected class
  * 
  * @param string $file
  * @param core_kernel_classes_Class $class
  * @return common_report_Report
  */
 private function flatImport($file, core_kernel_classes_Class $class)
 {
     $report = common_report_Report::createSuccess(__('Data imported successfully'));
     $graph = new EasyRdf_Graph();
     $graph->parseFile($file);
     // keep type property
     $map = array(RDF_PROPERTY => RDF_PROPERTY);
     foreach ($graph->resources() as $resource) {
         $map[$resource->getUri()] = common_Utils::getNewUri();
     }
     $format = EasyRdf_Format::getFormat('php');
     $data = $graph->serialise($format);
     foreach ($data as $subjectUri => $propertiesValues) {
         $resource = new core_kernel_classes_Resource($map[$subjectUri]);
         $subreport = $this->importProperties($resource, $propertiesValues, $map, $class);
         $report->add($subreport);
     }
     return $report;
 }
 public function testResources()
 {
     $data = readFixture('foaf.json');
     $graph = new EasyRdf_Graph('http://example.com/joe/foaf.rdf', $data);
     $resources = $graph->resources();
     $this->assertTrue(is_array($resources));
     $this->assertType('EasyRdf_Resource', $resources['_:genid1']);
     $urls = array_keys($resources);
     sort($urls);
     $this->assertEquals(array('_:genid1', 'http://www.example.com/joe#me', 'http://www.example.com/joe/', 'http://www.example.com/joe/foaf.rdf', 'http://www.example.com/project', 'http://xmlns.com/foaf/0.1/Person', 'http://xmlns.com/foaf/0.1/PersonalProfileDocument', 'http://xmlns.com/foaf/0.1/Project'), $urls);
 }
예제 #6
0
$uniqid = uniqid();
$suchbegriff = str_replace(" ", "+", $_GET["qname"]);
//$suchbegriff='123apfelkuchen';
$rdf = "";
if (isset($_GET["rdf"])) {
    $rdf = $_GET["rdf"];
}
$basedir = dirname(realpath(__FILE__));
$root = $basedir;
$ldfu = $root . '/ldfu/bin/ldfu.sh';
$n3_programm = $root . '/n3-files/chefkoch.n3';
$input = 'http://manke-hosting.de/wrapper/index.php/explore/' . $suchbegriff;
$output = $root . '/output/' . $suchbegriff . '.nt';
if (!file_exists($output)) {
    $command = 'sh ' . $ldfu . ' ' . '-i ' . $input . ' ' . '-p ' . $n3_programm . ' ' . '-o ' . $output;
    shell_exec($command);
}
$graph->parseFile($output);
//$graph ->parseFile('/Users/raphaelmanke/Downloads/linked-data-fu-0.9.9/streuselkuchen3.nt');
//$me = $foaf->primaryTopic();
//echo $graph->dump('html');
$resources = $graph->resources();
$namespace = new EasyRdf_Namespace();
$namespace->set('rezept', "http://manke-hosting.de/ns-syntax#");
$rezepte = $graph->resourcesMatching('rezept:RezeptName');
if ($rdf == "true") {
    header("Content-Type: text/turtle; charset=utf-8");
    echo $graph->serialise("turtle");
} else {
    include 'results/rezept.php';
}
예제 #7
0
 public function testResources()
 {
     $data = readFixture('foaf.json');
     $graph = new EasyRdf_Graph('http://example.com/joe/foaf.rdf', $data);
     $resources = $graph->resources();
     $this->assertStringEquals('http://www.example.com/joe#me', $resources['http://www.example.com/joe#me']);
     $this->assertStringEquals('_:eid1', $resources['_:eid1']);
     $this->assertStringEquals('http://www.example.com/joe/', $resources['http://www.example.com/joe/']);
     $this->assertStringEquals('http://www.example.com/joe/foaf.rdf', $resources['http://www.example.com/joe/foaf.rdf']);
     $this->assertStringEquals('http://www.example.com/project', $resources['http://www.example.com/project']);
 }
예제 #8
0
파일: Turtle.php 프로젝트: aWEBoLabs/taxi
 /**
  * @ignore
  */
 protected function serialiseSubjects(EasyRdf_Graph $graph, $filterType)
 {
     $turtle = '';
     foreach ($graph->resources() as $resource) {
         /** @var $resource EasyRdf_Resource */
         // If the resource has no properties - don't serialise it
         $properties = $resource->propertyUris();
         if (count($properties) == 0) {
             continue;
         }
         // Is this node of the right type?
         $thisType = $resource->isBNode() ? 'bnode' : 'uri';
         if ($thisType != $filterType) {
             continue;
         }
         if ($thisType == 'bnode') {
             $id = $resource->getBNodeId();
             if (isset($this->outputtedBnodes[$id])) {
                 // Already been serialised
                 continue;
             }
             $this->outputtedBnodes[$id] = true;
             $rpcount = $this->reversePropertyCount($resource);
             if ($rpcount == 0) {
                 $turtle .= '[]';
             } else {
                 $turtle .= $this->serialiseResource($resource);
             }
         } else {
             $turtle .= $this->serialiseResource($resource);
         }
         $turtle .= $this->serialiseProperties($resource);
         $turtle .= "\n";
     }
     return $turtle;
 }