Ejemplo n.º 1
0
 /**
  * This function parse a SPARQL query, send the query and parse the SPARQL result in a array. 
  * You can custom the result with the parameter $result_format : 
  * <ul>
  * <li>rows to return array of results
  * <li>row to return array of first result
  * <li>raw to return boolean for request ask, insert and delete
  * </ul>
  * @param string $q : Query SPARQL 
  * @param string $result_format : Optional,  rows, row or raw
  * @return array|boolean in function of parameter $result_format
  * @access public
  */
 public function query($q, $result_format = '')
 {
     $t1 = Endpoint::mtime();
     $response = $this->queryRead($q);
     xml_parse($this->_parserSparqlResult->getParser(), $response, true);
     $result = $this->_parserSparqlResult->getResult();
     $result['query_time'] = Endpoint::mtime() - $t1;
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * This function parse a SPARQL query, send the query and parse the SPARQL result in a array. 
  * You can custom the result with the parameter $result_format : 
  * <ul>
  * <li>rows to return array of results
  * <li>row to return array of first result
  * <li>raw to return boolean for request ask, insert and delete
  * </ul>
  * @param string $q : Query SPARQL 
  * @param string $result_format : Optional,  rows, row or raw
  * @return array|boolean in function of parameter $result_format
  * @access public
  */
 public function query($q, $result_format = 'rows')
 {
     $t1 = Endpoint::mtime();
     $result = null;
     switch ($result_format) {
         case "json":
             $response = $this->queryRead($q, "application/sparql-results+json");
             $result = json_decode($response);
             break;
         case "row":
         case "raw":
         default:
             //rows
             $response = "";
             if (preg_match("/(INSERT|DELETE|CLEAR|LOAD)/i", $q)) {
                 $response = $this->queryUpdate($q);
             } else {
                 $response = $this->queryRead($q);
             }
             $parser = $this->_parserSparqlResult->getParser();
             $success = xml_parse($parser, $response, true);
             $result = $this->_parserSparqlResult->getResult();
             if (!$success) {
                 //if(! array_key_exists("result",$result)){
                 $message = "Error parsing XML result:" . xml_error_string(xml_get_error_code($parser)) . ' Response : ' . $response . "\n";
                 $error = $this->errorLog($q, null, $this->_endpoint, 200, $message);
                 $this->addError($error);
                 return false;
             }
     }
     $result['query_time'] = Endpoint::mtime() - $t1;
     switch ($result_format) {
         case "row":
             return $result["result"]["rows"][0];
         case "raw":
             return $result["result"]["rows"][0][$result["result"]["variables"][0]];
         case "json":
         default:
             //rows
             return $result;
     }
 }