[ Expand All ] [ Collapse All ] - [ Properties (4) ] [ Methods (46) ] - [ Legend ]

MemModel Class v. V0.9.1

Object
Model
MemModel

Class: MemModel ----------------------------------------------------------------------------------

A MemModel is an RDF Model, which is stored in the main memory. This class provides methods for manipulating MemModels.

<BR><BR>History:<UL> <LI>12-06-2004 : improved namespace handling added ( tobias.gauss@web.de )</LI> <LI>10-07-2004 : Function findFirstMatchingStatement() added paramter $offset to set an search offset <LI>09-09-2004 : Function remove() bug removed: now removes ALL matching statements. Function addWithoutDuplicates() now uses the contains() / add() functions. Functions reify(),addModel(),unite(),subtract() changed to use the statement iterator.</LI> <LI>16-08-2004 : Function getUniqueResourceURI() has been made faster</LI> <LI>08-06-2004 : Function findAsIterator() added</LI> <LI>06-13-2004 : Improved function index() which allows the definition of different search indexes</LI> <LI>03-29-2004 : Function addModel() fixed, reindexing of triples in remove() added</LI> <LI>11-13-2003 : Functions load, saveAs moved to class model <LI>11-12-2003 : Function rdqlQueryAsIterator() added.</LI> <LI>07-31-2003 : Class renamed from Model to MemModel. Variable BaseURI and Function getBaseURI() moved to Model. Functions containsAll(), containsAny(), equals(), unite(), subtract(), intersect(), addModel() can now get DbModel as paramter. Functions load() and saveAs() can now work with n3 format too. Function rdqlQuery added. radol@gmx.de </LI> <LI>05-31-2003 : Functions load(), saveAs() and writeXX() findFirstMatchingStatement() added. Changed function index() to a faster index type.</LI> <LI>05-28-2003 : Functions addWithoutDuplicates() and addModel() added, optimised bits and pieces.</LI> <LI>05-19-2003 : Function add() made more efficient, optimised bits and pieces. ggrimnes@csd.abdn.ac.uk </LI> <LI>05-19-2003 : Functions index() and isIndexed() added, ggrimnes@csd.abdn.ac.uk </LI> <LI>02-21-2003 : Function findCount() added.</LI> <LI>01-13-2003 : Function equals() made more efficient.</LI> <LI>09-10-2002 : First version of this class.</LI>

AuthorsChris Bizer, Gunnar AAstrand Grimnes, Radoslaw Oldakowski, Daniel Westphal, Tobias Gauß
Properties implemented by MemModel
private method indexArr

Array containing the search indices

private method indexed

depending on which index is used this variable is -1,0,1,2 or 3

-1 : no index 0 : default indices over subject, predicate, object separate 1 : index over subject+predicate+object 2 : index over subject+predicate 3 : index over subject+object

private method parsedNamespaces

Array of namespaces

private method triples

Triples of the MemModel

Methods implemented by MemModel
private method _containsIndex

PHPboolean _containsIndex(unknown $statement, integer $ind)

============================================================================= *************************** helper functions ******************************** =============================================================================

Checks if $statement is in index

Arguments

private method _findInIndex

PHPmemmodel _findInIndex(string $pos, unknown $subject, unknown $predicate, unknown $object, unknown $ind)

finds a statement in an index. $pos is the Position in the index and $ind the adequate searchindex

Arguments

Return

$res

private method _findMatchIndex

PHPinteger _findMatchIndex(unknown $pos, unknown $s, unknown $p, unknown $o, unknown $ind, unknown $off)

finds next or previous matching statement. Returns Position in model or -1 if there is no match.

Arguments

private method _indexOpr

PHPinteger _indexOpr(unknown $statement, integer $k, integer $ind, integer $mode)

adds/removes a statement into/from an index. mode=0 removes the statement from the index; mode=1 adds the statement into the index. returns the statements position.

Arguments

Return

$k

public method add

PHPadd(unknown $statement)

Adds a new triple to the MemModel without checking if the statement is already in the MemModel. So if you want a duplicate free MemModel use the addWithoutDuplicates() function (which is slower then add())

Arguments

