Source for file InfModel.php
Documentation is available at InfModel.php
// ----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------
* A InfModel Model extends a MemModel , by adding the ability to infer statements from
* known statements and RDFS/OWL-Schematas.
* It uses the same interface as MemModel, thus making the
* infererence process hidden.
* @version $Id: fsource_infModel__infModelInfModel.php.html,v 1.10 2006/06/26 12:34:12 tgauss Exp $
* @author Daniel Westphal <mail at d-westphal dot de>
* Array that holds the objects of the class Infrule,
* which were assigned by the _addToInference() function
* Array of URI-Strings that produces Infrules.
* Array of the connection between the infrules and the statement
* that assigned those rules.
* array[2][3]=true;array[2][5]=true means, that statement 2
* assigned rule 3 & 5 to the model.
* Array of the infRule triggers and the matching infrules.
* $this->infRulesTriggerIndex['s'] for subject index, ['p'] for predicates,
* Array of the infRule entailments and the matching infrules.
* $this->infRulesEntailIndex['s'] for subject index, ['p'] for predicates,
* You can supply a base_uri
//call the memmodel constructor method
//arraylist of predicate labels that shall add inference rules
//The constants, wich statements will create rules can be configured in constants.php
if (INF_RES_SUBPROPERTYOF)
if (INF_RES_OWL_INVERSEOF)
$infRule->setTrigger(null,new Resource(RDF_NAMESPACE_URI.
RDF_TYPE),new Resource(RDF_SCHEMA_URI.
'ContainerMembershipProperty'));
$infRule->setEntailment('<s>',new Resource(RDF_SCHEMA_URI.
RDFS_SUBPROPERTYOF),new Resource(RDF_SCHEMA_URI.
'member'));
$infRule->setTrigger(null,new Resource(RDF_NAMESPACE_URI.
RDF_TYPE),new Resource(RDF_NAMESPACE_URI.
RDF_PROPERTY));
$infRule->setEntailment('<s>',new Resource(RDF_SCHEMA_URI.
RDFS_SUBPROPERTYOF),'<s>');
$infRule->setTrigger(null,new Resource(RDF_NAMESPACE_URI.
RDF_TYPE),new Resource(RDF_SCHEMA_URI.
RDFS_CLASS));
$infRule->setEntailment('<s>',new Resource(RDF_SCHEMA_URI.
RDFS_SUBCLASSOF),new Resource(RDF_SCHEMA_URI.
RDFS_RESOURCE));
$infRule->setTrigger(null,new Resource(RDF_NAMESPACE_URI.
RDF_TYPE),new Resource(RDF_SCHEMA_URI.
RDFS_CLASS));
$infRule->setEntailment('<s>',new Resource(RDF_SCHEMA_URI.
RDFS_SUBCLASSOF),'<s>');
$infRule->setTrigger(null,new Resource(RDF_NAMESPACE_URI.
RDF_TYPE),new Resource(RDF_SCHEMA_URI.
RDFS_DATATYPE));
$infRule->setEntailment('<s>',new Resource(RDF_SCHEMA_URI.
RDFS_SUBCLASSOF),new Resource(RDF_SCHEMA_URI.
RDFS_LITERAL));
* Adds a new triple to the Model without checking if the statement
* is already in the Model.
* So if you want a duplicate free MemModel use the addWithoutDuplicates()
* function (which is slower then add())
* If the statement's predicate label is supported by the inference,
* the matching rules are added.
* @param object Statement $statement
//if the predicate is supported by the inference
* This function analyses the statement's predicate and adds the
* matching infrule to the model.
* @param object Statement $statement
$predicateLabel=
$statement->getLabelPredicate();
//get the position of the the statement in the model
case RDF_SCHEMA_URI.
RDFS_SUBPROPERTYOF :
//set the trigger to match all statements, having a
//predicate, that matches the subject of the statement that
$infRule->setTrigger(null,$statement->getSubject(),null);
//set the infrule to return a statement, having the same
//subject and object as the statement, that asked for an
//entailment, and having the object of the statement,
//that created this rule as predicate.
$infRule->setEntailment('<s>',$statement->getObject(),'<o>');
//add the infule to Model, Statement/Rule-Index,
//and Rule/Trigger (or Rule/Entailment) index
case RDF_SCHEMA_URI.
RDFS_SUBCLASSOF :
$infRule->setTrigger(null,new Resource(RDF_NAMESPACE_URI.
RDF_TYPE),$statement->getSubject());
$infRule->setEntailment('<s>',new Resource(RDF_NAMESPACE_URI.
RDF_TYPE),$statement->getObject());
case RDF_SCHEMA_URI.
RDFS_DOMAIN :
$infRule->setTrigger(null,$statement->getSubject(),null);
$infRule->setEntailment('<s>',new Resource(RDF_NAMESPACE_URI.
RDF_TYPE),$statement->getObject());
case RDF_SCHEMA_URI.
RDFS_RANGE :
$infRule->setTrigger(null,$statement->getSubject(),null);
$infRule->setEntailment('<o>',new Resource(RDF_NAMESPACE_URI.
RDF_TYPE),$statement->getObject());
case OWL_URI.
OWL_INVERSE_OF :
$infRule->setTrigger(null,$statement->getSubject(),null);
$infRule->setEntailment('<o>',$statement->getObject(),'<s>');
$infRule->setTrigger(null,$statement->getObject(),null);
$infRule->setEntailment('<o>',$statement->getSubject(),'<s>');
case OWL_URI.
OWL_SAME_AS :
$infRule->setTrigger($statement->getSubject(),null,null);
$infRule->setEntailment($statement->getObject(),'<p>','<o>');
$infRule->setTrigger($statement->getObject(),null,null);
$infRule->setEntailment($statement->getSubject(),'<p>','<o>');
$infRule->setTrigger(null,$statement->getSubject(),null);
$infRule->setEntailment('<s>',$statement->getObject(),'<o>');
$infRule->setTrigger(null,$statement->getObject(),null);
$infRule->setEntailment('<s>',$statement->getSubject(),'<o>');
$infRule->setTrigger(null,null,$statement->getSubject());
$infRule->setEntailment('<s>','<p>',$statement->getObject());
$infRule->setTrigger(null,null,$statement->getObject());
$infRule->setEntailment('<s>','<p>',$statement->getSubject());
* This function checks, which infrules were added by the statement and
* @param object Statement $statement
//get the position of the statement that should be removed
$statement->getPredicate(),
if ($statementPosition!=-
1)
//remove from Rule-Trigger Index
if (is_a($this,'InfModelF'))
$trigger=
$this->infRules[$key]->getTrigger();
if(is_a($trigger['s'],'Node'))
$subjectLabel=
$trigger['s']->getLabel();
if(is_a($trigger['p'],'Node'))
$predicateLabel=
$trigger['p']->getLabel();
if(is_a($trigger['o'],'Node'))
$objectLabel=
$trigger['o']->getLabel();
//remove from Rule-Entailment Index
$entailment=
$this->infRules[$key]->getEntailment();
if(is_a($entailment['s'],'Node'))
$subjectLabel=
$entailment['s']->getLabel();
if(is_a($entailment['p'],'Node'))
$predicateLabel=
$entailment['p']->getLabel();
if(is_a($entailment['o'],'Node'))
$objectLabel=
$entailment['o']->getLabel();
//remove from statement-Rule Index
$return[]=
$statementPosition;
} while($statementPosition!=-
1);
//return the positions of the statements to be removed OR emty array
* Returns a model, containing all Statements, having a Predicate, that
* is supported by the inference.
//Search the base-model for all statements, having a Predicate, that
//is supported by the inference.
$res->addModel($this->find(null, new Resource($inferencePredicateLabel), null));
* General method to replace nodes of a MemModel.
* This function is disabled in the Inference Model.
* @param object Node $subject
* @param object Node $predicate
* @param object Node $object
* @param object Node $replacement
function replace($subject, $predicate, $object, $replacement)
$errmsg =
RDFAPI_ERROR .
'(class: InfModel; method: replace): This function is disabled in the Inference Model';
* 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
* Returns an empty MemModel if nothing is found.
* This function is disabled in the Inference Model
* @param string $subject_regex
* @param string $predicate_regex
* @param string $object_regex
* @return object MemModel
function findRegex($subject_regex, $predicate_regex, $object_regex)
$errmsg =
RDFAPI_ERROR .
'(class: InfModel; method: findRegex):
This function is disabled in the
* Returns all tripels of a certain vocabulary.
* $vocabulary is the namespace of the vocabulary inluding a # : / char at
* e.g. http://www.w3.org/2000/01/rdf-schema#
* Returns an empty MemModel if nothing is found.
* This function is disabled in the Inference Model.
* @param string $vocabulary
* @return object MemModel
$errmsg =
RDFAPI_ERROR .
'(class: InfModel; method: findVocabulary):
This function is disabled in the
* Adds the URI or NULL to the Infrule trigger or entailment index.
* @param object infrule $infRule
* @param integer $infRulePosition
//Add the rule only to the trigger index, if it is a InfFModel
if (is_a($this,'InfModelF'))
$trigger =
$infRule->getTrigger();
//evaluate and set the index
if ($trigger['s'] ==
null)
if ($trigger['p'] ==
null)
if ($trigger['o'] ==
null)
//add to entailment Index if it is a BModel
$entailment =
$infRule->getEntailment();
//evaluate the entailment and add to index
if (!is_a($entailment['s'],'Node'))
if (!is_a($entailment['p'],'Node'))
if (!is_a($entailment['o'],'Node'))
* Searches the trigger-index for a matching trigger and returns an
* array of infRule positions.
* @param object infrule $infRule
//a statement's subject matches all triggers with null and the same URI
$subjectLabel=
$statement->getLabelSubject();
//a statement's predicate matches all triggers with null and the same URI
$predicateLabel=
$statement->getLabelPredicate();
//a statement's object matches all triggers with null and the same URI
$objectLabel=
$statement->getLabelObject();
//if an infrule position occurs in subject, predicate, and object index, add to result array.
foreach ($inIndexP as $positionP)
* Searches the Entailment-index for a matching Entailment and returns an
* array of infRule positions.
* @param node or null $subject
* @param node or null $predicate
* @param node or null $object
//a node matches all entailments with NULL or a matching URI
if(is_a($subject,'Node'))
$subjectLabel=
$subject->getLabel();
//if the subject search pattern is NULL, every rule will match the subject search patter
if(is_a($predicate,'Node'))
$predicateLabel=
$predicate->getLabel();
$objectLabel=
$object->getLabel();
//if an infrule position occurs in subject, predicate, and object index, add to result array.
foreach ($inIndexP as $positionP)
* Adds an InfRule to the InfModel.
* $statementPosition states the positiion of the statement, that created
* this rule, in the model->triples array.
* @param object Infrule $infRule
* @param integer $statementPosition
//get the position of the added rule in the model
//add the information to the index, that this statement
//add informations to index over trigger & entailment
Documentation generated on Mon, 26 Jun 2006 14:25:29 +0200 by phpDocumentor 1.3.0RC6