source: Dev/branches/rest-dojo-ui/jQueryUI/server/rdfapi/infModel/InfModel.php @ 312

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