public method addModel

PHPaddModel(unknown $model)

Adds another model to this MemModel. Duplicate statements are not removed. If you don't want duplicates, use unite(). 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.

Arguments

public method addNamespace

PHPaddNamespace(string $prefix, unknown $nmsp)

Adds a namespace and prefix to the model.

AuthorTobias Gauß

Arguments

public method addParsedNamespaces

PHPaddParsedNamespaces(array $newNs)

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

AuthorTobias Gauß

Arguments

public method addWithoutDuplicates

PHPboolean addWithoutDuplicates(unknown $statement)

Checks if a new statement is already in the MemModel and adds the statement, if it is not in the MemModel. addWithoutDuplicates() is significantly slower then add(). Retruns TRUE if the statement is added. FALSE otherwise.

Arguments

public method close

PHPclose()

Close the MemModel and free up resources held.

public method contains

PHPboolean contains(unknown $statement)

Tests if the MemModel contains the given triple. TRUE if the triple belongs to the MemModel; FALSE otherwise.

Arguments

public method containsAll

PHPboolean containsAll(unknown $model)

Determine if all of the statements in a model are also contained in this MemModel. True if all of the statements in $model are also contained in this MemModel and false otherwise.

Arguments

public method containsAny

PHPboolean containsAny(unknown $model)

Determine if any of the statements in a model are also contained in this MemModel. True if any of the statements in $model are also contained in this MemModel and false otherwise.

Arguments

public method equals

PHPboolean equals(unknown $that)

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

Arguments

public method find

PHPobject find(unknown $subject, unknown $predicate, unknown $object)

General method to search for triples. NULL input for any parameter will match anything. Example: $result = $m->find( NULL, NULL, $node ); Finds all triples with $node as object. Returns an empty MemModel if nothing is found.

Arguments

Return

MemModel

public method findAsIterator

PHPobject findAsIterator(unknown $sub, unknown $pred, unknown $obj)

Returns a FindIterator for traversing the MemModel.

Arguments

Return

FindIterator

public method findCount

PHPinteger findCount(unknown $subject, unknown $predicate, unknown $object)

Searches for triples and returns the number of matches. NULL input for any parameter will match anything. Example: $result = $m->findCount( NULL, NULL, $node ); Finds all triples with $node as object.

Arguments

public method findFirstMatchingStatement

PHPobject findFirstMatchingStatement(unknown $subject, unknown $predicate, unknown $object, integer $offset)

Searches for triples and returns the first matching statement. NULL input for any parameter will match anything. Example: $result = $m->findFirstMatchingStatement( NULL, NULL, $node ); Returns the first statement of the MemModel where the object equals $node. Returns an NULL if nothing is found. You can define an offset to search for. Default = 0

Arguments

Return

Statement

private method findFirstMatchOff

PHPinteger findFirstMatchOff(unknown $subject, unknown $predicate, unknown $object, integer $off)

Searches for triples and returns the first matching statement from a given offset. This method is used by the util/findIterator. NULL input for any parameter will match anything. Example: $result = $m->findFirstMatchingStatement( NULL, NULL, $node, $off ); Returns the position of the first statement of the MemModel where the object equals $node from the given offset. Returns an -1 if nothing is found.

Arguments

public method findRegex

PHPobject findRegex(string $subject_regex, string $predicate_regex, string $object_regex)

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. Returns an empty MemModel if nothing is found.

Arguments

Return

MemModel

public method findVocabulary

PHPobject findVocabulary(string $vocabulary)

Returns 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 # Returns an empty MemModel if nothing is found.

Arguments

Return

MemModel

public method getIndexType

PHPinteger getIndexType()

Returns the indextype: -1 if there is no index, 0 if there are indices over S,P,O(separate), 1 if there is an index over SPO, 2 if there is an index over SP and 3 if there is an index over SO.

public method getParsedNamespaces

PHParray getParsedNamespaces()

Returns the models namespaces.

AuthorTobias Gauß
public method getStatementIterator

PHPobject getStatementIterator()

Returns a StatementIterator for traversing the MemModel.

Return

StatementIterator

public method index

PHPindex(integer $mode)

