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

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