Source for file Query.php

Documentation is available at Query.php

  1. <?php
  2. // ---------------------------------------------
  3. // class: Query
  4. // ---------------------------------------------
  5.  
  6. /**
  7. * The Class Query represents a SPARQL query.
  8. *
  9. *
  10. * <BR><BR>History:<UL>
  11. * <LI>08.09.2005: Initial version</LI>
  12. *
  13. * @author Tobias Gauss <tobias.gauss@web.de>
  14. * @version 0.9.3
  15. *
  16. * @package sparql
  17. */
  18.  
  19. Class Query extends Object {
  20.  
  21. /**
  22. * @var string The BASE part of the SPARQL query.
  23. */
  24. private $base;
  25.  
  26. /**
  27. * @var array Array that vontains used prefixes and namespaces.
  28. */
  29. public $prefixes = array();
  30.  
  31. /**
  32. * @var array List of result variables.
  33. */
  34. private $resultVars = array();
  35.  
  36. /**
  37. * The result form of the query.
  38. */
  39. private $resultForm;
  40.  
  41. /**
  42. * Contains the result part of the SPARQL query.
  43. */
  44. private $resultPart;
  45.  
  46. /**
  47. * @var array Contains the FROM part of the SPARQL query.
  48. */
  49. private $fromPart = array();
  50.  
  51. /**
  52. * @var array Contains the FROM NAMED part of the SPARQL query.
  53. */
  54. private $fromNamedPart = array();
  55.  
  56. /**
  57. * @var array Optional solution modifier of the query.
  58. */
  59. private $solutionModifier = array();
  60.  
  61. /**
  62. * @var int Blanknode counter.
  63. */
  64. private $bnodeCounter;
  65.  
  66. /**
  67. * @var int GraphPattern counter.
  68. */
  69. public $graphPatternCounter;
  70.  
  71. /**
  72. * @var array List of all vars used in the query.
  73. */
  74. public $usedVars;
  75.  
  76. /**
  77. * If the query type is CONSTRUCT this variable contains the
  78. * CONSTRUCT graph pattern.
  79. */
  80. private $constructPattern;
  81.  
  82. /**
  83. * @var boolean TRUE if the query is empty FALSE if not.
  84. */
  85. public $isEmpty;
  86.  
  87.  
  88. /**
  89. * Constructor
  90. */
  91. public function Query(){
  92. $this->resultForm = false;
  93. $this->solutionModifier[''order by''] = 0;
  94. $this->solutionModifier[''limit''] = 0;
  95. $this->solutionModifier[''offset''] = 0;
  96. $this->bnodeCounter = 0;
  97. $this->graphPatternCounter = 0;
  98.  
  99. }
  100.  
  101. /*
  102. * Returns the BASE part of the query.
  103. *
  104. * @return String
  105. */
  106. public function getBase(){
  107. return $this->base;
  108. }
  109.  
  110. /*
  111. * Returns the prefix map of the query.
  112. *
  113. * @return Array
  114. */
  115. public function getPrefixes(){
  116. return $this->prefixes;
  117. }
  118.  
  119. /*
  120. * Returns a list containing the result vars.
  121. *
  122. * @return Array
  123. */
  124. public function getResultVars(){
  125. return $this->resultVars;
  126. }
  127.  
  128. /*
  129. * Returns a list containing the result vars.
  130. *
  131. * @return Array
  132. */
  133. public function getResultForm(){
  134. return $this->resultForm;
  135. }
  136. /*
  137. * Returns a list containing the graph patterns of the query.
  138. *
  139. * @return Array
  140. */
  141. public function getResultPart(){
  142. return $this->resultPart;
  143. }
  144.  
  145. /*
  146. * Returns the FROM clause of the query.
  147. *
  148. * @return String
  149. */
  150. public function getFromPart(){
  151. return $this->fromPart;
  152. }
  153.  
  154. /*
  155. * Returns the FROM NAMED clause of the query.
  156. *
  157. * @return Array
  158. */
  159. public function getFromNamedPart(){
  160. return $this->fromNamedPart;
  161. }
  162.  
  163. /*
  164. * Returns the queries solution modifiers.
  165. * $solutionModifiers[''order by''] = value
  166. * [''limit''] = vlaue
  167. * [''offset''] = value
  168. *
  169. * @return Array
  170. */
  171. public function getSolutionModifiers(){
  172. return $this->solutionModifier;
  173. }
  174.  
  175. /**
  176. * Returns an unused Bnode label.
  177. *
  178. * @return String
  179. */
  180. public function getBlanknodeLabel(){
  181. return "_:bN".$this->bnodeCounter++;
  182. }
  183.  
  184.  
  185. /**
  186. * Sets the base part.
  187. *
  188. * @param String $base
  189. * @return void
  190. */
  191. public function setBase($base){
  192. $this->base = $base;
  193. }
  194.  
  195.  
  196. /**
  197. * Adds a prefix to the list of prefixes.
  198. *
  199. * @param String $prefix
  200. * @param String $label
  201. * @return void
  202. */
  203. public function addPrefix($prefix, $label){
  204. $this->prefixes[$prefix]= $label;
  205. }
  206.  
  207. /**
  208. * Adds a variable to the list of result variables.
  209. *
  210. * @param String $var
  211. * @return void
  212. */
  213. public function addVariable($var){
  214. $this->resultVars[]= $var;
  215. }
  216.  
  217.  
  218. /**
  219. * Sets the result form.
  220. *
  221. * @param String $form
  222. * @return void
  223. */
  224. public function setResultForm($form){
  225. $this->resultForm = $form;
  226. }
  227.  
  228. /**
  229. * Adds a graph pattern to the result part.
  230. *
  231. * @param GraphPattern $pattern
  232. * @return void
  233. */
  234. public function addGraphPattern($pattern){
  235. $pattern->setId($this->graphPatternCounter);
  236. $this->resultPart[] = $pattern;
  237. $this->graphPatternCounter++;
  238. }
  239.  
  240. /**
  241. * Adds a construct graph pattern to the query.
  242. *
  243. * @param GraphPattern $pattern
  244. * @return void
  245. */
  246. public function addConstructGraphPattern($pattern){
  247. $this->constructPattern = $pattern;
  248. }
  249.  
  250.  
  251. /**
  252. * Adds a graphuri to the from part.
  253. *
  254. * @param String $graphURI
  255. * @return void
  256. */
  257. public function addFrom($graphURI){
  258. $this->fromPart = $graphURI;
  259. }
  260.  
  261. /**
  262. * Adds a graphuri to the from named part.
  263. *
  264. * @param String $graphURI
  265. * @return void
  266. */
  267. public function addFromNamed($graphURI){
  268. $this->fromNamedPart[] = $graphURI;
  269. }
  270.  
  271. /**
  272. * Sets a solution modifier.
  273. *
  274. * @param String $name
  275. * @param Value $value
  276. * @return void
  277. */
  278. public function setSolutionModifier($name, $value){
  279. $this->solutionModifier[$name] = $value;
  280. }
  281.  
  282.  
  283. /**
  284. * Generates a new GraphPattern. If it is a CONSTRUCT graph pattern
  285. * $constr has to set to TRUE FALSE if not.
  286. *
  287. * @param boolean $constr
  288. * @return GraphPattern
  289. */
  290. public function getNewPattern($constr = false){
  291. $pattern = new GraphPattern();
  292. if($constr)
  293. $this->addConstructGraphPattern($pattern);
  294. else
  295. $this->addGraphPattern($pattern);
  296. return $pattern;
  297. }
  298.  
  299. /**
  300. * Adds a new variable to the variable list.
  301. *
  302. * @param String $var
  303. * @return void
  304. */
  305. public function addVar($var){
  306. $this->usedVars[$var]=true;
  307. }
  308.  
  309. /**
  310. * Returns a list with all used variables.
  311. *
  312. * @return Array
  313. */
  314. public function getAllVars(){
  315. return array_keys($this->usedVars);
  316. }
  317. /**
  318. * Gets the solution modifiers of the query.
  319. * $solutionModifiers[''order by''] = value
  320. * [''limit''] = vlaue
  321. * [''offset''] = value
  322. *
  323. *
  324. * @return Array
  325. */
  326. public function getSolutionModifier(){
  327. return $this->solutionModifier;
  328. }
  329.  
  330.  
  331. /**
  332. * Returns the constcutGraphPattern of the query if there is one.
  333. *
  334. * @return GraphPattern
  335. */
  336. public function getConstructPattern(){
  337. return $this->constructPattern;
  338. }
  339.  
  340.  
  341.  
  342.  
  343.  
  344. }
  345. // end class: Query.php
  346.  
  347. ?>

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