Builds a search index for the statements in the MemModel. The index is used by the find(),contains(),add() and remove() functions. Performance example using a model with 43000 statements on a Linux machine: Find without index takes 1.7 seconds. Indexing takes 1.8 seconds. Find with index takes 0.001 seconds. So if you want to query a model more then once, build a index first. The defaultindex is indices over subject, predicate, object seperate.

mode = 0 : indices over subject,predicate,object (default) mode = 1 : index over subject+predicate+object mode = 2 : index over subject+predicate mode = 3 : index over subject+object

Arguments

public method intersect

PHPobject intersect(unknown $model)

Returns a new MemModel containing all the statements which are in both this MemModel and another.

Arguments

Return

MemModel

public method isEmpty

PHPboolean isEmpty()

Checks if MemModel is empty

public method isIndexed

PHPboolean isIndexed()

Returns true if there is an index, false if not.

private method matchStatement

PHPboolean matchStatement(unknown $statement, unknown $subject, unknown $predicate, unknown $object)

Internal method that checks, if a statement matches a S, P, O or NULL combination. NULL input for any parameter will match anything.

Arguments

constructor MemModel

PHPMemModel(string $baseURI)

Constructor You can supply a base_uri

Arguments

public method rdqlQuery

PHParray rdqlQuery(string $queryString, boolean $returnNodes)

Perform an RDQL query on this MemModel. 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.

Arguments

Return

[][?VARNAME] = object Node (if $returnNodes = TRUE) OR array [][?VARNAME] = string

public method rdqlQueryAsIterator

PHPobject rdqlQueryAsIterator(string $queryString, boolean $returnNodes)

Perform an RDQL query on this MemModel. 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.

Arguments

Return

RdqlResultIterator = with values as object Node (if $returnNodes = TRUE) OR object RdqlResultIterator = with values as strings if (if $returnNodes = FALSE)

public method reify

PHPobject reify()

Reifies the MemModel. Returns a new MemModel that contains the reifications of all statements of this MemModel.

Return

MemModel

public method remove

PHPboolean remove(unknown $statement)

Removes the triple from the MemModel. TRUE if the triple is removed. FALSE otherwise.

Arguments

public method removeNamespace

PHPremoveNamespace(string $nmsp)

removes a single namespace from the model

AuthorTobias Gauß

Arguments

public method replace

PHPreplace(unknown $subject, unknown $predicate, unknown $object, unknown $replacement)

General method to replace nodes of a MemModel. NULL input for any parameter will match nothing. Example: $m->replace($node, NULL, $node, $replacement); Replaces all $node objects beeing subject or object in any triple of the MemModel with the $needle node.

Arguments

public method saveAs

PHPboolean saveAs(string $filename, string $type)

Saves the RDF,N3 or N-Triple serialization of the MemModel 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 MemModel couldn't be saved to the file.

Arguments

public method setBaseURI

PHPsetBaseURI(string $uri)

Set a base URI for the MemModel. Affects creating of new resources and serialization syntax. If the URI doesn't end with # : or /, then a # is added to the URI.

Arguments

public method size

PHPinteger size()

Number of triples in the MemModel

public method subtract

PHPobject subtract(unknown $model)

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

Arguments

Return

MemModel

public method toString

PHPstring toString()

Short Dump of the MemModel.

public method toStringIncludingTriples

PHPstring toStringIncludingTriples()

Dumps of the MemModel including all triples.

public method unite

PHPobject unite(unknown $model)

Returns a new MemModel that is the set-union of the MemModel with another model. Duplicate statements are removed. If you want to allow duplicates, use addModel() which is much faster.

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

Arguments

Return

MemModel

public method writeAsHtml

PHPwriteAsHtml()

Writes the RDF serialization of the MemModel as HTML.

public method writeAsHtmlTable

PHPwriteAsHtmlTable()

Writes the RDF serialization of the MemModel as HTML table.

public method writeRdfToString

PHPstring writeRdfToString()

Writes the RDF serialization of the MemModel as HTML table.

Generated by PHPEdit - Copyright © 1999-2004 - Sébastien Hordeaux - WaterProof SARL