Source for file InfModel.php

Documentation is available at InfModel.php

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

Documentation generated on Fri, 13 Jan 2006 07:48:19 +0100 by phpDocumentor 1.3.0RC4