Class DbModel

Description

This class provides methods for manipulating DbModels from DbStore.

A DbModel is an RDF Model, which is persistently stored in a relational database. This Class uses the ADOdb Database Abstraction Library for PHP (http://adodb.sourceforge.net/).

  • author: Radoslaw Oldakowski <radol@gmx.de>
  • version: $Id: DbModel.html 443 2007-06-01 16:25:38Z cax $
  • access: public

Located in /model/DbModel.php (line 22)

Object
   |
   --Model
      |
      --DbModel
Direct descendents
Class Description
NamedGraphDb Persistent NamedGraph implementation that extends a DbModel.
Method Summary
DbModel DbModel (object ADOConnection &$dbConnection, string $modelURI, string $modelID, [string $baseURI = NULL])
mixed add (object Statement &$statement)
void addModel ( &$model, object Model $model)
void addNamespace ( $prefix,  $nmsp, String $prefix,)
void addParsedNamespaces (Array $newNs)
void close ()
boolean contains (object Statement &$statement)
boolean containsAll (object Model &$model)
boolean containsAny (object Model &$model)
void delete ()
boolean equals (object model &$that)
object MemModel find (object Resource $subject, object Resource $predicate, object Node $object)
integer findCount (object Resource $subject, object Resource $predicate, object Node $object)
object Statement findFirstMatchingStatement (object Resource $subject, object Resource $predicate, object Node $object, [integer $offset = -1])
object MemModel findRegex (string $subject_regex, string $predicate_regex, string $object_regex)
object MemModel findVocabulary (string $vocabulary)
ADOdb &getDbConn ()
int getModelID ()
object MemModel &intersect ( &$model, object Model $model)
boolean isEmpty ()
object FindIterator &iterFind ([ $sub = null], [ $pred = null], [ $obj = null])
array rdqlQuery (string $queryString, [boolean $returnNodes = TRUE])
object RdqlResultIterator rdqlQueryAsIterator (string $queryString, [boolean $returnNodes = TRUE])
void remove (object Statement &$statement)
void removeNamespace (String $nmsp)
void replace (object Resource $subject, object Resource $predicate, object Node $object, object Node $replacement)
boolean saveAs (string $filename, [string $type = 'rdf'])
void setBaseURI (string $uri)
integer size ()
object MemModel &subtract ( &$model, object Model $model)
string toString ()
object MemModel &unite ( &$model, object Model $model)
void writeAsHtml ()
string writeRdfToString ()
Variables

Inherited Variables

Inherited from Model

Model::$queryParser
Methods
Constructor DbModel (line 65)

Constructor Do not call this directly.

Use the method getModel,getNewModel or putModel of the Class DbStore instead.

  • access: public
DbModel DbModel (object ADOConnection &$dbConnection, string $modelURI, string $modelID, [string $baseURI = NULL])
  • object ADOConnection &$dbConnection
  • string $modelURI
  • string $modelID
  • string $baseURI
add (line 131)

Add a new triple to this DbModel.

  • return: true on success, false if the statement is already in the model, error message (string) on failure
  • throws: SqlError
  • throws: PhpError
  • access: public
mixed add (object Statement &$statement)
addModel (line 881)

Add the given model to this DbModel.

This function monitors for SQL errors, and will commit if no errors have occured, otherwise it will rollback. If any statement of the model to be added to this model contains a blankNode with an identifier already existing in this model, a new blankNode is generated.

  • throws: PhpError
  • access: public
void addModel ( &$model, object Model $model)
addNamespace (line 1194)

Adds a namespace and prefix to the model.

void addNamespace ( $prefix,  $nmsp, String $prefix,)
  • String $prefix,: String $nmsp
  • $prefix
  • $nmsp
addParsedNamespaces (line 1179)

Adds the namespaces to the model. This method is called by the parser. !!!! addParsedNamespaces() not overwrites manual added namespaces in the model !!!!

void addParsedNamespaces (Array $newNs)
  • Array $newNs
addWithoutDuplicates (line 183)

Alias for the method add().

  • throws: SqlError
  • throws: PhpError
  • access: public
void addWithoutDuplicates (object Statement &$statement)
close (line 953)

Close this DbModel

  • access: public
void close ()
contains (line 345)

Check if the DbModel contains the given statement.

  • access: public
boolean contains (object Statement &$statement)
containsAll (line 366)

Determine if all of the statements in the given model are also contained in this DbModel.

  • access: public
boolean containsAll (object Model &$model)
containsAny (line 399)

Determine if any of the statements in the given model are also contained in this DbModel.

  • access: public
boolean containsAny (object Model &$model)
delete (line 933)

Remove this DbModel from database and clean up.

This function monitors for SQL errors, and will commit if no errors have occured, otherwise it will rollback.

  • throws: SqlError
  • access: public
void delete ()
equals (line 747)

Check if two models are equal.

Two models are equal if and only if the two RDF graphs they represent are isomorphic.

Warning: This method doesn't work correct with models where the same blank node has different identifiers in the two models. We will correct this in a future version.

  • throws: PhpError
  • access: public
boolean equals (object model &$that)
  • object model &$that
find (line 439)

General method to search for triples in the DbModel.

NULL input for any parameter will match anything. Example: $result = $m->find( NULL, NULL, $node ); Finds all triples with $node as object.

  • throws: SqlError
  • throws: PhpError
  • access: public
object MemModel find (object Resource $subject, object Resource $predicate, object Node $object)
findCount (line 588)

Search for triples and return the number of matches.

NULL input for any parameter will match anything.

  • throws: SqlError
  • throws: PhpError
  • access: public
integer findCount (object Resource $subject, object Resource $predicate, object Node $object)
findFirstMatchingStatement (line 542)

Search for triples and return the first matching statement.

NULL input for any parameter will match anything. Return an NULL if nothing is found. You can set an search offset with $offset.

  • throws: SqlError
  • throws: PhpError
  • access: public
object Statement findFirstMatchingStatement (object Resource $subject, object Resource $predicate, object Node $object, [integer $offset = -1])
findRegex (line 489)

Method to search for triples using Perl-style regular expressions.

NULL input for any parameter will match anything. Example: $result = $m->find_regex( NULL, NULL, $regex ); Finds all triples where the label of the object node matches the regular expression. Return an empty MemModel if nothing is found. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING: Mhis method loads a DbModel into memory and performs the search on a MemModel, which can be slow with large models. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • throws: SqlError
  • throws: PhpError
  • access: public
object MemModel findRegex (string $subject_regex, string $predicate_regex, string $object_regex)
  • string $subject_regex
  • string $predicate_regex
  • string $object_regex
findVocabulary (line 509)

Return all tripels of a certain vocabulary.

$vocabulary is the namespace of the vocabulary inluding a # : / char at the end. e.g. http://www.w3.org/2000/01/rdf-schema# Return an empty model if nothing is found.

  • throws: SqlError
  • throws: PhpError
  • access: public
object MemModel findVocabulary (string $vocabulary)
  • string $vocabulary
getDbConn (line 273)

Returns the database connection object

  • return: Database object
  • access: public
ADOdb &getDbConn ()
getMemModel (line 246)

Create a MemModel containing all the triples of the current DbModel.

  • access: public
object MemModel &getMemModel ()
getModelID (line 260)

Returns the model id

  • return: Model id number
  • access: public
int getModelID ()
getParsedNamespaces (line 1154)

Returns the models namespaces.

Array getParsedNamespaces ()
intersect (line 850)

Return a new MemModel containing all the statements which are in both this model and the given model.

  • throws: PhpError
  • access: public
object MemModel &intersect ( &$model, object Model $model)
isEmpty (line 113)

Check if this DbModel is empty.

  • access: public
boolean isEmpty ()
iterFind (line 1244)

Returns a FindIterator for traversing the MemModel.

  • access: public
object FindIterator &iterFind ([ $sub = null], [ $pred = null], [ $obj = null])
  • $sub
  • $pred
  • $obj
rdqlQuery (line 629)

Perform an RDQL query on this DbModel.

This method returns an associative array of variable bindings. The values of the query variables can either be RAP's objects (instances of Node) if $returnNodes set to TRUE, or their string serialization.

  • return: [][?VARNAME] = object Node (if $returnNodes = TRUE) OR array [][?VARNAME] = string
  • access: public
array rdqlQuery (string $queryString, [boolean $returnNodes = TRUE])
  • string $queryString
  • boolean $returnNodes
rdqlQueryAsIterator (line 663)

Perform an RDQL query on this DBModel.

This method returns an RdqlResultIterator of variable bindings. The values of the query variables can either be RAP's objects (instances of Node) if $returnNodes set to TRUE, or their string serialization.

  • return: = with values as object Node (if $returnNodes = TRUE) OR object RdqlResultIterator = with values as strings if (if $returnNodes = FALSE)
  • access: public
object RdqlResultIterator rdqlQueryAsIterator (string $queryString, [boolean $returnNodes = TRUE])
  • string $queryString
  • boolean $returnNodes
reify (line 919)

Reify the DbModel.

Return a new MemModel that contains the reifications of all statements of this DbModel.

  • access: public
object MemModel &reify ()
remove (line 197)

Remove the given triple from this DbModel.

  • throws: SqlError
  • throws: PhpError
  • access: public
void remove (object Statement &$statement)
removeNamespace (line 1259)

removes a single namespace from the model

void removeNamespace (String $nmsp)
  • String $nmsp
replace (line 684)

General method to replace nodes of a DbModel.

NULL input for any parameter will match nothing. Example: $m->replace($resource, NULL, $node, $replacement); Replaces all $node objects beeing subject or object in any triple of the model with the $replacement node. Throw an error in case of a paramter mismatch.

  • throws: SqlError
  • throws: PhpError
  • access: public
void replace (object Resource $subject, object Resource $predicate, object Node $object, object Node $replacement)
saveAs (line 330)

Saves the RDF,N3 or N-Triple serialization of the DbModel to a file.

You can decide to which format the model should be serialized by using a corresponding suffix-string as $type parameter. If no $type parameter is placed this method will serialize the model to XML/RDF format. Returns FALSE if the DbModel couldn't be saved to the file.

  • throws: PhpError
  • access: public
boolean saveAs (string $filename, [string $type = 'rdf'])
  • string $filename
  • string $type
setBaseURI (line 82)

Set a base URI for the DbModel.

Affects creating of new resources and serialization syntax.

  • throws: SqlError
  • access: public
void setBaseURI (string $uri)
  • string $uri
size (line 99)

Return the number of statements in this DbModel.

  • access: public
integer size ()
subtract (line 819)

Return a new MemModel that is the subtraction of another model from this DbModel.

  • throws: PhpError
  • access: public
object MemModel &subtract ( &$model, object Model $model)
toString (line 220)

Short dump of the DbModel.

  • access: public
string toString ()

Redefinition of:
Object::toString()
Serializes a object into a string
toStringIncludingTriples (line 232)

Dump of the DbModel including all triples.

  • access: public
string toStringIncludingTriples ()
unite (line 788)

Return a new MemModel that is the set-union the model with another model.

The result of taking the set-union of two or more RDF graphs (i.e. sets of triples) is another graph, which we will call the merge of the graphs. Each of the original graphs is a subgraph of the merged graph. Notice that when forming a merged graph, two occurrences of a given uriref or literal as nodes in two different graphs become a single node in the union graph (since by definition they are the same uriref or literal) but blank nodes are not 'merged' in this way; and arcs are of course never merged. In particular, this means that every blank node in a merged graph can be identified as coming from one particular graph in the original set of graphs.

Notice that one does not, in general, obtain the merge of a set of graphs by concatenating their corresponding N-triples documents and constructing the graph described by the merged document, since if some of the documents use the same node identifiers, the merged document will describe a graph in which some of the blank nodes have been 'accidentally' merged. To merge Ntriples documents it is necessary to check if the same nodeID is used in two or more documents, and to replace it with a distinct nodeID in each of them, before merging the documents. (Not implemented yet !!!!!!!!!!!)

  • throws: PhpError
  • access: public
object MemModel &unite ( &$model, object Model $model)
writeAsHtml (line 285)

Write the RDF serialization of the _DbModel as HTML.

  • access: public
void writeAsHtml ()
writeAsHtmlTable (line 297)

Write the RDF serialization of the DbModel as HTML table.

  • access: public
void writeAsHtmlTable ()
writeRdfToString (line 310)

Write the RDF serialization of the DbModel to string.

  • access: public
string writeRdfToString ()

Inherited Methods

Inherited From Model

Model::Model()
Model::findForward()
Model::getBaseURI()
Model::getMemModelByRDQL()
Model::getOntModel()
Model::getResModel()
Model::load()
Model::sparqlPrepare()
Model::sparqlQuery()
Model::visualize()
Model::_parseSparqlQuery()
Model::_prepareSparql()

Inherited From Object

Object::toString()

Documentation generated on Fri, 1 Jun 2007 16:48:48 +0200 by phpDocumentor 1.3.2