Пример #1
0
 function del_friend($uri, $format = 'rdfxml')
 {
     $uri = urldecode($uri);
     $path = $this->get_local_path($this->webid);
     // Create the new graph object in which we store data
     $graph = new EasyRdf_Graph($this->webid);
     $graph->load();
     $person = $graph->resource($this->webid);
     $graph->deleteResource($person, 'foaf:knows', $uri);
     // write profile to file
     $data = $graph->serialise($format);
     if (!is_scalar($data)) {
         $data = var_export($data, true);
     } else {
         $data = print_r($data, true);
     }
     $pf = fopen($path . '/foaf.rdf', 'w') or die('Cannot open profile RDF file!');
     fwrite($pf, $data);
     fclose($pf);
     $pf = fopen($path . '/foaf.txt', 'w') or die('Cannot open profile TXT file!');
     fwrite($pf, $data);
     fclose($pf);
     // get the user's name
     $friend = new MyProfile($uri, $this->base_uri, SPARQL_ENDPOINT);
     $friend->load();
     // everything is fine
     return success("You have just removed " . $friend->get_name() . " from your list of friends.");
 }
Пример #2
0
 /**
  * Rebase the graph on triples with the start fragment to our own base URI
  *
  * @param string        $start_fragment
  * @param EasyRdf_Graph $graph
  *
  * @return EasyRdf_Graph
  */
 private function rebaseGraph($start_fragment, $graph)
 {
     // Filter out the #dataset meta-data (if present) and change the URI's to our base URI
     $collections = $graph->allOfType('hydra:Collection');
     // Fetch all of the subject URI's that bring forth hydra meta-data (and are thus irrelevant)
     $ignore_subjects = array();
     if (empty($collection)) {
         $collections = $graph->allOfType('hydra:PagedCollection');
     }
     if (!empty($collections)) {
         foreach ($collections as $collection) {
             array_push($ignore_subjects, $collection->getUri());
         }
     }
     // Fetch the bnode of the hydra mapping (property is hydra:search)
     $hydra_mapping = $graph->getResource($start_fragment . '#dataset', 'hydra:search');
     if (!empty($hydra_mapping)) {
         // Hydra mapping's will be a bnode structure
         array_push($ignore_subjects, '_:' . $hydra_mapping->getBNodeId());
         $mapping_nodes = $hydra_mapping->all('hydra:mapping');
         foreach ($mapping_nodes as $mapping_node) {
             if ($mapping_node->isBNode()) {
                 array_push($ignore_subjects, '_:' . $mapping_node->getBNodeId());
             }
         }
         $graph->deleteResource($start_fragment . '#dataset', 'hydra:search', '_:genid1');
         $graph->deleteResource('_:genid1', 'hydra:mapping', '_:genid2');
         // Delete all of the mapping related resources
         $triples = $graph->toRdfPhp();
     } else {
         // Change all of the base (startfragment) URI's to our own base URI
         $triples = $graph->toRdfPhp();
     }
     // Unset the #dataset
     unset($triples[$start_fragment . '#dataset']);
     foreach ($ignore_subjects as $ignore_subject) {
         unset($triples[$ignore_subject]);
     }
     $adjusted_graph = new \EasyRdf_Graph();
     foreach ($triples as $subject => $triple) {
         foreach ($triple as $predicate => $objects) {
             foreach ($objects as $object) {
                 $adjusted_graph->add($subject, $predicate, $object['value']);
             }
         }
     }
     return $adjusted_graph;
 }