/** * Free a model's resources. * * @return void * @access public */ public function __destruct() { if ($this->model) { librdf_free_model($this->model); } }
$nval = '(unbound)'; } print " " . librdf_query_results_get_binding_name($results, $i) . "=" . $nval . "\n"; } print "}\n"; librdf_query_results_next($results); $count++; } if ($results) { print "Returned {$count} results\n"; } $results = null; print "\nExecuting query again\n"; $results = librdf_model_query_execute($model, $query); if ($results) { $str = librdf_query_results_to_string($results, null, null); print "Query results serialized to an XML string size " . strlen($str) . " bytes\n"; } else { print "Query results couldn't be serialized to an XML string\n"; } $serializer = librdf_new_serializer($world, 'rdfxml', null, null); print "Redland serializer created\n"; $base = librdf_new_uri($world, 'http://example.org/base.rdf'); print "Serializing...\n"; librdf_serializer_serialize_model_to_file($serializer, './test-out.rdf', $base, $model); print "Done...\n"; librdf_free_serializer($serializer); librdf_free_uri($base); librdf_free_model($model); librdf_free_storage($storage); print "Done\n";
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; }