Source for file InfRule.php
Documentation is available at InfRule.php
// ----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------
* This class represents a single rule in a RDFS inference model.
* It primary constists of a trigger and an entailment.
* In the forward-chaining mode (RDFSFModel) a statement is checked,
* if it satisfies the trigger. If it does, a new statement is returned.
* In the backward-chaining mode (RDFSBModel) a find-query is checked
* with the entailment. If this entailment could satify the find-query,
* a new find-query is returned, that searches for statements that
* satisfy the trigger of this rule.
* @version $Id: fsource_infModel__infModelInfRule.php.html,v 1.10 2006/06/26 12:34:12 tgauss Exp $
* @author Daniel Westphal <mail at d-westphal dot de>
* Array, that hold the trigger subject in key ['s'], the trigger
* predicate in ['p'], and the trigger object in ['o'].
* The array values can be NULL to match anything or be a node that
* Array, that hold the entailment subject in key ['s'], the
* entailment predicate in ['p'], and the entailment object in ['o'].
* The array values can be a node that will be inserted in the
* returning statement, or '<s>' to insert the subject,'<p>' to insert
* the predicate, or '<o>' to insert the object of the checked statement
* to this position in the new returned statement.
* Sets the trigger of this rule
* The values can be NULL to match anything or be a node that has to
* @param object Node OR NULL $subject
* @param object Node OR NULL $predicate
* @param object Node OR NULL $object
function setTrigger ($subject, $predicate, $object)
//throw an error if subject, predicate, or object are neither
if(!is_a($subject,'Node') &&
$subject !=
null)
setTrigger): $subject has to be null or of class Node'
if(!is_a($predicate,'Node') &&
$predicate !=
null)
setTrigger): $predicate has to be null or of class Node'
if(!is_a($object,'Node') &&
$object !=
null)
setTrigger): $object has to be null or of class Node'
* Sets the entailment of this rule
* The values can be NULL to match anything or be a node that has to
* @param object Node OR NULL $subject
* @param object Node OR NULL $predicate
* @param object Node OR NULL $object
//throw an error if subject, predicate, or object are neither node,
if(!is_a($subject,'Node') &&
!ereg('<[spo]>', $subject))
setEntailment): $subject has to be <s>,<p>,or <o> or of class Node'
if(!is_a($predicate,'Node') &&
!ereg('<[spo]>', $predicate))
setEntailment): $predicate has to be <s>,<p>,or <o> or of class Node'
if(!is_a($object,'Node') &&
!ereg('<[spo]>', $object))
setEntailment): $object has to be <s>,<p>,or <o> or of class Node'
* Checks, if the statement satisfies the trigger.
* @param object Statement
//is true, if the trigger is null to match anything
//or equals the statement's subject
$shouldFireS =
$this->trigger['s'] ==
null ||
$this->trigger['s']->equals($statement->getSubject());
//is true, if the trigger is null to match anything
//or equals the statement's predicate
$shouldFireP =
$this->trigger['p'] ==
null ||
$this->trigger['p']->equals($statement->getPredicate());
//is true, if the trigger is null to match anything
//or equals the statement's object
$shouldFireO =
$this->trigger['o'] ==
null ||
$this->trigger['o']->equals($statement->getObject());
//returns true, if ALL are true
return $shouldFireS &&
$shouldFireP &&
$shouldFireO;
* Checks, if this rule could entail a statement that matches
* a find of $subject,$predicate,$object.
* @param object Statement
//true, if $subject is null, the entailment's subject matches
//anything, or the $subject equals the entailment-subject.
$matchesS=
$subject ==
null ||
//true, if $predicate is null, the entailment's predicate matches
//anything, or the $predicate equals the entailment-predicate.
$matchesP=
$predicate ==
null ||
//true, if $object is null, the entailment's object matches
//anything, or the $object equals the entailment-object.
$matchesO=
$object ==
null ||
//returns true, if ALL are true
return $matchesS &&
$matchesP &&
$matchesO;
* Returns a infered InfStatement by evaluating the statement with
* @param object Statement
* @return object InfStatement
//if the entailment's subject is <s>,<p>,or <o>, put the statements
//subject,predicate,or object into the subject of the
//entailed statement. If the entailment's subject is a node,
//add that node to the statement.
$entailedSubject=
$statement->getSubject();
$entailedSubject=
$statement->getPredicate();
$entailedSubject=
$statement->getObject();
//if the entailment's predicate is <s>,<p>,or <o>, put the
//statements subject,predicate,or object into the predicate of
//the entailed statement. If the entailment's predicate is a node,
//add that node to the statement.
$entailedPredicate=
$statement->getSubject();
$entailedPredicate=
$statement->getPredicate();
$entailedPredicate=
$statement->getObject();
//if the entailment's object is <s>,<p>,or <o>, put the
//statements subject,predicate,or object into the object of
//the entailed statement. If the entailment's object is a node,
//add that node to the statement.
$entailedObject=
$statement->getSubject();
$entailedObject=
$statement->getPredicate();
$entailedObject=
$statement->getObject();
//return the infered statement
return (new InfStatement($entailedSubject,$entailedPredicate,$entailedObject));
* Returns a find-query that matches statements, whose entailed
* statements would match the supplied find query.
* @param Node OR null $subject
* @param Node OR null $predicate
* @param Node OR null $object
$findPredicate=
$this->trigger['p'];
$findPredicate=
$predicate;
return array('s' =>
$findSubject,
return array ( 's' =>
$this->trigger['s'],
Documentation generated on Mon, 26 Jun 2006 14:25:33 +0200 by phpDocumentor 1.3.0RC6