/** * Create a new node object from an existing node. * * @return void * @throws LibRDF_Error If unable to copy the node * @access public */ public function __clone() { $this->node = librdf_new_node_from_node($this->node); if (!$this->node) { throw new LibRDF_Error("Unable to create new Node from Node"); } }
/** * Get the statement's object. * * @return LibRDF_Node The statement's object * @access public */ public function getObject() { $node = librdf_statement_get_object($this->statement); $object = LibRDF_Node::makeNode(librdf_new_node_from_node($node)); return $object; }
/** * Return the current node or NULL if the iterator is no longer valid. * * @return LibRDF_Statement The current node on the iterator * @access public */ public function current() { if ($this->isvalid and !librdf_iterator_end($this->iterator)) { // the pointer returned is overwritten when the iterator is // advanced or closed, so make a copy of the node $ret = librdf_iterator_get_object($this->iterator); if ($ret) { return LibRDF_Node::makeNode(librdf_new_node_from_node($ret)); } else { throw new LibRDF_Error("Unable to get current node"); } } else { return NULL; } }
/** * 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); }
/** * Return the current tuple of bindings. * * The result is an associative array using the binding names as the * indices. * * @return array The current bindings tuple * @throws LibRDF_Error If unable to get the current bindings tuple * @access public */ public function current() { if ($this->isvalid and !librdf_query_results_finished($this->query_results)) { $retarr = array(); $numbindings = librdf_query_results_get_bindings_count($this->query_results); if ($numbindings < 0) { throw new LibRDF_Error("Unable to get number of bindings in result"); } for ($i = 0; $i < $numbindings; $i++) { $key = librdf_query_results_get_binding_name($this->query_results, $i); $value = librdf_query_results_get_binding_value($this->query_results, $i); if (!$key or !$value) { throw new LibRDF_Error("Failed to get current binding {$i}"); } $retarr[$key] = LibRDF_Node::makeNode(librdf_new_node_from_node($value)); } return $retarr; } else { return NULL; } }