示例#1
0
 public function newInstance($subject, $predicate, $object, $graph = null)
 {
     $world = librdf_php_get_world();
     $factory = new NodeFactory();
     try {
         $redlandSubject = $factory->createRedlandNodeFromNode($subject);
         $redlandPredicate = $factory->createRedlandNodeFromNode($predicate);
         $redlandObject = $factory->createRedlandNodeFromNode($object);
         $statement = librdf_new_statement_from_nodes($world, $redlandSubject, $redlandPredicate, $redlandObject);
         return new Statement($statement, $graph);
     } catch (\Exception $e) {
         $this->markTestSkipped('Can\'t execute this test because: ' . $e->getMessage());
     }
 }
示例#2
0
文件: Model.php 项目: bakulf/raop
 /**
  * Find a statement in the model.
  *
  * A NULL argument for any of source, predicate or target is treated as
  * a wildcard.  If a context is given, only statements from that context
  * will be returned.  The result is an object that be used in foreach
  * iteration.  The returned iterator cannot be rewound.
  *
  * The search arguments can be either a (source, predicate target) triple
  * of LibRDF_Node objects or a LibRDF_Statement object.  Valid argument 
  * lists are (source, predicate, target, [context]) or
  * (statement, [context]).
  *
  * For more complex queries, see {@link LibRDF_Query}.
  *
  * @param   mixed       $statement  The statement to match or a source node
  * @param   LibRDF_Node $predicate  The predicate to match
  * @param   LibRDF_Node $target     The target to match
  * @param   LibRDF_URINode  $context    The context in which to search
  * @return  LibRDF_StreamIterator   An iterator over the matched statements
  * @access  public
  */
 public function findStatements()
 {
     $num_args = func_num_args();
     if ($num_args == 1 or $num_args == 2) {
         $statement = func_get_arg(0);
         if (!$statement instanceof LibRDF_Statement) {
             throw new LibRDF_Error("First argument must be a LibRDF_Statement");
         }
         if ($num_args == 2) {
             $context = func_get_arg(1);
             if (!$context instanceof LibRDF_URINode) {
                 throw new LibRDF_Error("Context must be LibRDF_URINode");
             }
         } else {
             $context = NULL;
         }
         $statement = $statement->getStatement();
     } elseif ($num_args == 3 or $num_args == 4) {
         $source = func_get_arg(0);
         $predicate = func_get_arg(1);
         $target = func_get_arg(2);
         if ($source !== NULL) {
             if (!$source instanceof LibRDF_Node) {
                 throw new LibRDF_Error("Argument 1 must be of type LibRDF_Node");
             } else {
                 $source = librdf_new_node_from_node($source->getNode());
             }
         }
         if ($predicate !== NULL) {
             if (!$predicate instanceof LibRDF_Node) {
                 throw new LibRDF_Error("Argument 2 must be of type LibRDF_Node");
             } else {
                 $predicate = librdf_new_node_from_node($predicate->getNode());
             }
         }
         if ($target !== NULL) {
             if (!$target instanceof LibRDF_Node) {
                 throw new LibRDF_Error("Argument 3 must be of type LibRDF_Node");
             } else {
                 $target = librdf_new_node_from_node($target->getNode());
             }
         }
         if ($num_args == 4) {
             $context = func_get_arg(3);
             if (!$context instanceof LibRDF_URINode) {
                 throw new LibRDF_Error("Context must be LibRDF_URINode");
             }
         } else {
             $context = NULL;
         }
         $statement = librdf_new_statement_from_nodes(librdf_php_get_world(), $source, $predicate, $target);
     } else {
         throw new LibRDF_Error("findStatements takes 2-4 arguments");
     }
     if ($context !== NULL) {
         $stream_resource = librdf_model_find_statements_in_context($this->model, $statement, $context->getNode());
     } else {
         $stream_resource = librdf_model_find_statements($this->model, $statement);
     }
     if ($num_args > 2) {
         librdf_free_statement($statement);
     }
     if (!$stream_resource) {
         throw new LibRDF_Error("Unable to create new statement iterator");
     }
     return new LibRDF_StreamIterator($stream_resource, $this);
 }
示例#3
0
文件: Statement.php 项目: bakulf/raop
 /**
  * Create a new Statement.
  *
  * The subject must be either a URINode or a BlankNode.  The predicate
  * must be a URINode.
  *
  * @param   mixed       $statement  The librdf_statement to copy or the source Node of a statement
  * @param   LibRDF_Node $predicate  The statement's predicate
  * @param   LibRDF_Node $object     The statement's object
  * @return  void
  * @throws  LibRDF_Error            If unable to create a new statement
  * @access  public
  */
 public function __construct()
 {
     $num_args = func_num_args();
     if ($num_args == 1) {
         $statement = func_get_arg(0);
         if (!is_resource($statement)) {
             throw new LibRDF_Error("Single parameter must be a librdf_statement");
         } else {
             $this->statement = $statement;
         }
     } elseif ($num_args == 3) {
         $subject = func_get_arg(0);
         $predicate = func_get_arg(1);
         $object = func_get_arg(2);
         if ($subject instanceof LibRDF_Node and $predicate instanceof LibRDF_Node and $object instanceof LibRDF_Node) {
             $this->statement = librdf_new_statement_from_nodes(librdf_php_get_world(), librdf_new_node_from_node($subject->getNode()), librdf_new_node_from_node($predicate->getNode()), librdf_new_node_from_node($object->getNode()));
         } else {
             throw new LibRDF_Error("Arguments must be of type LibRDF_Node");
         }
     }
     if (!$this->statement) {
         throw new LibRDF_Error("Uanble to create new statement");
     }
 }
示例#4
0
文件: Graph.php 项目: sgml/rww.io
 function remove_triple($triple)
 {
     if (!isset($triple['type']) || $triple['type'] != 'triple') {
         return 0;
     }
     $r = 0;
     $s = $triple['s'];
     $p = $triple['p'];
     $o = $triple['o'];
     if (!is_null($s)) {
         $s = $this->_uriNode($s);
     }
     if (!is_null($p)) {
         $p = $this->_uriNode($p);
     }
     if (!is_null($o)) {
         if ($triple['o_type'] == 'uri') {
             $o = $this->_uriNode($o);
         } elseif ($triple['o_type'] == 'literal') {
             $o = $this->_literalNode($o);
         }
     }
     $pattern = librdf_new_statement_from_nodes($this->_world, $s, $p, $o);
     $stream = librdf_model_find_statements($this->_model, $pattern);
     while (!librdf_stream_end($stream)) {
         $elt = librdf_stream_get_object($stream);
         $r += librdf_model_remove_statement($this->_model, $elt) ? 0 : 1;
         librdf_stream_next($stream);
     }
     librdf_free_stream($stream);
     //librdf_free_statement($pattern);
     //$s && librdf_free_node($s);
     //$p && librdf_free_node($p);
     return $r;
 }