Source for file IteratorFindQuadsMem.php

Documentation is available at IteratorFindQuadsMem.php

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

Documentation generated on Fri, 1 Jun 2007 16:49:37 +0200 by phpDocumentor 1.3.2