Esempio n. 1
0
 public function store()
 {
     $model = $this->build();
     $context = $this->Agent->getContextNode($this->getName());
     $store = MwRdf::StoredModel();
     $stream = librdf_model_as_stream($model->getModel());
     librdf_model_context_add_statements($store->getModel(), $context->getNode(), $stream);
     librdf_free_stream($stream);
     return true;
 }
Esempio n. 2
0
 /**
  * Discard the current statement iterator and create a new one.
  *
  * @return  void
  * @access  private
  */
 private function resetIterator()
 {
     if ($this->iterator === NULL) {
         $this->iterator = new LibRDF_StreamIterator(librdf_model_as_stream($this->model), $this);
     }
 }
Esempio n. 3
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;
 }
Esempio n. 4
0
 function to_jsonld_string()
 {
     $r = array();
     $stream = librdf_model_as_stream($this->_model);
     while (!librdf_stream_end($stream)) {
         $elt = $this->_statement(librdf_stream_get_object($stream));
         $d = new \stdClass();
         $d->{'@subject'} = $elt[0]['value'];
         if ($elt[2]['type'] == 'literal') {
             if (isset($elt[2]['datatype'])) {
                 $d->{$elt[1]['value']} = (object) array('@literal' => $elt[2]['value'], '@datatype' => $elt[2]['datatype']);
             } else {
                 $d->{$elt[1]['value']} = $elt[2]['value'];
             }
         } else {
             $d->{$elt[1]['value']} = (object) array('@iri' => $elt[2]['value']);
         }
         $r[] = $d;
         librdf_stream_next($stream);
     }
     librdf_free_stream($stream);
     return str_replace('\\/', '/', json_encode(jsonld_normalize($r)));
 }