Exemple #1
0
 public function retrieve()
 {
     $sm = MwRdf::StoredModel();
     $model = MwRdf::Model();
     $context = $this->Agent->getContextNode($this->getName());
     $stream = librdf_model_context_as_stream($sm->getModel(), $context->getNode());
     librdf_model_add_statements($model->getModel(), $stream);
     librdf_free_stream($stream);
     $sm->rewind();
     return $model;
 }
Exemple #2
0
 public function retrieveModel($par)
 {
     if (gettype($par) == 'string') {
         $par = array($par);
     }
     if (!gettype($par) == 'array') {
         throw new Exception('retrieveModel takes either a model ' . 'name string or an array of modelnames');
     }
     $model = MwRdf::Model();
     foreach ($par as $name) {
         $mm = $this->ModelMakers[$name];
         ### TODO Retrieve from Cache if it's there
         $sub_model = $mm->retrieve($name);
         ### TODO Cache the sub_model
         $stream = librdf_model_as_stream($sub_model->getModel());
         librdf_model_add_statements($model->getModel(), $stream);
         librdf_free_stream($stream);
         $sub_model->rewind();
     }
     return $model;
 }
Exemple #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;
 }