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 443 2007-06-01 16:25:38Z cax $
* @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.
$this->entailment=
array();
* 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'
$this->trigger['s']=
$subject;
$this->trigger['p']=
$predicate;
$this->trigger['o']=
$object;
* 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'
$this->entailment['s']=
$subject;
$this->entailment['p']=
$predicate;
$this->entailment['o']=
$object;
* 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 ||
!is_a($this->entailment['s'],'Node') ||
$this->entailment['s']->equals($subject);
//true, if $predicate is null, the entailment's predicate matches
//anything, or the $predicate equals the entailment-predicate.
$matchesP=
$predicate ==
null ||
!is_a($this->entailment['p'],'Node') ||
$this->entailment['p']->equals($predicate);
//true, if $object is null, the entailment's object matches
//anything, or the $object equals the entailment-object.
$matchesO=
$object ==
null ||
!is_a($this->entailment['o'],'Node') ||
$this->entailment['o']->equals($object);
//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.
switch ($this->entailment['s'])
$entailedSubject=
$statement->getSubject();
$entailedSubject=
$statement->getPredicate();
$entailedSubject=
$statement->getObject();
$entailedSubject=
$this->entailment['s'];
//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.
switch ($this->entailment['p'])
$entailedPredicate=
$statement->getSubject();
$entailedPredicate=
$statement->getPredicate();
$entailedPredicate=
$statement->getObject();
$entailedPredicate=
$this->entailment['p'];
//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.
switch ($this->entailment['o'])
$entailedObject=
$statement->getSubject();
$entailedObject=
$statement->getPredicate();
$entailedObject=
$statement->getObject();
$entailedObject=
$this->entailment['o'];
//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
$findSubject=
$this->trigger['s'];
$findPredicate=
$this->trigger['p'];
$findObject=
$this->trigger['o'];
switch ($this->entailment['s'])
switch ($this->entailment['p'])
$findPredicate=
$predicate;
switch ($this->entailment['o'])
return array('s' =>
$findSubject,
return array ( 's' =>
$this->trigger['s'],
'p' =>
$this->trigger['p'],
'o' =>
$this->trigger['o'],
return array ( 's' =>
$this->entailment['s'],
'p' =>
$this->entailment['p'],
'o' =>
$this->entailment['o'],
Documentation generated on Fri, 1 Jun 2007 16:49:33 +0200 by phpDocumentor 1.3.2