Source for file IteratorFindQuadsMem.php

Documentation is available at IteratorFindQuadsMem.php

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

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