Source for file InfModel.php

Documentation is available at InfModel.php

  1. <?php
  2. // ----------------------------------------------------------------------------------
  3. // Class: infModel
  4. // ----------------------------------------------------------------------------------
  5.  
  6. /**
  7. * Class: InfModel
  8. * @package infModel
  9. */
  10.  
  11. /**
  12. * A InfModel Model extends a MemModel , by adding the ability to infer statements from
  13. * known statements and RDFS/OWL-Schematas.
  14. * It uses the same interface as MemModel, thus making the
  15. * infererence process hidden.
  16. * <BR><BR>History:<UL>
  17. * <LI>09-23-2004 : Bug removed in _findRuleEntailmentInIndex().</LI>
  18. * <LI>09-15-2004 : Added Index over InRule Triggers
  19. * and Entailments to increase performance.</LI>
  20. * <LI>09-10-2004 : First version of this class.</LI>
  21. * </UL>
  22. * @version V0.9.1
  23. * @author Daniel Westphal <mail at d-westphal dot de>
  24. *
  25. * @package infModel
  26. * @access public
  27. */
  28.  
  29. class InfModel extends MemModel
  30. {
  31. /**
  32. * array that holds the objects of the class Infrule,
  33. * which were assigned by the _addToInference() function
  34. * @var array
  35. * @access private
  36. */
  37. var $infRules;
  38.  
  39. /**
  40. * array of URI-Strings that produces Infrules
  41. * @var array
  42. * @access private
  43. */
  44. var $supportedInference;
  45. /**
  46. * array of the connection between the infrules and the statement
  47. * that assigned those rules.
  48. * array[2][3]=true;array[2][5]=true means, that statement 2
  49. * assigned rule 3 & 5 to the model.
  50. * @var array
  51. * @access private
  52. */
  53. var $statementRuleIndex;
  54. /**
  55. * array of the infRule triggers and the matching infrules.
  56. * $this->infRulesTriggerIndex['s'] for subject index, ['p'] for predicates,
  57. * and ['o'] for objects.
  58. * @var array
  59. * @access private
  60. */
  61. var $infRulesTriggerIndex;
  62. /**
  63. * array of the infRule entailments and the matching infrules.
  64. * $this->infRulesEntailIndex['s'] for subject index, ['p'] for predicates,
  65. * and ['o'] for objects.
  66. * @var array
  67. * @access private
  68. */
  69. var $infRulesEntailIndex;
  70.  
  71.  
  72.  
  73. /**
  74. * Constructor
  75. * You can supply a base_uri
  76. *
  77. * @param string $baseURI
  78. * @access public
  79. */
  80. function InfModel ($baseURI = NULL)
  81. {
  82. //call the memmodel constructor method
  83. parent::MemModel($baseURI);
  84. //initialise vars
  85. $this->infRulesTriggerIndex['s']=array();
  86. $this->infRulesTriggerIndex['p']=array();
  87. $this->infRulesTriggerIndex['o']=array();
  88. $this->infRulesEntailIndex['s']=array();
  89. $this->infRulesEntailIndex['p']=array();
  90. $this->infRulesEntailIndex['o']=array();
  91. $this->infRules=array();
  92. $this->statementRuleIndex = array();
  93. //arraylist of predicate labels that shall add inference rules
  94. //to the model
  95. //The constants, wich statements will create rules can be configured in constants.php
  96. if (INF_RES_SUBCLASSOF)
  97. $this->supportedInference[] = RDF_SCHEMA_URI.RDFS_SUBCLASSOF;
  98. if (INF_RES_SUBPROPERTYOF)
  99. $this->supportedInference[] = RDF_SCHEMA_URI.RDFS_SUBPROPERTYOF;
  100.  
  101. if (INF_RES_RANGE)
  102. $this->supportedInference[] = RDF_SCHEMA_URI.RDFS_RANGE;
  103.  
  104. if (INF_RES_DOMAIN)
  105. $this->supportedInference[] = RDF_SCHEMA_URI.RDFS_DOMAIN;
  106.  
  107. if (INF_RES_OWL_SAMEAS)
  108. $this->supportedInference[] = OWL_URI.OWL_SAME_AS;
  109.  
  110. if (INF_RES_OWL_INVERSEOF)
  111. $this->supportedInference[] = OWL_URI.OWL_INVERSE_OF;
  112.  
  113. //Rule: rdfs12
  114. if (INF_RES_RULE_RDFS12)
  115. {
  116. $infRule=new InfRule();
  117. $infRule->setTrigger(null,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),new Resource(RDF_SCHEMA_URI.'ContainerMembershipProperty'));
  118. $infRule->setEntailment('<s>',new Resource(RDF_SCHEMA_URI.RDFS_SUBPROPERTYOF),new Resource(RDF_SCHEMA_URI.'member'));
  119. $this->_addInfRule($infRule,'base');
  120. }
  121. //Rule: rdfs6
  122. if (INF_RES_RULE_RDFS6)
  123. {
  124. $infRule=new InfRule();
  125. $infRule->setTrigger(null,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),new Resource(RDF_NAMESPACE_URI.RDF_PROPERTY));
  126. $infRule->setEntailment('<s>',new Resource(RDF_SCHEMA_URI.RDFS_SUBPROPERTYOF),'<s>');
  127. $this->_addInfRule($infRule,'base');
  128. }
  129. //Rule: rdfs8
  130. if (INF_RES_RULE_RDFS8)
  131. {
  132. $infRule=new InfRule();
  133. $infRule->setTrigger(null,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),new Resource(RDF_SCHEMA_URI.RDFS_CLASS));
  134. $infRule->setEntailment('<s>',new Resource(RDF_SCHEMA_URI.RDFS_SUBCLASSOF),new Resource(RDF_SCHEMA_URI.RDFS_RESOURCE));
  135. $this->_addInfRule($infRule,'base');
  136. }
  137. //Rule: rdfs10
  138. if (INF_RES_RULE_RDFS10)
  139. {
  140. $infRule=new InfRule();
  141. $infRule->setTrigger(null,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),new Resource(RDF_SCHEMA_URI.RDFS_CLASS));
  142. $infRule->setEntailment('<s>',new Resource(RDF_SCHEMA_URI.RDFS_SUBCLASSOF),'<s>');
  143. $this->_addInfRule($infRule,'base');
  144. }
  145. //Rule: rdfs13
  146. if (INF_RES_RULE_RDFS13)
  147. {
  148. $infRule=new InfRule();
  149. $infRule->setTrigger(null,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),new Resource(RDF_SCHEMA_URI.RDFS_DATATYPE));
  150. $infRule->setEntailment('<s>',new Resource(RDF_SCHEMA_URI.RDFS_SUBCLASSOF),new Resource(RDF_SCHEMA_URI.RDFS_LITERAL));
  151. $this->_addInfRule($infRule,'base');
  152. }
  153. }
  154. /**
  155. * Adds a new triple to the Model without checking if the statement
  156. * is already in the Model.
  157. * So if you want a duplicate free MemModel use the addWithoutDuplicates()
  158. * function (which is slower then add())
  159. * If the statement's predicate label is supported by the inference,
  160. * the matching rules are added.
  161. *
  162. * @param object Statement $statement
  163. * @access public
  164. * @throws PhpError
  165. */
  166. function add($statement)
  167. {
  168. parent::add($statement);
  169. //if the predicate is supported by the inference
  170. if (in_array($statement->getLabelPredicate(),$this->supportedInference))
  171. {
  172. $this->_addToInference($statement);
  173. };
  174. }
  175.  
  176. /**
  177. * This function analyses the statement's predicate and adds the
  178. * matching infrule to the model
  179. *
  180. * @param object Statement $statement
  181. * @access private
  182. */
  183. function _addToInference($statement)
  184. {
  185. $predicateLabel=$statement->getLabelPredicate();
  186. //get the position of the the statement in the model
  187. end($this->triples);
  188. $statementPosition=key($this->triples);
  189. switch ($predicateLabel)
  190. {
  191. case RDF_SCHEMA_URI.RDFS_SUBPROPERTYOF :
  192. //create a new rule
  193. $infRule=new InfRule();
  194. //set the trigger to match all statements, having a
  195. //predicate, that matches the subject of the statement that
  196. //created this rule.
  197. $infRule->setTrigger(null,$statement->getSubject(),null);
  198. //set the infrule to return a statement, having the same
  199. //subject and object as the statement, that asked for an
  200. //entailment, and having the object of the statement,
  201. //that created this rule as predicate.
  202. $infRule->setEntailment('<s>',$statement->getObject(),'<o>');
  203. //add the infule to Model, Statement/Rule-Index,
  204. //and Rule/Trigger (or Rule/Entailment) index
  205. $this->_addInfRule($infRule,$statementPosition);
  206. break;
  207. case RDF_SCHEMA_URI.RDFS_SUBCLASSOF :
  208. $infRule=new InfRule();
  209. $infRule->setTrigger(null,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),$statement->getSubject());
  210. $infRule->setEntailment('<s>',new Resource(RDF_NAMESPACE_URI.RDF_TYPE),$statement->getObject());
  211. $this->infRules[]=$infRule;
  212. $this->_addInfRule($infRule,$statementPosition);
  213. break;
  214. case RDF_SCHEMA_URI.RDFS_DOMAIN :
  215. $infRule=new InfRule();
  216. $infRule->setTrigger(null,$statement->getSubject(),null);
  217. $infRule->setEntailment('<s>',new Resource(RDF_NAMESPACE_URI.RDF_TYPE),$statement->getObject());
  218. $this->infRules[]=$infRule;
  219. $this->_addInfRule($infRule,$statementPosition);
  220. break;
  221. case RDF_SCHEMA_URI.RDFS_RANGE :
  222. $infRule=new InfRule();
  223. $infRule->setTrigger(null,$statement->getSubject(),null);
  224. $infRule->setEntailment('<o>',new Resource(RDF_NAMESPACE_URI.RDF_TYPE),$statement->getObject());
  225. $this->infRules[]=$infRule;
  226. $this->_addInfRule($infRule,$statementPosition);
  227. break;
  228. case OWL_URI.OWL_INVERSE_OF :
  229. $infRule=new InfRule();
  230. $infRule->setTrigger(null,$statement->getSubject(),null);
  231. $infRule->setEntailment('<o>',$statement->getObject(),'<s>');
  232. $this->infRules[]=$infRule;
  233. $this->_addInfRule($infRule,$statementPosition);
  234. $infRule=new InfRule();
  235. $infRule->setTrigger(null,$statement->getObject(),null);
  236. $infRule->setEntailment('<o>',$statement->getSubject(),'<s>');
  237. $this->infRules[]=$infRule;
  238. $this->_addInfRule($infRule,$statementPosition);
  239. break;
  240. case OWL_URI.OWL_SAME_AS :
  241. $infRule=new InfRule();
  242. $infRule->setTrigger($statement->getSubject(),null,null);
  243. $infRule->setEntailment($statement->getObject(),'<p>','<o>');
  244. $this->_addInfRule($infRule,$statementPosition);
  245. $infRule=new InfRule();
  246. $infRule->setTrigger($statement->getObject(),null,null);
  247. $infRule->setEntailment($statement->getSubject(),'<p>','<o>');
  248. $this->_addInfRule($infRule,$statementPosition);
  249. $infRule=new InfRule();
  250. $infRule->setTrigger(null,$statement->getSubject(),null);
  251. $infRule->setEntailment('<s>',$statement->getObject(),'<o>');
  252. $this->_addInfRule($infRule,$statementPosition);
  253. $infRule=new InfRule();
  254. $infRule->setTrigger(null,$statement->getObject(),null);
  255. $infRule->setEntailment('<s>',$statement->getSubject(),'<o>');
  256. $this->_addInfRule($infRule,$statementPosition);
  257. $infRule=new InfRule();
  258. $infRule->setTrigger(null,null,$statement->getSubject());
  259. $infRule->setEntailment('<s>','<p>',$statement->getObject());
  260. $this->_addInfRule($infRule,$statementPosition);
  261. $infRule=new InfRule();
  262. $infRule->setTrigger(null,null,$statement->getObject());
  263. $infRule->setEntailment('<s>','<p>',$statement->getSubject());
  264. $this->_addInfRule($infRule,$statementPosition);
  265. break;
  266. };
  267. }
  268.  
  269. /**
  270. * This function checks, which infrules were added by the statement and
  271. * removes those.
  272. *
  273. * @param object Statement $statement
  274. * @return integer
  275. * @access private
  276. */
  277. function _removeFromInference($statement)
  278. {
  279. $return= array();
  280. $statementPosition=-1;
  281. do
  282. {
  283. //get the position of the statement that should be removed
  284. $statementPosition=$this->findFirstMatchOff($statement->getSubject(),
  285. $statement->getPredicate(),
  286. $statement->getObject(),
  287. $statementPosition+1);
  288. if ($statementPosition!=-1)
  289. {
  290. //if it added any rules
  291. if (isset ($this->statementRuleIndex[$statementPosition]))
  292. {
  293. //remove all rules
  294. foreach ($this->statementRuleIndex[$statementPosition] as $key => $value)
  295. {
  296. //remove from Rule-Trigger Index
  297. if (is_a($this,'InfModelF'))
  298. {
  299. $trigger=$this->infRules[$key]->getTrigger();
  300. if(is_a($trigger['s'],'Node'))
  301. {
  302. $subjectLabel=$trigger['s']->getLabel();
  303. } else
  304. {
  305. $subjectLabel='null';
  306. }
  307. unset ($this->infRulesTriggerIndex['s'][$subjectLabel][array_search($key,$this->infRulesTriggerIndex['s'][$subjectLabel])]);
  308. if(is_a($trigger['p'],'Node'))
  309. {
  310. $predicateLabel=$trigger['p']->getLabel();
  311. } else
  312. {
  313. $predicateLabel='null';
  314. }
  315. unset ($this->infRulesTriggerIndex['p'][$predicateLabel][array_search($key,$this->infRulesTriggerIndex['p'][$predicateLabel])]);
  316. if(is_a($trigger['o'],'Node'))
  317. {
  318. $objectLabel=$trigger['o']->getLabel();
  319. } else
  320. {
  321. $objectLabel='null';
  322. }
  323. unset ($this->infRulesTriggerIndex['o'][$objectLabel][array_search($key,$this->infRulesTriggerIndex['o'][$objectLabel])]);
  324. } else
  325. //remove from Rule-Entailment Index
  326. {
  327. $entailment=$this->infRules[$key]->getEntailment();
  328. if(is_a($entailment['s'],'Node'))
  329. {
  330. $subjectLabel=$entailment['s']->getLabel();
  331. } else
  332. {
  333. $subjectLabel='null';
  334. }
  335. unset ($this->infRulesEntailIndex['s'][$subjectLabel][array_search($key,$this->infRulesEntailIndex['s'][$subjectLabel])]);
  336. if(is_a($entailment['p'],'Node'))
  337. {
  338. $predicateLabel=$entailment['p']->getLabel();
  339. } else
  340. {
  341. $predicateLabel='null';
  342. }
  343. unset ($this->infRulesEntailIndex['p'][$predicateLabel][array_search($key,$this->infRulesEntailIndex['p'][$predicateLabel])]);
  344. if(is_a($entailment['o'],'Node'))
  345. {
  346. $objectLabel=$entailment['o']->getLabel();
  347. } else
  348. {
  349. $objectLabel='null';
  350. }
  351. unset ($this->infRulesEntailIndex['o'][$objectLabel][array_search($key,$this->infRulesEntailIndex['o'][$objectLabel])]);
  352. }
  353. //remove from statement-Rule Index
  354. unset ($this->infRules[$key]);
  355. }
  356. unset($this->statementRuleIndex[$statementPosition]);
  357. $return[]=$statementPosition;
  358. };
  359. }
  360. } while($statementPosition!=-1);
  361. //return the positions of the statements to be removed OR emty array
  362. //if nothing was found.
  363. return $return;
  364. }
  365.  
  366. /**
  367. * Returns a model, containing all Statements, having a Predicate, that
  368. * is supported by the inference.
  369. *
  370. * @return object Model
  371. * @access public
  372. */
  373. function getSchema()
  374. {
  375. $res=new MemModel();
  376. //Search the base-model for all statements, having a Predicate, that
  377. //is supported by the inference.
  378. foreach ($this->supportedInference as $inferencePredicateLabel)
  379. {
  380. $res->addModel($this->find(null, new Resource($inferencePredicateLabel), null));
  381. }
  382. return $res;
  383. }
  384. /**
  385. * General method to replace nodes of a MemModel.
  386. *
  387. * This function is disabled in the Inference Model
  388. *
  389. * @param object Node $subject
  390. * @param object Node $predicate
  391. * @param object Node $object
  392. * @param object Node $replacement
  393. * @access public
  394. * @throws PhpError
  395. */
  396. function replace($subject, $predicate, $object, $replacement)
  397. {
  398. $errmsg = RDFAPI_ERROR . '(class: InfModel; method: replace): This function is disabled in the Inference Model';
  399. trigger_error($errmsg, E_USER_ERROR);
  400. }
  401.  
  402. /**
  403. * Method to search for triples using Perl-style regular expressions.
  404. * NULL input for any parameter will match anything.
  405. * Example: $result = $m->find_regex( NULL, NULL, $regex );
  406. * Finds all triples where the label of the object node matches the regular
  407. * expression.
  408. * Returns an empty MemModel if nothing is found.
  409. *
  410. * This function is disabled in the Inference Model
  411. *
  412. * @param string $subject_regex
  413. * @param string $predicate_regex
  414. * @param string $object_regex
  415. * @return object MemModel
  416. * @access public
  417. */
  418. function findRegex($subject_regex, $predicate_regex, $object_regex)
  419. {
  420.  
  421. $errmsg = RDFAPI_ERROR . '(class: InfModel; method: findRegex):
  422. This function is disabled in the
  423. Inference Model';
  424. trigger_error($errmsg, E_USER_ERROR);
  425. }
  426. /**
  427. * Returns all tripels of a certain vocabulary.
  428. * $vocabulary is the namespace of the vocabulary inluding a # : / char at
  429. * the end.
  430. * e.g. http://www.w3.org/2000/01/rdf-schema#
  431. * Returns an empty MemModel if nothing is found.
  432. *
  433. * This function is disabled in the Inference Model
  434. *
  435. * @param string $vocabulary
  436. * @return object MemModel
  437. * @access public
  438. */
  439. function findVocabulary($vocabulary)
  440. {
  441. $errmsg = RDFAPI_ERROR . '(class: InfModel; method: findVocabulary):
  442. This function is disabled in the
  443. Inference Model';
  444. trigger_error($errmsg, E_USER_ERROR);
  445. }
  446.  
  447. /**
  448. * Adds the URI or NULL to the Infrule trigger or entailment index
  449. *
  450. *
  451. * @param object infrule $infRule
  452. * @param integer $infRulePosition
  453. * @access private
  454. */
  455. function _addInfruleToIndex(& $infRule,& $infRulePosition)
  456. {
  457. //Add the rule only to the trigger index, if it is a InfFModel
  458. if (is_a($this,'InfModelF'))
  459. {
  460. //get the trigger
  461. $trigger = $infRule->getTrigger();
  462. //evaluate and set the index
  463. if ($trigger['s'] == null)
  464. {
  465. $this->infRulesTriggerIndex['s']['null'][]=$infRulePosition;
  466. } else
  467. {
  468. $this->infRulesTriggerIndex['s'][$trigger['s']->getLabel()][]=$infRulePosition;
  469. };
  470. if ($trigger['p'] == null)
  471. {
  472. $this->infRulesTriggerIndex['p']['null'][]=$infRulePosition;
  473. } else
  474. {
  475. $this->infRulesTriggerIndex['p'][$trigger['p']->getLabel()][]=$infRulePosition;
  476. };
  477. if ($trigger['o'] == null)
  478. {
  479. $this->infRulesTriggerIndex['o']['null'][]=$infRulePosition;
  480. } else
  481. {
  482. $this->infRulesTriggerIndex['o'][$trigger['o']->getLabel()][]=$infRulePosition;
  483. };
  484. } else
  485. //add to entailment Index if it is a BModel
  486. {
  487. //get the entailment
  488. $entailment = $infRule->getEntailment();
  489. //evaluate the entailment and add to index
  490. if (!is_a($entailment['s'],'Node'))
  491. {
  492. $this->infRulesEntailIndex['s']['null'][]=$infRulePosition;
  493. } else
  494. {
  495. $this->infRulesEntailIndex['s'][$entailment['s']->getLabel()][]=$infRulePosition;
  496. };
  497. if (!is_a($entailment['p'],'Node'))
  498. {
  499. $this->infRulesEntailIndex['p']['null'][]=$infRulePosition;
  500. } else
  501. {
  502. $this->infRulesEntailIndex['p'][$entailment['p']->getLabel()][]=$infRulePosition;
  503. };
  504. if (!is_a($entailment['o'],'Node'))
  505. {
  506. $this->infRulesEntailIndex['o']['null'][]=$infRulePosition;
  507. } else
  508. {
  509. $this->infRulesEntailIndex['o'][$entailment['o']->getLabel()][]=$infRulePosition;
  510. };
  511. };
  512. }
  513. /**
  514. * Searches the trigger-index for a matching trigger and returns an
  515. * array of infRule positions
  516. *
  517. *
  518. * @param object infrule $infRule
  519. * @return array integer
  520. * @access private
  521. */
  522. function _findRuleTriggerInIndex($statement)
  523. {
  524. $return=array();
  525. //a statement's subject matches all triggers with null and the same URI
  526. $subjectLabel=$statement->getLabelSubject();
  527. $inIndexS=array();
  528. if (isset($this->infRulesTriggerIndex['s']['null']))
  529. $inIndexS=array_values($this->infRulesTriggerIndex['s']['null']);
  530. if (isset($this->infRulesTriggerIndex['s'][$subjectLabel]))
  531. $inIndexS= array_merge($subjectLabel,array_values($this->infRulesTriggerIndex['s'][$subjectLabel]));
  532. //a statement's predicate matches all triggers with null and the same URI
  533. $predicateLabel=$statement->getLabelPredicate();
  534. $inIndexP=array();
  535. if (isset($this->infRulesTriggerIndex['p']['null']))
  536. $inIndexP=array_values($this->infRulesTriggerIndex['p']['null']);
  537. if (isset($this->infRulesTriggerIndex['p'][$predicateLabel]))
  538. $inIndexP= array_merge($inIndexP,array_values($this->infRulesTriggerIndex['p'][$predicateLabel]));
  539. //a statement's object matches all triggers with null and the same URI
  540. $objectLabel=$statement->getLabelObject();
  541. $inIndexO=array();
  542. if (isset($this->infRulesTriggerIndex['o']['null']))
  543. $inIndexO=array_values($this->infRulesTriggerIndex['o']['null']);
  544. if (isset($this->infRulesTriggerIndex['o'][$objectLabel]))
  545. $inIndexO= array_merge($inIndexO,array_values($this->infRulesTriggerIndex['o'][$objectLabel]));
  546.  
  547. //if an infrule position occurs in subject, predicate, and object index, add to result array.
  548. foreach ($inIndexP as $positionP)
  549. {
  550. if (in_array($positionP,$inIndexO))
  551. if (in_array($positionP,$inIndexS))
  552. $return[]=$positionP;
  553. }
  554. return $return;
  555. }
  556. /**
  557. * Searches the Entailment-index for a matching Entailment and returns an
  558. * array of infRule positions
  559. *
  560. *
  561. * @param node or null $subject
  562. * @param node or null $predicate
  563. * @param node or null $object
  564. * @return array integer
  565. * @access private
  566. */
  567. function _findRuleEntailmentInIndex($subject,$predicate,$object)
  568. {
  569. $return=array();
  570. //a node matches all entailments with NULL or a matching URI
  571. if(is_a($subject,'Node'))
  572. {
  573. $subjectLabel=$subject->getLabel();
  574. $inIndexS=array();
  575. if (isset($this->infRulesEntailIndex['s']['null'])) $inIndexS=array_values($this->infRulesEntailIndex['s']['null']);
  576. if (isset($this->infRulesEntailIndex['s'][$subjectLabel])) $inIndexS= array_merge($inIndexS,array_values($this->infRulesEntailIndex['s'][$subjectLabel]));
  577. } else
  578. //if the subject search pattern is NULL, every rule will match the subject search patter
  579. {
  580. $inIndexS=array_keys($this->infRules);
  581. }
  582. if(is_a($predicate,'Node'))
  583. {
  584. $predicateLabel=$predicate->getLabel();
  585. $inIndexP=array();
  586. if (isset($this->infRulesEntailIndex['p']['null'])) $inIndexP=array_values($this->infRulesEntailIndex['p']['null']);
  587. if (isset($this->infRulesEntailIndex['p'][$predicateLabel])) $inIndexP= array_merge($inIndexP,array_values($this->infRulesEntailIndex['p'][$predicateLabel]));
  588. } else
  589. {
  590. $inIndexP=array_keys($this->infRules);
  591. }
  592. if(is_a($object,'Node'))
  593. {
  594. $objectLabel=$object->getLabel();
  595. $inIndexO=array();
  596. if (isset($this->infRulesEntailIndex['o']['null'])) $inIndexO=array_values($this->infRulesEntailIndex['o']['null']);
  597. if (isset($this->infRulesEntailIndex['o'][$objectLabel])) $inIndexO= array_merge($inIndexO,array_values($this->infRulesEntailIndex['o'][$objectLabel]));
  598. } else
  599. {
  600. $inIndexO=array_keys($this->infRules);
  601. }
  602. //if an infrule position occurs in subject, predicate, and object index, add to result array.
  603. foreach ($inIndexP as $positionP)
  604. {
  605. if (in_array($positionP,$inIndexO))
  606. if (in_array($positionP,$inIndexS))
  607. $return[]=$positionP;
  608. }
  609. return $return;
  610. }
  611. /**
  612. * Adds an InfRule to the InfModel.
  613. * $statementPosition states the positiion of the statement, that created
  614. * this rule, in the model->triples array.
  615. *
  616. *
  617. * @param object Infrule $infRule
  618. * @param integer $statementPosition
  619. * @access private
  620. */
  621. function _addInfRule($infRule, $statementPosition)
  622. {
  623. //add the rule
  624. $this->infRules[]=$infRule;
  625. //get the position of the added rule in the model
  626. end($this->infRules);
  627. $rulePosition=key($this->infRules);
  628. //add the information to the index, that this statement
  629. //added this rule.
  630. $this->statementRuleIndex[$statementPosition][$rulePosition]=true;
  631. //add informations to index over trigger & entailment
  632. $this->_addInfruleToIndex($infRule,$rulePosition);
  633. }
  634. }
  635. ?>

Documentation generated on Fri, 17 Dec 2004 16:15:06 +0100 by phpDocumentor 1.3.0RC3