Class LibRDF_Model

Description

Implements interfaces:

  • Iterator (internal interface)

A wrapper around the librdf_model datatype.

A LibRDF_Model is a collection of LibRDF_Statement objects using a LibRDF_Storage object to save the statements. Statements are added using addStatement or through the use of a LibRDF_Parser and loadStatementsFromString or loadStatementsFromURI, and statements are removed using removeStatement. Statements can be queried through the use of either findStatements or a LibRDF_Query object. The statements can be written to a stream using LibRDF_Serializer and serializeStatements or serializeStatementsToFile.

This object is iterable. When used as part of a foreach statement, it will iterate over every statement contained in the model. For example,

  1. foreach ($model as $statement{
  2.     echo $statement;
  3.  }

will echo each statement individually. Unlike LibRDF_StreamIterator, the Model can be rewound and used for multiple iterations.

Located in /Model.php (line 103)


	
			
Method Summary
void __construct (LibRDF_Storage $storage, [string $options = NULL])
void __destruct ()
void addStatement (LibRDF_Statement $statement, [LibRDF_URINode $context = NULL])
LibRDF_StreamIterator findStatements (mixed $statement, LibRDF_Node $predicate, LibRDF_Node $target, LibRDF_URINode $context)
LibRDF_Node getArc (LibRDF_Node $source, LibRDF_Node $target)
resource getModel ()
boolean hasStatement (LibRDF_Statement $statement)
integer key ()
void loadStatementsFromString (LibRDF_Parser $parser, string $string, [string $base_uri = NULL])
void loadStatementsFromURI (LibRDF_Parser $parser, string $uri, [string $base_uri = NULL])
void next ()
void removeStatement (LibRDF_Statement $statement, [LibRDF_URINode $context = NULL])
void rewind ()
string serializeStatements (LibRDF_Serializer $serializer, [string $base_uri = NULL])
void serializeStatementsToFile (LibRDF_Serializer $serializer, string $file_name, [string $base_uri = NULL])
integer size ()
boolean valid ()
void __clone ()
string __toString ()
Methods
Constructor __construct (line 138)

Create a new librdf_model.

See the librdf documentation for information on the possible options.

  • access: public
  • throws: LibRDF_Error If unable to create a new model
void __construct (LibRDF_Storage $storage, [string $options = NULL])
  • LibRDF_Storage $storage: The storage on which this model should be built
  • string $options: Options to pass to librdf_new_model
Destructor __destruct (line 156)

Free a model's resources.

  • access: public
void __destruct ()
addStatement (line 224)

Add a statement to the model.

A statement can be added more than once by adding it under different contexts, otherwise adding a duplicate statement will have no effect. Not all models support contexts.

  • access: public
  • throws: LibRDF_Error If unable to add the statement
void addStatement (LibRDF_Statement $statement, [LibRDF_URINode $context = NULL])
current (line 508)

Return the current statement on the iterator.

  • return: The current statement
  • access: public
LibRDF_Statement current ()

Implementation of:
Iterator::current
findStatements (line 394)

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 LibRDF_Query.

  • return: An iterator over the matched statements
  • access: public
LibRDF_StreamIterator findStatements (mixed $statement, LibRDF_Node $predicate, LibRDF_Node $target, LibRDF_URINode $context)
  • mixed $statement: The statement to match or a source node
  • LibRDF_Node $predicate: The predicate to match
  • LibRDF_Node $target: The target to match
  • LibRDF_URINode $context: The context in which to search
getArc (line 320)

Return a single predicate node that is part of a statement containing the given source and target.

This function is equivalent to

  1. $model->findStatements($sourceNULL$target)->current()->getPredicate()

  • return: A node that matches the criteria
  • access: public
  • throws: LibRDF_LookupError If no statement with the given source and target is found
LibRDF_Node getArc (LibRDF_Node $source, LibRDF_Node $target)
  • LibRDF_Node $source: The source node for which to search
  • LibRDF_Node $target: The target node for which to search
getModel (line 206)

Return the model resource.

This function is intended for other LibRDF classes and should not be called.

  • return: The wrapped model resource
  • access: public
resource getModel ()
getSource (line 296)

Return a single source node that is part of a statement containing the given predicate and target.

This function is equivalent to

  1. $model->findStatements(NULL$predicate$target)->current()->getSubject()

  • return: A node that matches the criteria
  • access: public
  • throws: LibRDF_LookupError If no statement with the given predicate and target is found
LibRDF_Node getSource (LibRDF_Node $arc, LibRDF_Node $target)
  • LibRDF_Node $arc: The predicate node for which to search
  • LibRDF_Node $target: The target node for which to search
getTarget (line 344)

Return a single target node that is part of a statement containing the given source and predicate.

This function is equivalent to

  1. $model->findStatements($source$predicateNULL)->current()->getTarget()

  • return: A node that matches the criteria
  • access: public
  • throws: LibRDF_LookupError If no statement with the given source and predicate is found
LibRDF_Node getTarget (LibRDF_Node $source, LibRDF_Node $arc)
  • LibRDF_Node $source: The source node for which to search
  • LibRDF_Node $arc: The predicate node for which to search
hasStatement (line 362)

Test whether the model contains a statement.

  • return: Whether such a statement exists in the graph
  • access: public
boolean hasStatement (LibRDF_Statement $statement)
key (line 520)

Return the current iteration key.

  • return: The current key
  • access: public
integer key ()

Implementation of:
Iterator::key
loadStatementsFromString (line 563)

Load statements using a LibRDF_Parser.

If no $base_uri is given, the RDF namespace URI will be used as the base for relative URIs.

  • access: public
  • throws: LibRDF_Error If unable to parse the string
void loadStatementsFromString (LibRDF_Parser $parser, string $string, [string $base_uri = NULL])
  • LibRDF_Parser $parser: The parser with which to parse the string
  • string $string: The string to parse
  • string $base_uri: The base URI to use for relative URIs in the string
loadStatementsFromURI (line 590)

Load statements from a URI using a LibRDF_Parser.

  • access: public
  • throws: LibRDF_Error If unable to parse the URI contents
void loadStatementsFromURI (LibRDF_Parser $parser, string $uri, [string $base_uri = NULL])
  • LibRDF_Parser $parser: The parser with which to parse the URI's contents
  • string $uri: The URI with the contents to load
  • string $base_uri: The base URI to use for relative URIs if different from $uri
next (line 532)

Advance the iterator's position.

  • access: public
void next ()

Implementation of:
Iterator::next
removeStatement (line 255)

Remove a statement from the model.

  • access: public
  • throws: LibRDF_Error If unable to remove the statement
void removeStatement (LibRDF_Statement $statement, [LibRDF_URINode $context = NULL])
rewind (line 497)

Reset the statement iterator.

  • access: public
void rewind ()

Implementation of:
Iterator::rewind
serializeStatements (line 616)

Serialize the model as a string.

  • return: The model as a string
  • access: public
  • throws: LibRDF_Error If unable to serialize the model
string serializeStatements (LibRDF_Serializer $serializer, [string $base_uri = NULL])
  • LibRDF_Serializer $serializer: The serializer to use
  • string $base_uri: The base URI to use if relative URIs are desired
serializeStatementsToFile (line 643)

Serialize the model and write the contents to a file.

  • access: public
  • throws: LibRDF_Error If unable to serialize the model
void serializeStatementsToFile (LibRDF_Serializer $serializer, string $file_name, [string $base_uri = NULL])
  • LibRDF_Serializer $serializer: The serializer to use
  • string $file_name: The name of the file to which to write
  • string $base_uri: The base URI to use
size (line 278)

Return the number of statements in the model.

  • return: The number of statements
  • access: public
integer size ()
valid (line 544)

Check whether the statement iterator is still valid.

  • return: Whether the iterator is still valid
  • access: public
boolean valid ()

Implementation of:
Iterator::valid
__clone (line 188)

Create a copy of the model.

Whether a model can be copied depends upon the underlying model factory. In-memory storages cannot be cloned, so a clone of models using this form of storage will fail.

  • access: public
  • throws: LibRDF_Error If unable to copy the model
void __clone ()
__toString (line 172)

Return a string representation of the model.

This function can be used as a lazy form of serializtion. Use a LibRDF_Serializer if you care about the format of the output.

  • return: The model as a string
  • access: public
string __toString ()

Documentation generated on Thu, 15 Jun 2006 19:25:12 -0400 by phpDocumentor 1.3.0