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/).

  • access: public
  • author: Radoslaw Oldakowski <radol@gmx.de>
  • version: $Id: DbModel.html,v 1.15 2006/06/26 12:34:20 tgauss Exp $

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

Object
   |
   --Model
      |
      --DbModel
Direct descendents
Class Description
NamedGraphDb Persistent NamedGraph implementation that extends a DbModel.
Variable Summary
object ADOConnection $dbConn
string $modelID
string $modelURI
Method Summary
DbModel DbModel (object ADOConnection &$dbConnection, string $modelURI, string $modelID, [string $baseURI = NULL])
void 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)
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 ()
string _checkBaseURI (string $uri)
void _checkNamespace ( $nmsp, Array $newNs)
boolean _containsRow (array $row)
string _createDynSqlPart_SPO (object Resource $subject, object Resource $predicate, object Node $object)
string _getNodeFlag (object Node $object)
object ADORecordSet _getRecordSet ( &$dbModel, object DbModel $DbModel)
Variables
object ADOConnection $dbConn (line 29)

Database connection object.

  • access: private
string $modelID (line 48)

Database internal modelID.

Used to avoid JOINs.

  • access: private
string $modelURI (line 38)

Unique model URI.

Used to identify the DbModel.

  • access: private

Inherited Variables

Inherited from Model

Model::$baseURI
Model::$bNodeCount
Methods
Constructor DbModel (line 64)

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 128)

Add a new triple to this DbModel.

  • access: public
  • throws: PhpError
  • throws: SqlError
void add (object Statement &$statement)
addModel (line 844)

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.

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

Adds a namespace and prefix to the model.

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

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 173)

Alias for the method add().

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

Close this DbModel

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

Check if the DbModel contains the given statement.

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

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 362)

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 896)

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.

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

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.

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

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.

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

Search for triples and return the number of matches.

NULL input for any parameter will match anything.

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

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.

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

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

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

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.

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

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

  • access: public
object MemModel &getMemModel ()
getParsedNamespaces (line 1117)

Returns the models namespaces.

Array getParsedNamespaces ()
intersect (line 813)

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

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

Check if this DbModel is empty.

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

Returns a FindIterator for traversing the MemModel.

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

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 626)

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 882)

Reify the DbModel.

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

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

Remove the given triple from this DbModel.

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

removes a single namespace from the model

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

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.

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

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 81)

Set a base URI for the DbModel.

Affects creating of new resources and serialization syntax.

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

Return the number of statements in this DbModel.

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

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

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

Short dump of the DbModel.

  • access: public
string toString ()

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

Dump of the DbModel including all triples.

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

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 !!!!!!!!!!!)

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

Write the RDF serialization of the _DbModel as HTML.

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

Write the RDF serialization of the DbModel as HTML table.

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

Write the RDF serialization of the DbModel to string.

  • access: public
string writeRdfToString ()
_checkBaseURI (line 938)

If the URI doesn't end with # : or /, then a # is added to the URI.

Used at setting the baseURI of this DbModel.

  • access: private
string _checkBaseURI (string $uri)
  • string $uri
_checkNamespace (line 1183)

checks if a namespace is already in the model.

void _checkNamespace ( $nmsp, Array $newNs)
  • Array $newNs
  • $nmsp
_containsRow (line 1086)

Check if this DbModel contains the given row from the array fields[] of an ADORecordSet

The array index corresponds to following table columns: [0] - subject, [1] - predicate, [2] - object, [3] - l_language, [4] - l_datatype, [5] - subject_is, [6] - object_is

  • access: private
boolean _containsRow (array $row)
  • array $row
_convertRecordSetToMemModel (line 980)

Convert an ADORecordSet to a memory Model.

Every successful database query returns an ADORecordSet object which is actually a cursor that holds the current row in the array fields[]. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!! This method can only be applied to a RecordSet with array fields[] !!! containing a representation of the database table: statements, !!! with an index corresponding to following table columns: !!! [0] - subject, [1] - predicate, [2] - object, [3] - l_language, !!! [4] - l_datatype, [5] - subject_is, [6] - object_is !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • access: private
object MemModel _convertRecordSetToMemModel (mixed &$recordSet)
_createDynSqlPart_SPO (line 1025)

Create the dynamic part of an sql statement selecting triples with the given parameters ($subject, $predicate, $object).

  • access: private
string _createDynSqlPart_SPO (object Resource $subject, object Resource $predicate, object Node $object)
_getNodeFlag (line 957)

' Return the flag of the Node object.

r - Resource, b - BlankNode, l - Literal

  • access: private
string _getNodeFlag (object Node $object)
_getRecordSet (line 1066)

Get an ADORecordSet with array fields[] containing a representation of

the given DbModel stored in the table: statements, with an index corresponding to following table columns: [0] - subject, [1] - predicate, [2] - object, [3] - l_language, [4] - l_datatype, [5] - subject_is, [6] - object_is (This method operates on data from a DbModel without loading it into a memory model in order to save resources and improve speed).

  • access: private
object ADORecordSet _getRecordSet ( &$dbModel, object DbModel $DbModel)

Inherited Methods

Inherited From Model

Model::Model()
Model::findForward()
Model::getBaseURI()
Model::getMemModelByRDQL()
Model::getOntModel()
Model::getResModel()
Model::getUniqueResourceURI()
Model::load()
Model::sparqlQuery()
Model::visualize()
Model::_addStatementFromAnotherModel()

Inherited From Object

Object::toString()

Documentation generated on Mon, 26 Jun 2006 14:25:23 +0200 by phpDocumentor 1.3.0RC6