예제 #1
0
파일: Query.php 프로젝트: bakulf/raop
 /**
  * Create a new query.
  *
  * Query language is any language supported by rasqal, including "rdql",
  * "sparql" and "triples".
  *
  * The syntax of the query is not checked until it is executed.
  *
  * @param   string      $query_string   The contents of the query
  * @param   string      $base_uri       The base URI to use
  * @param   string      $query_language The language of the query (default rdql)
  * @param   string      $query_uri      The URI of the query language or NULL
  * @return  void
  * @throws  LibRDF_Error                If unable to create a new query
  * @access  public
  */
 public function __construct($query_string, $base_uri = NULL, $query_language = "rdql", $query_uri = NULL)
 {
     if ($base_uri) {
         $base_uri = new LibRDF_URI($base_uri);
     }
     if ($query_uri) {
         $query_uri = new LibRDF_URI($query_uri);
     }
     $this->query = librdf_new_query(librdf_php_get_world(), $query_language, $query_uri ? $query_uri->getURI() : $query_uri, $query_string, $base_uri ? $base_uri->getURI() : $base_uri);
     if (!$this->query) {
         throw new LibRDF_Error("Unable to create a new query");
     }
 }
예제 #2
0
}
$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";
    for ($i = 0; $i < librdf_query_results_get_bindings_count($results); $i++) {
        $val = librdf_query_results_get_binding_value($results, $i);
        if ($val) {
            $nval = librdf_node_to_string($val);
        } else {
            $nval = '(unbound)';
        }
        print "  " . librdf_query_results_get_binding_name($results, $i) . "=" . $nval . "\n";
    }
    print "}\n";
예제 #3
0
파일: Graph.php 프로젝트: sgml/rww.io
 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;
 }