Exemplo n.º 1
0
Arquivo: URI.php Projeto: bakulf/raop
 /**
  * Create a new URI object from a string.
  *
  * @param   string          $uri_string The string to use for the URI
  * @return  void
  * @throws  LibRDF_Error    If unable to create a new URI
  * @access  public
  */
 public function __construct($uri_string)
 {
     $this->uri = librdf_new_uri(librdf_php_get_world(), $uri_string);
     if (!$this->uri) {
         throw new LibRDF_Error("Unable to create new URI from string");
     }
 }
Exemplo n.º 2
0
 /**
  * Create a new parser.
  *
  * Name is the type of parser.  Common parsers are "rdfxml", "ntriples" and
  * "turtle".  If all arguments are NULL, any available parser for
  * application/rdf+xml will be used.
  *
  * @param   string      $name       The name of the parser to use
  * @param   string      $mime_type  The MIME type of the values to parse
  * @param   string      $type_uri   The URI of the RDF syntax to parse
  * @return  void
  * @throws  LibRDF_Error            If unable to create a new parser
  * @access  public
  */
 public function __construct($name = NULL, $mime_type = NULL, $type_uri = NULL)
 {
     if ($type_uri) {
         $type_uri = new LibRDF_URI($type_uri);
     }
     $this->parser = librdf_new_parser(librdf_php_get_world(), $name, $mime_type, $type_uri ? $type_uri->getURI() : $type_uri);
     if (!$this->parser) {
         throw new LibRDF_Error("Unable to create new parser");
     }
 }
Exemplo n.º 3
0
 public function __construct()
 {
     if (!extension_loaded('redland')) {
         throw new \Exception('Redland php5-librdf is required for this parser');
     }
     $format = 'turtle';
     $this->world = librdf_php_get_world();
     $this->parser = librdf_new_parser($this->world, $format, null, null);
     if (false === $this->parser) {
         throw new \Exception('Failed to create librdf_parser of type: ' . $format);
     }
 }
Exemplo n.º 4
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");
     }
 }
Exemplo n.º 5
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());
     }
 }
Exemplo n.º 6
0
 /**
  * @param  string $uri URI of the new named node.
  * @return NamedNode
  */
 public function createNamedNode($uri)
 {
     if ($uri === null) {
         throw new \Exception('Can\'t initialize node with null.');
     }
     if (!NodeUtils::simpleCheckURI($uri)) {
         throw new \Exception('Invalid URI was given for RDF NamedNode creation.');
     }
     // TODO catch invalid URIs
     $world = librdf_php_get_world();
     $uri = librdf_new_uri($world, $uri);
     $redlandNode = librdf_new_node_from_uri($world, $uri);
     if ($redlandNode === null) {
         throw new \Exception('Initialization of redland node failed.');
     }
     return new NamedNode($redlandNode);
 }
Exemplo n.º 7
0
 * the above three licenses.
 * 
 * See LICENSE.html or LICENSE.txt at the top of this package for the
 * full license terms.
 *
 *
 */
/* ------------------------------------------------------------------------ */
print "Testing Redland...\n";
$dlls = array("redland.so", "php_redland.dll", "redland.dylib", "redland.bundle");
foreach ($dlls as $dll) {
    if (file_exists($dll)) {
        dl($dll);
    }
}
$world = librdf_php_get_world();
print "Redland world opened\n";
$storage = librdf_new_storage($world, 'hashes', 'dummy', "new=yes,hash-type='memory'");
print "Redland storage created\n";
$model = librdf_new_model($world, $storage, '');
print "Redland model created\n";
$parser = librdf_new_parser($world, 'rdfxml', 'application/rdf+xml', null);
print "Redland parser created\n";
$uri = librdf_new_uri($world, 'file:../data/dc.rdf');
print "Parsing...\n";
librdf_parser_parse_into_model($parser, $uri, $uri, $model);
print "Done...\n";
librdf_free_uri($uri);
librdf_free_parser($parser);
$query = librdf_new_query($world, 'sparql', null, "PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?a ?c ?d WHERE { ?a dc:title ?c . OPTIONAL { ?a dc:related ?d } }", null);
print "Querying for dc:titles:\n";
 /**
  * Constructor
  *
  * @return object EasyRdf_Parser_Redland
  */
 public function __construct()
 {
     if (extension_loaded('redland')) {
         $this->_world = librdf_php_get_world();
         if (!$this->_world) {
             throw new EasyRdf_Exception("Failed to initialise librdf world.");
         }
     } else {
         throw new EasyRdf_Exception("Redland PHP extension is not available.");
     }
 }
Exemplo n.º 9
0
 /**
  * Create a new LibRDF_Serializer.
  *
  * Name is the name of the serializer to use.  Common choices are
  * "rdfxml", "ntriples" and "turtle".
  *
  * The "rdfxml" serializer is not pretty, outputing a flat list of
  * one XML element per statement.  "rdfxml-abbrev" is a bit nicer, but
  * slower.
  *
  * @param   string      $name       The name of the serializer to use
  * @param   string      $mime_type  The MIME type of the syntax
  * @param   string      $type_uri   The URI of the syntax
  * @return  void
  * @throws  LibRDF_Error            If unable to create a new serializer
  * @access  public
  */
 public function __construct($name, $mime_type = NULL, $type_uri = NULL)
 {
     if ($type_uri) {
         $type_uri = new LibRDF_URI($type_uri);
     }
     $this->serializer = librdf_new_serializer(librdf_php_get_world(), $name, $mime_type, $type_uri ? $type_uri->getURI : $type_uri);
     if (!$this->serializer) {
         throw new LibRDF_Error("Unable to create new serializer");
     }
     foreach (self::$namespaces as $uri => $prefix) {
         $this->setNamespace($uri, $prefix);
     }
 }
