Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 * See LICENSE.html or LICENSE.txt at the top of this package for the
 * full license terms.
 *
 *
 */
/* ------------------------------------------------------------------------ */
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;
Exemplo n.º 3
0
 /**
  * Creates a new storage backend.
  *
  * The storage methods available depends on the librdf configuration.
  * Methods always available are `memory', `hashes', `file' and `uri'.
  * Optional methods are `bdb', `mysql' and `sqllite'.  The default is
  * `memory'.
  *
  * The name argument is mandatory for storage methods that required a named
  * handle, such as file and URI.
  *
  *   <code>$stor = new LibRDF_Storage(storage_name="file", name="/tmp/filename");</code>
  *
  * The options string passes storage_name specific options to the chosen
  * backend and uses the following form:
  *
  *   <code>$stor = new LibRDF_Storage("storage_name", "name",
  *              "key1='value1', key2='value2', ...");</code>
  * 
  * Options values must be surrounded by single quotes for multiple
  * key/option pairs.
  *
  * The options common to all storage methods are:
  *    new - optional boolean (default false)
  *       If true, delete any existing store and create a new one, otherwise
  *       open an existing store.
  *    
  *    write - optional boolean (default true)
  *       If true, open the store in read-write mode.
  * 
  * For hashes:
  *    hash-type - the name of any supported hash type (default 'memory')
  *       'memory' and 'file' hash types are always present, and 'bdb'
  *       may be available depending on compile-time configuration of
  *       librdf.
  *    
  *    dir - (default '.') the directory in which to create files
  *
  *    mode - (default 0644) the octal file mode with which to create files
  *
  * @param   string  $storage_name   The type of storage to use
  * @param   string  $name           A name for the storage handle
  * @param   string  $options        Options for the storage backend
  * @return  void
  * @throws  LibRDF_Error            If unable to create a new storage
  * @access  public
  */
 public function __construct($storage_name = "memory", $name = NULL, $options = NULL)
 {
     $this->storage = librdf_new_storage(librdf_php_get_world(), $storage_name, $name, $options);
     if (!$this->storage) {
         throw new LibRDF_Error("Unable to create storage");
     }
 }