Source for file IteratorFindQuadsMem.php

Documentation is available at IteratorFindQuadsMem.php

  1. <?php 
  2. // ----------------------------------------------------------------------------------
  3. // Class: IteratorFindQuadsMem
  4. // ----------------------------------------------------------------------------------
  5.  
  6.  
  7.  
  8. /**
  9. * Implementation of a quad iterator.
  10. *
  11. * This Iterator should be used like:
  12. * for($iterator = $dataset->findInNamedGraphs(null,null,null,null); $iterator->valid(); $iterator->next())
  13. * {
  14. *    $currentQuad=$it->current();
  15. * };
  16. *
  17. @version  $Id: fsource_dataset__datasetIteratorFindQuadsMem.php.html,v 1.8 2006/06/26 12:34:12 tgauss Exp $
  18. @author Daniel Westphal (http://d-westphal.de)
  19. *
  20. *
  21. @package     dataset
  22. @access    public
  23. ***/
  24. {
  25.     /**
  26.     * key value in the current graph.
  27.     *
  28.     * @var     dataset 
  29.     * @access    private
  30.     */
  31.     var $graphKey;
  32.     
  33.     /**
  34.     * boolean value, if the results should be returned as triples.
  35.     *
  36.     * @var        boolean 
  37.     * @access    private
  38.     */
  39.     var $returnAsTriples;
  40.     
  41.     /**
  42.     * The current position.
  43.     *
  44.     * @var        integer 
  45.     * @access    private
  46.     */
  47.     var $key;
  48.     
  49.     /**
  50.     * If the current resource is valid.
  51.     *
  52.     * @var        boolean 
  53.     * @access    private
  54.     */
  55.     var $valid;
  56.     
  57.     /**
  58.     * The current NamedGraph.
  59.     *
  60.     * @var  NamedGraph 
  61.     * @access    private
  62.     */
  63.     var $current;
  64.     
  65.     /**
  66.     * The graphName Resource to search for.
  67.     *
  68.     * @var string 
  69.     * @access    private
  70.     */    
  71.     var $findGraphName;
  72.     
  73.     /**
  74.     * The subject Resource to search for.
  75.     *
  76.     * @var string 
  77.     * @access    private
  78.     */    
  79.     var $findSubject;
  80.     
  81.     /**
  82.     * The predicate Resource to search for.
  83.     *
  84.     * @var string 
  85.     * @access    private
  86.     */    
  87.     var $findPredicate;
  88.     
  89.     /**
  90.     * The object Resource to search for.
  91.     *
  92.     * @var string 
  93.     * @access    private
  94.     */    
  95.     var $findObject;
  96.     
  97.     /**
  98.     * Iterator over all graphs of the RDF dataset.
  99.     *
  100.     * @var string 
  101.     * @access    private
  102.     */    
  103.     var $graphIterator;
  104.     
  105.     
  106.     /**
  107.     * Constructor.
  108.     *
  109.     * $subject, $predicate, and $object are used like find().
  110.     * $getSPO supports the strings 's', 'p', and 'o' to return
  111.     * either the subject, predicate, or object of the result statements.
  112.     * 
  113.     *
  114.     * @param Resource 
  115.     * @param Resource 
  116.     * @param Resource 
  117.     * @param dataset 
  118.     * @param Boolean 
  119.     * @access    public
  120.     */
  121.     function IteratorFindQuadsMem($subject,$predicate,$object,&$graphIterator$returnAsTriples=false)
  122.     {
  123.         $this->findSubject=$subject;
  124.         $this->findPredicate=$predicate;
  125.         $this->findObject=$object;
  126.         $this->graphIterator=&$graphIterator;
  127.         $this->rewind();
  128.         $this->returnAsTriples=$returnAsTriples;
  129.     }
  130.     
  131.     /**
  132.     * Resets iterator list to start.
  133.     *
  134.     * @access    public
  135.     */
  136.     function rewind()
  137.     {
  138.         $this->graphIterator->rewind();
  139.         $this->key = -1;
  140.         $this->graphKey=-1;
  141.         $this->next();
  142.     }
  143.     
  144.     /**
  145.     * Says if there are additional items left in the list.
  146.     *
  147.     * @return    boolean 
  148.     * @access    public
  149.     */
  150.     function valid()
  151.     {
  152.         return $this->valid;
  153.     }
  154.     
  155.     /**
  156.     * Moves Iterator to the next item in the list.
  157.     *
  158.     * @access    public
  159.     */
  160.     function next()
  161.     {
  162.         if($this->graphIterator->valid()===false)
  163.         {
  164.             $this->valid=false;
  165.             return;    
  166.         }
  167.     
  168.         $currentGraph=&$this->graphIterator->current();
  169.         $this->current$currentGraph->findFirstMatchingStatement($this->findSubject,$this->findPredicate,$this->findObject,++$this->graphKey);
  170.         if($this->current==null)
  171.         {
  172.             do 
  173.             {
  174.                 $this->graphIterator->next();
  175.                 if($this->graphIterator->valid()===false)
  176.                 {
  177.                     $this->valid=false;
  178.                     return;    
  179.                 }
  180.                 $currentGraph=&$this->graphIterator->current();
  181.                 $this->graphKey=-1;
  182.                 $this->current$currentGraph->findFirstMatchingStatement($this->findSubject,$this->findPredicate,$this->findObject,++$this->graphKey);    
  183.         
  184.             while ($this->current==null);
  185.         }
  186.         $this->key++;
  187.         $this->valid=true;
  188.     }
  189.     
  190.     /**
  191.     * Returns the current item.
  192.     *
  193.     * @return    mixed 
  194.     * @access    public
  195.     */
  196.     function current()
  197.     {
  198.         if($this->returnAsTriplesreturn $this->current;
  199.         
  200.         $currentGraph=&$this->graphIterator->current();
  201.         return new Quad(new Resource($currentGraph->getGraphName()),$this->current->getSubject(),$this->current->getPredicate(),$this->current->getObject());
  202.     }
  203.     
  204.     /**
  205.     * Returns the key of the current item.
  206.     *
  207.     * @return    integer 
  208.     * @access    public
  209.     */
  210.     function key()
  211.     {
  212.         return $this->key;
  213.     }
  214. }
  215. ?>

Documentation generated on Mon, 26 Jun 2006 14:25:34 +0200 by phpDocumentor 1.3.0RC6