Esempio n. 1
0
 /**
  * Create a new librdf_model.
  *
  * See the {@link http://librdf.org/ librdf} documentation for information
  * on the possible options.
  *
  * @param   LibRDF_Storage  $storage    The storage on which this model should be built
  * @param   string          $options    Options to pass to librdf_new_model
  * @return  void
  * @throws  LibRDF_Error    If unable to create a new model
  * @access  public
  */
 public function __construct(LibRDF_Storage $storage, $options = NULL)
 {
     $this->model = librdf_new_model(librdf_php_get_world(), $storage->getStorage(), $options);
     if (!$this->model) {
         throw new LibRDF_Error("Unable to create new model");
     }
     $this->iterator = NULL;
 }
Esempio n. 2
0
 *
 *
 */
/* ------------------------------------------------------------------------ */
print "Testing Redland...\n";
$dlls = array("redland.so", "php_redland.dll", "redland.dylib", "redland.bundle");
foreach ($dlls as $dll) {
    if (file_exists($dll)) {
        dl($dll);
    }
}
$world = librdf_php_get_world();
print "Redland world opened\n";
$storage = librdf_new_storage($world, 'hashes', 'dummy', "new=yes,hash-type='memory'");
print "Redland storage created\n";
$model = librdf_new_model($world, $storage, '');
print "Redland model created\n";
$parser = librdf_new_parser($world, 'rdfxml', 'application/rdf+xml', null);
print "Redland parser created\n";
$uri = librdf_new_uri($world, 'file:../data/dc.rdf');
print "Parsing...\n";
librdf_parser_parse_into_model($parser, $uri, $uri, $model);
print "Done...\n";
librdf_free_uri($uri);
librdf_free_parser($parser);
$query = librdf_new_query($world, 'sparql', null, "PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?a ?c ?d WHERE { ?a dc:title ?c . OPTIONAL { ?a dc:related ?d } }", null);
print "Querying for dc:titles:\n";
$results = librdf_model_query_execute($model, $query);
$count = 1;
while ($results && !librdf_query_results_finished($results)) {
    print "result {$count}: {\n";
Esempio n. 3
0
 function CONSTRUCT($query, $base_uri = null)
 {
     if (is_null($base_uri)) {
         $base_uri = $this->_base_uri;
     }
     timings($query);
     $q = librdf_new_query($this->_world, 'sparql', null, $query, $base_uri);
     $r = librdf_model_query_execute($this->_model, $q);
     $r_stream = librdf_query_results_as_stream($r);
     $r_store = librdf_new_storage($this->_world, 'memory', '', null);
     $r_model = librdf_new_model($this->_world, $r_store, null);
     librdf_model_add_statements($r_model, $r_stream);
     librdf_free_stream($r_stream);
     $serializer = librdf_new_serializer($this->_world, 'json', null, null);
     $r = librdf_serializer_serialize_model_to_string($serializer, null, $r_model);
     librdf_free_serializer($serializer);
     $r = json_decode($r, 1);
     if (is_null($r)) {
         $r = array();
     }
     librdf_free_model($r_model);
     librdf_free_storage($r_store);
     librdf_free_query($q);
     timings();
     return $r;
 }