Exemple #1
0
 /**
  * Create a new query.
  *
  * Query language is any language supported by rasqal, including "rdql",
  * "sparql" and "triples".
  *
  * The syntax of the query is not checked until it is executed.
  *
  * @param   string      $query_string   The contents of the query
  * @param   string      $base_uri       The base URI to use
  * @param   string      $query_language The language of the query (default rdql)
  * @param   string      $query_uri      The URI of the query language or NULL
  * @return  void
  * @throws  LibRDF_Error                If unable to create a new query
  * @access  public
  */
 public function __construct($query_string, $base_uri = NULL, $query_language = "rdql", $query_uri = NULL)
 {
     if ($base_uri) {
         $base_uri = new LibRDF_URI($base_uri);
     }
     if ($query_uri) {
         $query_uri = new LibRDF_URI($query_uri);
     }
     $this->query = librdf_new_query(librdf_php_get_world(), $query_language, $query_uri ? $query_uri->getURI() : $query_uri, $query_string, $base_uri ? $base_uri->getURI() : $base_uri);
     if (!$this->query) {
         throw new LibRDF_Error("Unable to create a new query");
     }
 }
Exemple #2
0
 /**
  * Set a prefix to URI mapping.
  *
  * @param   string      $uri    The namespace URI
  * @param   string      $prefix The string prefix to use
  * @return  void
  * @throws  LibRDF_Error        If unable to set the prefix
  * @access  public
  */
 public function setNamespace($uri, $prefix)
 {
     $uri = new LibRDF_URI($uri);
     $ret = librdf_serializer_set_namespace($this->serializer, $uri->getURI(), $prefix);
     if ($ret) {
         throw new LibRDF_Error("Unable to set namespace prefix");
     }
 }
Exemple #3
0
 /**
  * Create a new URINode from a URI object.
  *
  * @param   mixed       $uri    The URI string or librdf_node value to use
  * @return  void
  * @throws  LibRDF_Error        If unable to create a new URI
  * @access  public
  */
 public function __construct($uri)
 {
     if (is_string($uri)) {
         $uri = new LibRDF_URI($uri);
         $this->node = librdf_new_node_from_uri(librdf_php_get_world(), $uri->getURI());
     } elseif (is_resource($uri) and librdf_node_is_resource($uri)) {
         $this->node = $uri;
     } else {
         throw new LibRDF_Error("Argument is not a string or \n                librdf_node resource");
     }
     if (!$this->node) {
         throw new LibRDF_Error("Unable to create new URI node");
     }
 }
Exemple #4
0
 /**
  * Serialize the model and write the contents to a file.
  *
  * @param   LibRDF_Serializer   $serializer The serializer to use
  * @param   string              $file_name  The name of the file to which to write
  * @param   string              $base_uri   The base URI to use
  * @return  void
  * @throws  LibRDF_Error        If unable to serialize the model
  * @access  public
  */
 public function serializeStatementsToFile(LibRDF_Serializer $serializer, $file_name, $base_uri = NULL)
 {
     if ($base_uri) {
         $base_uri = new LibRDF_URI($base_uri);
     }
     $ret = librdf_serializer_serialize_model_to_file($serializer->getSerializer(), $file_name, $base_uri ? $base_uri->getURI() : $base_uri, $this->model);
     if ($ret) {
         throw new LibRDF_Error("Error serializing model to file");
     }
 }
Exemple #5
0
 /**
  * Serialize the results to a string.
  *
  * @param   string      $uri        The uri of the target syntax or NULL
  * @param   string      $base_uri   The base URI for the output or NULL
  * @return  string                  The results as a string
  * @throws  LibRDF_Error            If unable to create a string from the results
  * @access  public
  */
 public function to_string($uri = NULL, $base_uri = NULL)
 {
     if ($uri) {
         $uri = new LibRDF_URI($uri);
     }
     if ($base_uri) {
         $base_uri = new LibRDF_URI($base_uri);
     }
     $ret = librdf_query_results_to_string($this->query_results, $uri ? $uri->getURI() : NULL, $base_uri ? $base_uri->getURI() : NULL);
     if ($ret) {
         return $ret;
     } else {
         throw new LibRDF_Error("Unable to convert the query results to a string");
     }
 }
Exemple #6
0
 /**
  * Parse a URI and return an iterable object over the statements.
  *
  * The object returned can be used in PHP foreach statements.  It is not
  * rewindable.
  *
  * @param   string      $uri        The URI to parse
  * @param   string      $base_uri   The value to use for the base URI if different from $uri
  * @return  LibRDF_StreamIterator   An iterator over the LibRDF_Statements parsed from $uri
  * @throws  LibRDF_Error            If unable to parse the URI
  * @access  public
  */
 public function parseURI($uri, $base_uri = NULL)
 {
     $uri = new LibRDF_URI($uri);
     if ($base_uri) {
         $base_uri = new LibRDF_URI($base_uri);
     }
     $stream = librdf_parser_parse_as_stream($this->parser, $uri->getURI(), $base_uri ? $base_uri->getURI() : $base_uri);
     if (!$stream) {
         throw new LibRDF_Error("Unable to parse URI");
     }
     return new LibRDF_StreamIterator($stream, $this);
 }
Exemple #7
0
 /**
  * Compare this URI against another URI for equality.
  *
  * @param   LibRDF_URI  $uri    The URI against which to compare
  * @return  boolean     Whether the two URIs are equal
  * @access  public
  */
 public function isEqual(LibRDF_URI $uri)
 {
     if (librdf_uri_equals($this->uri, $uri->getURI())) {
         return true;
     } else {
         return false;
     }
 }