Exemplo n.º 10
0
Arquivo: Node.php Projeto: bakulf/raop
 /**
  * Create a new Literal node.
  *
  * Both the $language and $datatype parameters are optional.
  *
  * The value of the literal node can either be a string or an XML literal
  * in the form of a DOMNodeList object.  If using XML, a datatype of
  * http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral is implied, so
  * the datatype parameter cannot be used with XML.  A literal cannot have
  * both a language and a datatype.
  *
  * @param   mixed       $value      The literal value, either a string, a DOMNodeList or a librdf_node resource
  * @param   string      $datatype   An optional datatype URI for the literal value
  * @param   string      $language   An option language for the literal value
  * @return  void
  * @throws  LibRDF_Error            If unabel to create a new node
  * @access  public
  */
 public function __construct()
 {
     $valuestr = "";
     $is_xml = 0;
     // possible parameter lists are either LibRDF_Node $resource or
     // string $value, $datatype=NULL, string $language=NULL
     $num_args = func_num_args();
     if ($num_args < 1 or $num_args > 3) {
         throw new LibRDF_Error("Invalid number of arguments");
     }
     $value = func_get_arg(0);
     if ($num_args >= 2) {
         $datatype = func_get_arg(1);
         if ($datatype) {
             $datatype = new LibRDF_URI($datatype);
         }
     } else {
         $datatype = NULL;
     }
     if ($num_args >= 3) {
         $language = func_get_arg(2);
     } else {
         $language = NULL;
     }
     if ($num_args == 1 and is_resource($value)) {
         if (!librdf_node_is_literal($value)) {
             throw new LibRDF_Error("Argument 1 not a valid librdf_node " . " literal node");
         } else {
             $this->node = $value;
         }
     } else {
         // value is XML, convert to a string and set the datatype
         if ($value instanceof DOMNodeList) {
             // XML values imply a datatype of
             // http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral, so
             // specifying a different datatype is an error
             if ($datatype !== NULL and $datatype->__toString() !== "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral") {
                 throw new LibRDF_Error("Cannot override datatype for XML literal");
             } else {
                 $datatype = NULL;
             }
             $valuestr = "";
             foreach ($value as $item) {
                 $valuestr .= $item->ownerDocument->saveXML($item);
             }
             $is_xml = 1;
         } else {
             $valuestr = (string) $value;
             $is_xml = 0;
         }
         if ($datatype !== NULL) {
             $datatype_uri = $datatype->getURI();
         } else {
             $datatype_uri = NULL;
         }
         if ($is_xml or $datatype === NULL and $language === NULL) {
             $this->node = librdf_new_node_from_literal(librdf_php_get_world(), $valuestr, $language, $is_xml);
         } else {
             $this->node = librdf_new_node_from_typed_literal(librdf_php_get_world(), $valuestr, $language, $datatype_uri);
         }
     }
     if (!$this->node) {
         throw new LibRDF_Error("Unable to create new literal node");
     }
 }
Exemplo n.º 11
0
 /**
  * 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");
     }
 }
Exemplo n.º 12
0
 /**
  * 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);
 }
Exemplo n.º 13
0
 /**
  * Creates a new storage backend.
  *
  * The storage methods available depends on the librdf configuration.
  * Methods always available are `memory', `hashes', `file' and `uri'.
  * Optional methods are `bdb', `mysql' and `sqllite'.  The default is
  * `memory'.
  *
  * The name argument is mandatory for storage methods that required a named
  * handle, such as file and URI.
  *
  *   <code>$stor = new LibRDF_Storage(storage_name="file", name="/tmp/filename");</code>
  *
  * The options string passes storage_name specific options to the chosen
  * backend and uses the following form:
  *
  *   <code>$stor = new LibRDF_Storage("storage_name", "name",
  *              "key1='value1', key2='value2', ...");</code>
  * 
  * Options values must be surrounded by single quotes for multiple
  * key/option pairs.
  *
  * The options common to all storage methods are:
  *    new - optional boolean (default false)
  *       If true, delete any existing store and create a new one, otherwise
  *       open an existing store.
  *    
  *    write - optional boolean (default true)
  *       If true, open the store in read-write mode.
  * 
  * For hashes:
  *    hash-type - the name of any supported hash type (default 'memory')
  *       'memory' and 'file' hash types are always present, and 'bdb'
  *       may be available depending on compile-time configuration of
  *       librdf.
  *    
  *    dir - (default '.') the directory in which to create files
  *
  *    mode - (default 0644) the octal file mode with which to create files
  *
  * @param   string  $storage_name   The type of storage to use
  * @param   string  $name           A name for the storage handle
  * @param   string  $options        Options for the storage backend
  * @return  void
  * @throws  LibRDF_Error            If unable to create a new storage
  * @access  public
  */
 public function __construct($storage_name = "memory", $name = NULL, $options = NULL)
 {
     $this->storage = librdf_new_storage(librdf_php_get_world(), $storage_name, $name, $options);
     if (!$this->storage) {
         throw new LibRDF_Error("Unable to create storage");
     }
 }