Karima Rafes has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/374797 )
Change subject: Update lib SPARQL ...................................................................... Update lib SPARQL Change-Id: I0dc0c88b173fc8c5052161428b24e3d35c33adb8 --- M vendor/bordercloud/sparql/.gitignore D vendor/bordercloud/sparql/Base.php D vendor/bordercloud/sparql/ConversionMimetype.php D vendor/bordercloud/sparql/Curl.php D vendor/bordercloud/sparql/Endpoint.php D vendor/bordercloud/sparql/Namespace.php D vendor/bordercloud/sparql/Net.php D vendor/bordercloud/sparql/ParserCSV.php D vendor/bordercloud/sparql/ParserSparqlResult.php D vendor/bordercloud/sparql/ParserTurtle.php M vendor/bordercloud/sparql/README.md D vendor/bordercloud/sparql/ToolsBlankNode.php D vendor/bordercloud/sparql/ToolsConvert.php M vendor/bordercloud/sparql/composer.json D vendor/bordercloud/sparql/query 15 files changed, 251 insertions(+), 3,163 deletions(-) Approvals: Karima Rafes: Verified; Looks good to me, approved jenkins-bot: Checked diff --git a/vendor/bordercloud/sparql/.gitignore b/vendor/bordercloud/sparql/.gitignore index 7eab032..e4cdcd5 100644 --- a/vendor/bordercloud/sparql/.gitignore +++ b/vendor/bordercloud/sparql/.gitignore @@ -1,5 +1,74 @@ -composer.lock -/output -/nbproject -/vendor -/nbproject/private/ +# External libraries +/vendor/ +/composer.phar + +# Configuration files with possibly sensitive information + +# Files and folders related to build/test tools + +# Ignore other .gitignore files to allow for personal customizations +.gitignore +!/.gitignore + +# Temporary files +.temp/ +tmp/ +output/ +doc_old/ + +# Files related to applying patches +*.rej +*.orig +*.patch +*.diff +.svn + + + +################# +## NetBeans specific +################# + +/nbproject/ +/nbbuild/ +/dist/ +/nbdist/ +/nbactions.xml +/nb-configuration.xml +/.nb-gradle/ + + + +################# +## Eclipse specific +################# + +*.pydevproject +.project +.metadata +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + +################# +## PHPStorm +################# +.idea/ diff --git a/vendor/bordercloud/sparql/Base.php b/vendor/bordercloud/sparql/Base.php deleted file mode 100644 index 745fbbd..0000000 --- a/vendor/bordercloud/sparql/Base.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php -/** - * @git g...@github.com:BorderCloud/SPARQL.git - * @author Karima Rafes <karima.ra...@bordercloud.com> - * @license http://creativecommons.org/licenses/by-sa/4.0/ -*/ -class Base { - - private $_errors; - private $_max_errors; - - function __construct() { - $this->_errors = array(); - $this->_max_errors = 25; - } - - function AddError($error) { - if (!in_array($error, $this->_errors)) { - $this->_errors[] = $error; - } - if (count($this->_errors) > $this->_max_errors) { - die('Too many errors (limit: ' . $this->_max_errors . '): ' . print_r($this->_errors, 1)); - } - return true; - } - - /** - * Give the errors - * @return array - * @access public - */ - function GetErrors() { - return $this->_errors; - } - - function ResetErrors() { - $this->_errors = array(); - } -} \ No newline at end of file diff --git a/vendor/bordercloud/sparql/ConversionMimetype.php b/vendor/bordercloud/sparql/ConversionMimetype.php deleted file mode 100644 index 84ec1d2..0000000 --- a/vendor/bordercloud/sparql/ConversionMimetype.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php -/** - * @git g...@github.com:BorderCloud/SPARQL.git - * @author Karima Rafes <karima.ra...@bordercloud.com> - * @license http://creativecommons.org/licenses/by-sa/4.0/ -*/ - -class ConversionMimetype { - - private static $_mimetypeToShortname; - private static $_filenameExtensionToMimetype; - - private static function init() - { - $_mimetypeToShortname = array(); - $_filenameExtensionToMimetype = array(); - self::add('rdf','rdf', 'application/rdf+xml'); - self::add('nt','text', 'text/plain'); - self::add('csv','csv', 'text/csv; charset=utf-8'); - self::add('','csv', 'text/csv'); - self::add('tsv','tsv', 'text/tab-separated-values; charset=utf-8'); - self::add('','tsv', 'text/tab-separated-values'); - self::add('ttl','ttl', 'text/turtle'); - self::add('srx','xml', 'application/sparql-results+xml'); - self::add('srj','json', 'application/sparql-results+json'); - } - - private static function add($extension, $shortname, $mimetype) - { - self::$_mimetypeToShortname[$mimetype] = $shortname; - - if(!EMPTY($extension)) - self::$_filenameExtensionToMimetype[$extension] = $mimetype; - } - - public static function getMimetypeOfFilenameExtensions($extension) - { - if (self::$_filenameExtensionToMimetype == null) - self::init(); - - if (array_key_exists($extension, self::$_filenameExtensionToMimetype)) { - return self::$_filenameExtensionToMimetype[$extension]; - }else{ - return NULL; - } - } - - public static function getShortnameOfMimetype($mimetype) - { - if (self::$_mimetypeToShortname == null) - self::init(); - - if (array_key_exists($mimetype, self::$_mimetypeToShortname)) { - return self::$_mimetypeToShortname[$mimetype]; - }else{ - return NULL; - } - } -} \ No newline at end of file diff --git a/vendor/bordercloud/sparql/Curl.php b/vendor/bordercloud/sparql/Curl.php deleted file mode 100644 index 6ab2856..0000000 --- a/vendor/bordercloud/sparql/Curl.php +++ /dev/null @@ -1,684 +0,0 @@ -<?php -/** - * @git g...@github.com:BorderCloud/SPARQL.git - * @author Karima Rafes <karima.ra...@bordercloud.com> - * @license http://creativecommons.org/licenses/by-sa/4.0/ -*/ - -class Curl -{ - /** - * Curl handler - * @access private - * @var resource - */ - var $ch ; - - /** - * set debug to true in order to get usefull output - * @access private - * @var string - */ - var $debug = false; - - /** - * Contain last error message if error occured - * @access private - * @var string - */ - var $error_msg; - - /** - * Curl_HTTP_Client constructor - * @param boolean debug - * @access public - */ - function __construct($debug = false) - { - $this->debug = $debug; - - // initialize curl handle - $this->ch = curl_init(); - - //set various options - - //set error in case http return code bigger than 300 - curl_setopt($this->ch, CURLOPT_FAILONERROR, true); - - // allow redirects - curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true); - - //hack to make code work on windows - //if(strpos(PHP_OS,"WIN") !== false) - { - curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0); - } - } - - /** - * Set username/pass for basic http auth - * @param string user - * @param string pass - * @access public - */ - function set_credentials($username,$password) - { - - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($this->ch, CURLOPT_USERPWD, $username.":".$password); - curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true); - } - - /** - * Set referrer - * @param string referrer url - * @access public - */ - function set_referrer($referrer_url) - { - curl_setopt($this->ch, CURLOPT_REFERER, $referrer_url); - } - - /** - * Set client's useragent - * @param string user agent - * @access public - */ - function set_user_agent($useragent) - { - curl_setopt($this->ch, CURLOPT_USERAGENT, $useragent); - } - - /** - * Set to receive output headers in all output functions - * @param boolean true to include all response headers with output, false otherwise - * @access public - */ - function include_response_headers($value) - { - curl_setopt($this->ch, CURLOPT_HEADER, $value); - } - - - /** - * Set proxy to use for each curl request - * @param string proxy - * @access public - */ - function set_proxy($proxy) - { - curl_setopt($this->ch, CURLOPT_PROXY, $proxy); - } - - /** - * Send post data to target URL - * return data returned from url or false if error occured - * @param string url - * @param array assoc post data array ie. $foo['post_var_name'] = $value - * @param string ip address to bind (default null) - * @param int timeout in sec for complete curl operation (default 600) - * @return string data - * @access public - */ - function send_post_data($url, $postdata, $arrayHeader=null, $ip=null, $timeout=600) - { - //set various curl options first - if($this->debug) - curl_setopt($this->ch, CURLOPT_VERBOSE, true); - - // set url to post to - curl_setopt($this->ch, CURLOPT_URL,$url); - - // return into a variable rather than displaying it - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); - - //bind to specific ip address if it is sent trough arguments - if($ip) - { - if($this->debug) - { - echo "Binding to ip $ip\n"; - } - curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); - } - - //set curl function timeout to $timeout - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); - - //set method to post - curl_setopt($this->ch, CURLOPT_POST, true); - - //generate post string - $post_array = array(); - if(!is_array($postdata)) - { - return false; - } - foreach($postdata as $key=>$value) - { - $post_array[] = urlencode($key) . "=" . urlencode($value); - } - - $post_string = implode("&",$post_array); - - if($this->debug) - { - curl_setopt($this->ch, CURLOPT_VERBOSE, true); - echo "Post String: $post_string\n"; - } - - // set post string - curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_string); - - // set header - if($arrayHeader != null) - curl_setopt($this->ch, CURLOPT_HTTPHEADER, $arrayHeader); - - //and finally send curl request - $result = curl_exec($this->ch); - - if(curl_errno($this->ch)) - { - if($this->debug) - { - echo "Error Occured in Curl\n"; - echo "Error number: " .curl_errno($this->ch) ."\n"; - echo "Error message: " .curl_error($this->ch)."\n"; - } - - return false; - } - else - { - return $result; - } - } - - /** - * fetch data from target URL - * return data returned from url or false if error occured - * @param string url - * @param array assoc get data array ie. $foo['post_var_name'] = $value - * @param string ip address to bind (default null) - * @param int timeout in sec for complete curl operation (default 600) - * @return string data - * @access public - */ - function fetch_url($url,$getdata=null, $ip=null, $timeout=600) - { - if($this->debug) - curl_setopt($this->ch, CURLOPT_VERBOSE, true); - - - //generate get string - $get_array = array(); - if(is_array($getdata)) - { - foreach($getdata as $key=>$value) - { - $get_array[] = urlencode($key) . "=" . urlencode($value); - } - $get_string = implode("&",$get_array); - - if($this->debug) - { - curl_setopt($this->ch, CURLOPT_VERBOSE, true); - echo "GET String: $get_string\n"; - } - } - else - { - $get_string = null; - } - - // set url to post to - if(empty($get_string)){ - curl_setopt($this->ch, CURLOPT_URL,$url); - }else{ - curl_setopt($this->ch, CURLOPT_URL,$url."?".$get_string); - } - - //set method to get - curl_setopt($this->ch, CURLOPT_HTTPGET,true); - - // return into a variable rather than displaying it - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); - - //bind to specific ip address if it is sent trough arguments - if($ip) - { - if($this->debug) - { - echo "Binding to ip $ip\n"; - } - curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); - } - - //set curl function timeout to $timeout - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); - - //and finally send curl request - $result = curl_exec($this->ch); - - if(curl_errno($this->ch)) - { - if($this->debug) - { - echo "Error Occured in Curl\n"; - echo "Error number: " .curl_errno($this->ch) ."\n"; - echo "Error message: " .curl_error($this->ch)."\n"; - } - - return false; - } - else - { - return $result; - } - } - - /** - * Fetch data from target URL - * and store it directly to file - * @param string url - * @param resource value stream resource(ie. fopen) - * @param string ip address to bind (default null) - * @param int timeout in sec for complete curl operation (default 5) - * @return boolean true on success false othervise - * @access public - */ - function fetch_into_file($url, $fp, $ip=null, $timeout=5) - { - if($this->debug) - curl_setopt($this->ch, CURLOPT_VERBOSE, true); - // set url to post to - curl_setopt($this->ch, CURLOPT_URL,$url); - - //set method to get - curl_setopt($this->ch, CURLOPT_HTTPGET, true); - - // store data into file rather than displaying it - curl_setopt($this->ch, CURLOPT_FILE, $fp); - - //bind to specific ip address if it is sent trough arguments - if($ip) - { - if($this->debug) - { - echo "Binding to ip $ip\n"; - } - curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); - } - - //set curl function timeout to $timeout - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); - - //and finally send curl request - $result = curl_exec($this->ch); - - if(curl_errno($this->ch)) - { - if($this->debug) - { - echo "Error Occured in Curl\n"; - echo "Error number: " .curl_errno($this->ch) ."\n"; - echo "Error message: " .curl_error($this->ch)."\n"; - } - - return false; - } - else - { - return true; - } - } - - /** - * Send multipart post data to the target URL - * return data returned from url or false if error occured - * (contribution by vule nikolic, v...@dinke.net) - * @param string url - * @param array assoc post data array ie. $foo['post_var_name'] = $value - * @param array assoc $file_field_array, contains file_field name = value - path pairs - * @param string ip address to bind (default null) - * @param int timeout in sec for complete curl operation (default 30 sec) - * @return string data - * @access public - */ - function send_multipart_post_data($url, $postdata, $file_field_array=array(), $ip=null, $timeout=30) - { - if($this->debug) - curl_setopt($this->ch, CURLOPT_VERBOSE, true); - //curl_setopt($this->ch, CURLOPT_VERBOSE, true); - //set various curl options first - - // set url to post to - curl_setopt($this->ch, CURLOPT_URL, $url); - - // return into a variable rather than displaying it - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); - - //bind to specific ip address if it is sent trough arguments - if($ip) - { - if($this->debug) - { - echo "Binding to ip $ip\n"; - } - curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); - } - - //set curl function timeout to $timeout - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); - - //set method to post - curl_setopt($this->ch, CURLOPT_POST, true); - - // disable Expect header - // hack to make it working - $headers = array("Expect: "); - curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers); - - // initialize result post array - $result_post = array(); - - //generate post string - $post_array = array(); - $post_string_array = array(); - if(!is_array($postdata)) - { - return false; - } - - foreach($postdata as $key=>$value) - { - $post_array[$key] = $value; - $post_string_array[] = urlencode($key)."=".urlencode($value); - } - - $post_string = implode("&",$post_string_array); - - - if($this->debug) - { - echo "Post String: $post_string\n"; - } - - // set post string - //curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_string); - - // set multipart form data - file array field-value pairs - if(!empty($file_field_array)) - { - foreach($file_field_array as $var_name => $var_value) - { - if(strpos(PHP_OS, "WIN") !== false) $var_value = str_replace("/", "\\", $var_value); // win hack - $file_field_array[$var_name] = "@".$var_value; - } - } - - // set post data - $result_post = array_merge($post_array, $file_field_array); - curl_setopt($this->ch, CURLOPT_POSTFIELDS, $result_post); - - - //and finally send curl request - $result = curl_exec($this->ch); - - if(curl_errno($this->ch)) - { - if($this->debug) - { - echo "Error Occured in Curl\n"; - echo "Error number: " .curl_errno($this->ch) ."\n"; - echo "Error message: " .curl_error($this->ch)."\n"; - } - - return false; - } - else - { - return $result; - } - } - - /** - * Set file location where cookie data will be stored and send on each new request - * @param string absolute path to cookie file (must be in writable dir) - * @access public - */ - function store_cookies($cookie_file) - { - // use cookies on each request (cookies stored in $cookie_file) - curl_setopt ($this->ch, CURLOPT_COOKIEJAR, $cookie_file); - } - - /** - * Get last URL info - * usefull when original url was redirected to other location - * @access public - * @return string url - */ - function get_effective_url() - { - return curl_getinfo($this->ch,CURLINFO_EFFECTIVE_URL); - } - - /** - * Get http response code - * @access public - * @return int - */ - function get_http_response_code() - { - return curl_getinfo($this->ch,CURLINFO_HTTP_CODE); - } - - function get_info() - { - return curl_getinfo($this->ch); - - } - - /** - * Return last error message and error number - * @return string error msg - * @access public - */ - function get_error_msg() - { - $err = "Error number: " .curl_errno($this->ch) ."\n"; - $err .="Error message: " .curl_error($this->ch)."\n"; - - return $err; - } - - function send_post_content($url, $headersdata,$postdata, $content, $ip=null, $timeout=10) - { - if($this->debug) - curl_setopt($this->ch, CURLOPT_VERBOSE, true); - //set various curl options first - - // set url to post to - curl_setopt($this->ch, CURLOPT_URL,$url); - - // return into a variable rather than displaying it - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); - - //bind to specific ip address if it is sent trough arguments - if($ip) - { - if($this->debug) - { - echo "Binding to ip $ip\n"; - } - curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); - } - - //set curl function timeout to $timeout - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); - - curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'POST'); - - //generate post string - $post_array = array(); - - if(count($postdata)> 0){ - foreach($postdata as $key=>$value) - { - $post_array[] = urlencode($key) . "=" . urlencode($value); - } - $post_array[] ="data=" . urlencode($content); - $post_string = implode("&",$post_array); - }else{ - $post_string=$content; - } - - if($this->debug) - { - echo "content String: $content\n"; - echo "header : ".print_r($headersdata,true)."\n"; - echo "Post String: $post_string\n"; - curl_setopt($this->ch, CURLOPT_VERBOSE, true); - } - - // set header - curl_setopt($this->ch, CURLOPT_HTTPHEADER, array_merge(array('Content-Length: ' . strlen($post_string)),$headersdata)); - - // set post string - curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_string); - - //and finally send curl request - $result = curl_exec($this->ch); - - if(curl_errno($this->ch)) - { - if($this->debug) - { - echo "Error Occured in Curl\n"; - echo "Error number: " .curl_errno($this->ch) ."\n"; - echo "Error message: " .curl_error($this->ch)."\n"; - } - - return false; - } - else - { - return $result; - } - } - - function send_put_data($url, $headersdata,$putdata, $ip=null, $timeout=10) - { - if($this->debug) - curl_setopt($this->ch, CURLOPT_VERBOSE, true); - //set various curl options first - - // set url to post to - curl_setopt($this->ch, CURLOPT_URL,$url); - - // return into a variable rather than displaying it - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); - - //bind to specific ip address if it is sent trough arguments - if($ip) - { - if($this->debug) - { - echo "Binding to ip $ip\n"; - } - curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); - } - - //set curl function timeout to $timeout - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); - - //set method to put - - curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'PUT'); - - if($this->debug) - { - echo "data String: $putdata\n"; - echo "header String: $headersdata\n"; - } - - // set header - curl_setopt($this->ch, CURLOPT_HTTPHEADER, array_merge(array('Content-Length: ' . strlen($putdata)),$headersdata)); - - // set post string - curl_setopt($this->ch, CURLOPT_POSTFIELDS, $putdata); - - //and finally send curl request - $result = curl_exec($this->ch); - - if(curl_errno($this->ch)) - { - if($this->debug) - { - echo "Error Occured in Curl\n"; - echo "Error number: " .curl_errno($this->ch) ."\n"; - echo "Error message: " .curl_error($this->ch)."\n"; - } - - return false; - } - else - { - return $result; - } - } - - - function send_delete($url, $ip=null, $timeout=10) - { - if($this->debug) - curl_setopt($this->ch, CURLOPT_VERBOSE, true); - //set various curl options first - - // set url to post to - curl_setopt($this->ch, CURLOPT_URL,$url); - - // return into a variable rather than displaying it - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); - - //bind to specific ip address if it is sent trough arguments - if($ip) - { - if($this->debug) - { - echo "Binding to ip $ip\n"; - } - curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); - } - - //set curl function timeout to $timeout - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); - - //set method to put - - curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "DELETE"); - - //and finally send curl request - $result = curl_exec($this->ch); - - if(curl_errno($this->ch)) - { - if($this->debug) - { - echo "Error Occured in Curl\n"; - echo "Error number: " .curl_errno($this->ch) ."\n"; - echo "Error message: " .curl_error($this->ch)."\n"; - } - - return false; - } - else - { - return $result; - } - } - -} diff --git a/vendor/bordercloud/sparql/Endpoint.php b/vendor/bordercloud/sparql/Endpoint.php deleted file mode 100644 index 88266bb..0000000 --- a/vendor/bordercloud/sparql/Endpoint.php +++ /dev/null @@ -1,686 +0,0 @@ -<?php -/** - * @git g...@github.com:BorderCloud/SPARQL.git - * @author Karima Rafes <karima.ra...@bordercloud.com> - * @license http://creativecommons.org/licenses/by-sa/4.0/ -*/ -require_once("Curl.php"); -require_once("Net.php"); -require_once("Base.php"); -require_once("ToolsConvert.php"); -require_once("ToolsBlankNode.php"); -require_once("ParserSparqlResult.php"); -require_once("ConversionMimetype.php"); - -/** - * Sparql HTTP Client for SPARQL1.1's Endpoint - * - * You can send a query to any endpoint sparql - * and read the result in an array. - * - * Example : send a simple query to DBpedia - * ```php - * <?php - * - * require_once('bordercloud/Endpoint.php'); - * - * $endpoint ="http://dbpedia.org/"; - * $sp_readonly = new Endpoint($endpoint); - * $q = "select * where {?x ?y ?z.} LIMIT 5"; - * $rows = $sp_readonly->query($q, 'rows'); - * $err = $sp_readonly->getErrors(); - * if ($err) { - * print_r($err); - * throw new Exception(print_r($err,true)); - * } - * - * foreach($rows["result"]["variables"] as $variable){ - * printf("%-20.20s",$variable); - * echo '|'; - * } - * echo "\n"; - * - * foreach ($rows["result"]["rows"] as $row){ - * foreach($rows["result"]["variables"] as $variable){ - * printf("%-20.20s",$row[$variable]); - * echo '|'; - * } - * echo "\n"; - * } - * ?> - * ``` - * - * For the different server, you can use the property setEndpointQuery, - * setEndpointUpdate,setNameParameterQueryRead or setNameParameterQueryWrite. - * - * EXAMPLE to config : Virtuoso - * ```php - * $sp_readonly = new Endpoint("http://localhost/tests/",$modeRead,$modeDebug); - * ``` - * - * EXAMPLE to config : 4Store - * ```php - * $sp_readonly = new Endpoint("http://localhost/",$modeRead,$modeDebug); - * ``` - * - * EXAMPLE to config : Sesame - * ```php - * $sp_readonly = new Endpoint("",$modeRead,$modeDebug); - * $sp_readonly->setEndpointQuery("http://localhost/openrdf-sesame/repositories/tests"); - * $sp_readonly->setEndpointUpdate("http://localhost/openrdf-sesame/repositories/tests/statements"); - * ``` - * - * EXAMPLE to config : Fuseki - * ```php - * $sp_readonly = new Endpoint("",$modeRead,$modeDebug); - * $sp_readonly->setEndpointQuery("http://localhost/tests/query"); - * $sp_readonly->setEndpointUpdate("http://localhost/tests/update"); - * ``` - * - * EXAMPLE to config : Allegrograph - * ```php - * $sp_readonly = new Endpoint("",$modeRead,$modeDebug); - * $sp_readonly->setEndpointQuery("http://localhost/repositories/tests"); - * $sp_readonly->setEndpointUpdate("http://localhost/repositories/tests"); - * $sp_readonly->setNameParameterQueryWrite("query"); - * ``` - * - * With a query ASK, you can use the parameter 'raw' - * in the function query and read directly the result true or false. - * - * Example : send a query ASK with the parameter raw - * ```php - * <?php - * $q = "PREFIX a: <http://example.com/test/a/> - * PREFIX b: <http://example.com/test/b/> - * ask where { GRAPH <".$graph."> {a:A b:Name \"Test3\" .}} "; - * $res = $sp_readonly->query($q, 'raw'); - * $err = $sp_readonly->getErrors(); - * if ($err) { - * print_r($err); - * throw new Exception(print_r($err,true)); - * } - * var_dump($res); - * ?> - * ``` - * - * You can insert data also with SPARQL and the function query in your graphs. - * The BorderCloud's service can host your graphs ( http://www.bordercloud.com ). - * You can choose your graph's name and Bordercloud will give you a code. - * With 3 parameters, you are alone to update your graph. - * - * Example : send a query Insert - * ```php - * $sp_write = new Endpoint($MyEndPointSparql,$MyCode,$MyGraph); - * echo "\nInsert :"; - * $q = " - * PREFIX a: <http://example.com/test/a/> - * PREFIX b: <http://example.com/test/b/> - * INSERT DATA { - * GRAPH <".$MyGraph."> { - * a:A b:Name \"Test1\" . - * a:A b:Name \"Test2\" . - * a:A b:Name \"Test3\" . - * }}"; - * $res = $sp_write->query($q,'raw'); - * $err = $sp_write->getErrors(); - * if ($err) { - * print_r($err); - * throw new Exception(print_r($err,true)); - * } - * var_dump($res); - * ``` - * - * Example : send a query Delete - * ```php - * $sp_write = new Endpoint($MyEndPointSparql,$MyCode,$MyGraph); - * - * echo "\nDelete :"; - * $q = " - * PREFIX a: <http://example.com/test/a/> - * PREFIX b: <http://example.com/test/b/> - * DELETE DATA { - * GRAPH <".$MyGraph."> { - * a:A b:Name \"Test2\" . - * }}"; - * - * $res = $sp_write->query($q,'raw'); - * $err = $sp_write->getErrors(); - * if ($err) { - * print_r($err); - * throw new Exception(print_r($err,true)); - * } - * var_dump($res); - * ``` - * - * You can change the format of the response with the function - * QueryRead and QueryUpdate. - */ -class Endpoint extends Base { - /** - * Root of the URL Endpoint - * @access private - * @var string - */ - private $_endpoint_root; - - /** - * URL of Endpoint to read - * @access private - * @var string - */ - private $_endpoint; - - /** - * URL sparql to write - * @access private - * @var string - */ - private $_endpoint_write; - - /** - * in the constructor set debug to true in order to get usefull output - * @access private - * @var bool - */ - private $_debug; - - /** - * in the constructor set the right to write or not in the store - * @access private - * @var string - */ - private $_readOnly; - - /** - * in the constructor set the proxy_host if necessary - * @access private - * @var string - */ - private $_proxy_host; - - /** - * in the constructor set the proxy_port if necessary - * @access private - * @var int - */ - private $_proxy_port; - - /** - * Parser of XML result - * @access private - * @var ParserSparqlResult - */ - private $_parserSparqlResult; - - /** - * Name of parameter HTTP to send a query SPARQL to read data. - * @access private - * @var string - */ - private $_nameParameterQueryRead; - - /** - * Name of parameter HTTP to send a query SPARQL to write data. - * @access private - * @var string - */ - private $_nameParameterQueryWrite; - - /** - * Method HTTP to send a query SPARQL to read data. - * @access private - * @var string - */ - private $_MethodHTTPRead; - private $_MethodHTTPWrite; - - - private $_login; - private $_password; - - - /** - * Constructor of Graph - * @param string $endpoint : url of endpoint, example : http://lod.bordercloud.com/sparql - * @param boolean $readOnly : true by default, if you allow the function query to write in the database - * @param boolean $debug : false by default, set debug to true in order to get usefull output - * @param string $proxy_host : null by default, IP of your proxy - * @param string $proxy_port : null by default, port of your proxy - * @access public - */ - public function __construct($endpoint, - $readOnly = true, - $debug = false, - $proxy_host = null, - $proxy_port = null) - { - parent::__construct(); - - if($readOnly){ - $this->_endpoint = $endpoint; - }else{ - if (preg_match("|/sparql/?$|i", $endpoint)) { - $this->_endpoint = $endpoint; - $this->_endpoint_root = preg_replace("|^(.*/)sparql/?$|i", "$1", $endpoint); - } else { - $this->_endpoint_root = $endpoint; - $this->_endpoint = $this->_endpoint_root."sparql/"; - } - } - - $this->_debug = $debug; - $this->_endpoint_write = $this->_endpoint_root."update/"; - $this->_readOnly = $readOnly; - - $this->_proxy_host = $proxy_host; - $this->_proxy_port = $proxy_port; - - if($this->_proxy_host != null && $this->_proxy_port != null){ - $this->_config = array( - /* remote endpoint */ - 'remote_store_endpoint' => $this->_endpoint, - /* network */ - 'proxy_host' => $this->_proxy_host, - 'proxy_port' => $this->_proxy_port, - ); - }else{ - $this->_config = array( - /* remote endpoint */ - 'remote_store_endpoint' => $this->_endpoint, - ); - } - - // init parameter in the standard - $this->_nameParameterQueryRead = "query"; - $this->_nameParameterQueryWrite = "update"; - - //init parser - $this->_parserSparqlResult = new ParserSparqlResult(); - - //FIX for Wikidata - if( $endpoint == "https://query.wikidata.org/sparql"){ - $this->_MethodHTTPRead= "GET"; - }else{ - $this->_MethodHTTPRead= "POST"; // by default - } - - } - - //FIX for WIKIDATA - /** - * Set the method HTTP to read - * @param string $method : HTTP method (GET or POST) for reading data (by default is POST) - * @access public - */ - public function setMethodHTTPRead($method) { - $this->_MethodHTTPRead = $method; - } - - /** - * Set the method HTTP to write - * @param string $method : HTTP method (GET or POST) for writing data (by default is POST) - * @access public - */ - public function setMethodHTTPWrite($method) { - $this->_MethodHTTPWrite = $method; - } - - /** - * Set the url to read - * @param string $url : endpoint's url to read - * @access public - */ - public function setEndpointQuery($url) { - $this->_endpoint = $url; - } - - /** - * Get the url to read - * @return string $url : endpoint's url to read - * @access public - */ - public function getEndpointQuery() { - return $this->_endpoint; - } - - /** - * Set the url to write - * @param string $url : endpoint's url to write - * @access public - */ - public function setEndpointUpdate($url) { - $this->_endpoint_write = $url; - } - - /** - * Get the url to write - * @return string $url : endpoint's url to write - * @access public - */ - public function getEndpointUpdate() { - return $this->_endpoint_write; - } - - /** - * Set the parameter in the query to write - * @param string $name : name of parameter - * @access public - */ - public function setNameParameterQueryWrite($name) { - $this->_nameParameterQueryWrite = $name; - } - - /** - * Get the parameter in the query to write - * @return string $name : name of parameter - * @access public - */ - public function getNameParameterQueryWrite() { - return $this->_nameparameterQueryWrite; - } - - /** - * Set the parameter in the query to read - * @param string $name : name of parameter - * @access public - */ - public function setNameParameterQueryRead($name) { - $this->_nameParameterQueryRead = $name; - } - - /** - * Get the parameter in the query to read - * @return string $name : name of parameter - * @access public - */ - public function getNameParameterQueryRead() { - return $this->_nameparameterQueryRead; - } - - /** - * Set the server login - * @param string $login : server login - * @access public - */ - public function setLogin($login) { - $this->_login = $login; - } - - /** - * Get the server login - * @return string $login : server login - * @access public - */ - public function getLogin() { - return $this->_login; - } - - /** - * Set the server password - * @param string $password : server password - * @access public - */ - public function setPassword($password) { - $this->_password = $password; - } - - /** - * Get the server login - * @return string $password : server password - * @access public - */ - public function getPassword() { - return $this->_password; - } - - /** - * Check if the server is up. - * @return boolean true if the triplestore is up. - * @access public - */ - public function check() { - return Net::ping($this->_endpoint) != -1; - } - - /** - * 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; - } - } -/* - public function queryConstruct($q) { - $t1 = Endpoint::mtime(); - $result = null; - - $response = $this->queryRead($q,"text/turtle"); - return $response; - $result = ParserTurtle::turtle_to_array($response,""); - - $result['query_time'] = Endpoint::mtime() - $t1 ; - - return $result; - } - */ - - /** - * Send a request SPARQL of type select or ask to endpoint directly and output the response - * of server. If you want parse the result of this function, it's better and simpler - * to use the function query(). - * - * @param string $query : Query Sparql - * @param string $typeOutput by default "application/sparql-results+xml", - * @return string response of server or false if error (to do getErrors()) - * @access public - */ - public function queryRead($query,$typeOutput="application/sparql-results+xml" ) { - $client = $this->initCurl(); - $sUri = $this->_endpoint; - $response =""; - - if($typeOutput == null){ - $data = array($this->_nameParameterQueryRead => $query); - if($this->_MethodHTTPRead == "POST"){ - $response = $client->send_post_data($sUri,$data); - }else{ - $response = $client->fetch_url($sUri,$data);//fix for wikidata - } - }else{ - $data = array($this->_nameParameterQueryRead => $query, - "output" => ConversionMimetype::getShortnameOfMimetype($typeOutput), //possible fix for 4store/fuseki.. - "Accept" => $typeOutput); //fix for sesame - //print_r($data); - if($this->_MethodHTTPRead == "POST"){ - $response = $client->send_post_data($sUri,$data,array('Accept: '.$typeOutput)); - }else{ - $response = $client->fetch_url($sUri,$data);//fix for wikidata - } - } - - $code = $client->get_http_response_code(); - - $this->debugLog($query,$sUri,$code,$response); - - if(($code < 200 || $code >= 300) ) - { - $error = $this->errorLog($query,$data,$sUri,$code,$response. - $client->get_error_msg() ); - $this->addError($error); - return false; - } - return $response; - } - - /** - * Send a request SPARQL of type insert data or delete data to endpoint directly. - * <ul> - * <li>Example insert : PREFIX ex: <http://example.com/> INSERT DATA { GRAPH <http://mygraph> { ex:a ex:p 12 .}} - * <li>Example delete : PREFIX ex: <http://example.com/> DELETE DATA { GRAPH <http://mygraph> { ex:a ex:p 12 .}} - * </ul> - * @param string $query : Query Sparql of type insert data or delete data only - * @param string $typeOutput by default "application/sparql-results+xml", - * @return boolean true if it did or false if error (to do getErrors()) - * @access public - */ - public function queryUpdate($query,$typeOutput="application/sparql-results+xml") { - if($this->_readOnly){ - $message = "Sorry, you have not the right to update the database.\n"; - $error = $this->errorLog('',null, $this->_endpoint,0,$message); - $this->addError($error); - return false; - } - - $client = $this->initCurl(); - $sUri = $this->_endpoint_write; - $response =""; - - if($typeOutput == null){ - $data = array($this->_nameParameterQueryWrite => $query); - if($this->_MethodHTTPWrite == "POST"){ - $response = $client->send_post_data($sUri,$data); - }else{ - $response = $client->fetch_url($sUri,$data);//fix for wikidata - } - }else{ - $data = array($this->_nameParameterQueryWrite => $query, - //"output" => ConversionMimetype::getShortnameOfMimetype($typeOutput), //possible fix for 4store/fuseki.. - "Accept" => $typeOutput); //fix for sesame - //print_r($data); - if($this->_MethodHTTPWrite == "POST"){ - $response = $client->send_post_data($sUri,$data,array('Accept: '.$typeOutput)); - }else{ - $response = $client->fetch_url($sUri,$data);//fix for wikidata - } - } - - $code = $client->get_http_response_code(); - - $this->debugLog($query,$sUri,$code,$response); - - if($code < 200 || $code >= 300 ){ - $error = $this->errorLog($query,$data,$sUri,$code,$response); - $this->addError($error); - return false; - } - //echo "OK".$response; - return $response; - } - - /************************************************************************/ - //PRIVATE Function - - static function mtime(){ - list($msec, $sec) = explode(" ", microtime()); - return ((float)$msec + (float)$sec); - } - - /** - * write error for human - * @param string $query - * @param string $endPoint - * @param number $httpcode - * @param string $response - * @access private - */ - private function errorLog($query,$data,$endPoint,$httpcode=0,$response=''){ - $error = "Error query : " .$query."\n" . - "Error endpoint: " .$endPoint."\n" . - "Error http_response_code: " .$httpcode."\n" . - "Error message: " .$response."\n"; - "Error data: " .print_r($data,true)."\n"; - if($this->_debug){ - echo '=========================>>>>>>'.$error ; - }else{ - error_log($error); - } - return $error; - } - - /** - * Print infos - * @param unknown_type $query - * @param unknown_type $endPoint - * @param unknown_type $httpcode - * @param unknown_type $response - * @access private - */ - private function debugLog($query,$endPoint,$httpcode='',$response=''){ - if($this->_debug) - { - $error = "\n#######################\n". - "query : " .$query."\n" . - "endpoint : " .$endPoint."\n" . - "http_response_code : " .$httpcode."\n" . - "message : " .$response. - "\n#######################\n"; - - echo $error ; - } - } - - /** - * Init an object Curl in function of proxy. - * @return an object of type Curl - * @access private - */ - private function initCurl(){ - $objCurl = new Curl();//$this->_debug - if($this->_proxy_host != null && $this->_proxy_port != null){ - $objCurl->set_proxy($this->_proxy_host.":".$this->_proxy_port); - } - if($this->_login != null && $this->_password != null){ - $objCurl->set_credentials($this->_login,$this->_password); - } - return $objCurl; - } -} diff --git a/vendor/bordercloud/sparql/Namespace.php b/vendor/bordercloud/sparql/Namespace.php deleted file mode 100644 index 4be54ed..0000000 --- a/vendor/bordercloud/sparql/Namespace.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php -/** - * @git g...@github.com:BorderCloud/SPARQL.git - * @author Karima Rafes <karima.ra...@bordercloud.com> - * @license http://creativecommons.org/licenses/by-sa/4.0/ -*/ - -class FourStore_Namespace { - - protected static $_namespaces = array(); - - public static function addW3CNamespace() - { - self::add('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); - self::add('rdfs', 'http://www.w3.org/2000/01/rdf-schema#'); - self::add('xsd', 'http://www.w3.org/2001/XMLSchema#'); - } - - public static function add($short, $long) - { - self::$_namespaces[$short] = $long; - } - - public static function get($short) - { - return self::$_namespaces[$short]; - } - - public static function to_sparql() { - $sparql = ""; - foreach(self::$_namespaces as $short => $long) { - $sparql .= "PREFIX $short: <$long>\n"; - } - return $sparql; - } - - public static function to_turtle() { - $turtle = ""; - foreach(self::$_namespaces as $short => $long) { - $turtle .= "@prefix $short: <$long> .\n"; - } - return $turtle; - } -} - -?> diff --git a/vendor/bordercloud/sparql/Net.php b/vendor/bordercloud/sparql/Net.php deleted file mode 100644 index e240ff4..0000000 --- a/vendor/bordercloud/sparql/Net.php +++ /dev/null @@ -1,63 +0,0 @@ -<?php -/** - * @git g...@github.com:BorderCloud/SPARQL.git - * @author Karima Rafes <karima.ra...@bordercloud.com> - * @license http://creativecommons.org/licenses/by-sa/4.0/ -*/ - -class Net { - - /** - * Ping a address - * @return int if -1 the server is down - * @access public - */ - static function ping($address){ - $urlInfo = parse_url($address); - $domain = $urlInfo['host']; - $port = Net::getUrlPort( $urlInfo ); - $starttime = microtime(true); - $file = @fsockopen ($domain,$port, $errno, $errstr, 10); - $stoptime = microtime(true); - $status = 0; - - if (!$file) $status = -1; // Site is down - else { - fclose($file); - $status = ($stoptime - $starttime) * 1000; - $status = floor($status); - } - return $status; - } - - private static function getUrlPort( $urlInfo ) - { - if( isset($urlInfo['port']) ) { - $port = $urlInfo['port']; - } else { // no port specified; get default port - if (isset($urlInfo['scheme']) ) { - switch( $urlInfo['scheme'] ) { - case 'http': - $port = 80; // default for http - break; - case 'https': - $port = 443; // default for https - break; - case 'ftp': - $port = 21; // default for ftp - break; - case 'ftps': - $port = 990; // default for ftps - break; - default: - $port = 0; // error; unsupported scheme - break; - } - } else { - $port = 0; // error; unknown scheme - } - } - return $port; - } -} - diff --git a/vendor/bordercloud/sparql/ParserCSV.php b/vendor/bordercloud/sparql/ParserCSV.php deleted file mode 100644 index 3409fca..0000000 --- a/vendor/bordercloud/sparql/ParserCSV.php +++ /dev/null @@ -1,204 +0,0 @@ - <?php -/** - * @git g...@github.com:BorderCloud/SPARQL.git - * @author Karima Rafes <karima.ra...@bordercloud.com> - * @license http://creativecommons.org/licenses/by-sa/4.0/ -*/ - -class ParserCSV { - - function csv_to_array($csv, $delimiter = ',', $enclosure = '\'', $escape = '\\', $terminator = "\n") { - - $r = array(); - //$string = utf8_encode($csv); - //echo mb_detect_encoding($names); - //echo $csv; - $rows = explode($terminator,trim($csv)); - $names = array_shift($rows); - $names = str_getcsv($names,$delimiter,$enclosure,$escape) ; - $nc = count($names); - foreach ($rows as $row) { - if (trim($row)) { - $values =str_getcsv($row,$delimiter,$enclosure,$escape) ; - - if (!$values) $values = array_fill(0,$nc,null); - - $tabTemp = array(); - //array_combine($names,$values); - foreach($names as $key=>$nameCol){ - if(isset($values[$key])){ - - $value = $values[$key]; - if (ToolsConvert::isTrueFloat($value)) { - $value = floatval($value); - } elseif (is_int($value)) { - $value = intval($value); - } - $tabTemp[$nameCol] = $value; - }else{ - $tabTemp[$nameCol] = NULL; - } - } - $r[] = $tabTemp; - - } - } - return $r; - } - - function mySortAllColumn($row1, $row2){ - $result = 0; - $countTab = 0; - if( count($row1) > count($row2)){ - $countTab = count($row1); - }else{ - $countTab = count($row2); - } - - for($i=0; $i < $countTab; $i++){ - if((!isset($row1[$i])) || (!isset($row2[$i]))){ - if(isset($row1[$i]) && isset($row2[$i])){//impossible in theory - $result = 0; - break; - }elseif(!isset($row1[$i])){ - $result = -1; - break; - }elseif(!isset($row2[$i])){ - $result = 1; - break; - } - } - else if($row1[$i] < $row2[$i]){ - $result = 1; - break; - } - else if($row1[$i] < $row2[$i]){ - $result = -1; - break; - } - } - return $result; - } - - function sortTable($array){ - $result = $array; - usort($result, 'ParserCSV::mySortAllColumn'); - return $result; - } - - public static function compare($rs1,$rs2,$ordered=false,$distinct=false) { - $difference=array(); - //A/ Check the variables lists in the header are the same. - if(count($rs1) ==0 && count($rs2) ==0){ - return $difference; //return true ; - }elseif (count($rs1[0]) != count($rs2[0])) { - $difference[1]="Nb columns :".count($rows1); - $difference[2]="Nb columns :".count($rows2); - return $difference; //return false ; - } - - - //Check if there are blanknodes////////////////////// - //ref : http://blog.datagraph.org/2010/03/rdf-isomorphism - - // 1.Compare graph sizes and all statements without blank nodes. If they do not match, fail. - //1.1 remove blank nodes - $clone1WithoutBlanknodes = NULL; - $clone2WithoutBlanknodes = NULL; - if($distinct){ - $clone1WithoutBlanknodes = $rs1; - $clone2WithoutBlanknodes = $rs2; - }else{ - $clone1WithoutBlanknodes = ToolsBlankNode::removeDuplicate($rs1); - $clone2WithoutBlanknodes = ToolsBlankNode::removeDuplicate($rs2); - } - - $bnodesInRs1=array(); - $bnodesInRs2=array(); - $patternBlankNode = '/^_:/'; - - // echo "AVANT"; - // print_r($clone1); - // print_r($clone2); - foreach ($clone1WithoutBlanknodes as &$row) { - foreach ($row as $key=>&$value) { - if (preg_match($patternBlankNode, $value)) { - $bnodesInRs1[] = $value ; - $value = "BLANKNODE";//remove - } - } - } - foreach ($clone2WithoutBlanknodes as &$row) { - foreach ($row as $key=>&$value) { - if (preg_match($patternBlankNode, $value)) { - $bnodesInRs2[] = $value ; - $value = "BLANKNODE";//remove - } - } - } - - // print_r($clone1WithoutBlanknodes); - //print_r($clone2WithoutBlanknodes); - //exit(); - //1.2 compare - if($ordered){ - $difference = ToolsBlankNode::array_diff_assoc_recursive( $clone1WithoutBlanknodes, $clone2WithoutBlanknodes); - }else{ - $difference = ToolsBlankNode::array_diff_assoc_unordered( $clone1WithoutBlanknodes, $clone2WithoutBlanknodes) ; - } - - //Check if there are blank nodes - if((count($bnodesInRs1) == 0 && count($bnodesInRs2) == 0 ) || count($difference) != 0) - return $difference; - - //With blank nodes - $bnodesInRs1=array_values(array_unique($bnodesInRs1)); - $bnodesInRs2=array_values(array_unique($bnodesInRs2)); - if(count($bnodesInRs1) != count($bnodesInRs2)) { - $difference[1]="Nb bnode :".count($bnodesInRs1); - $difference[2]="Nb bnode :".count($bnodesInRs2); - return $difference; //return false ; - } - -// echo "BLANKNODE\n"; -// print_r($bnodesInRs1); -// print_r($bnodesInRs2); - - $clone1 = $rs1; -// print_r($clone1); - - // 2.Repeat, for each graph: - $arrayPermutationsBnode = ToolsBlankNode::AllPermutations($bnodesInRs2); - //echo "PERMUTATION\n"; - //print_r($arrayPermutationsBnode ); - //exit(); - foreach ( $arrayPermutationsBnode as $permute) { -// print_r($permute); - $clone2 = $rs2; - foreach ( $clone2 as $key=>&$row) { - $arrayVariableTypeBnode = array_keys( $row , "bnode") ; - foreach ($arrayVariableTypeBnode as $variableTypeBnode) { - $variableArray = split(" ",$variableTypeBnode); - $variable=$variableArray[0]; - - $row[$variable] = $bnodesInRs1[array_search($row[$variable] ,$permute)]; - } - } - -// print_r($clone2); - - if($ordered){ - $difference = ToolsBlankNode::array_diff_assoc_recursive( $clone1WithoutBlanknodes, $clone2WithoutBlanknodes); - }else{ - $difference = ToolsBlankNode::array_diff_assoc_unordered( $clone1WithoutBlanknodes, $clone2WithoutBlanknodes) ; - } - if(count($difference) == 0){ - return $difference; //true - } - } - - return $difference; - } - - -} diff --git a/vendor/bordercloud/sparql/ParserSparqlResult.php b/vendor/bordercloud/sparql/ParserSparqlResult.php deleted file mode 100644 index ae5fa4f..0000000 --- a/vendor/bordercloud/sparql/ParserSparqlResult.php +++ /dev/null @@ -1,320 +0,0 @@ -<?php -/** - * @git g...@github.com:BorderCloud/SPARQL.git - * @author Karima Rafes <karima.ra...@bordercloud.com> - * @license http://creativecommons.org/licenses/by-sa/4.0/ -*/ - -class ParserSparqlResult extends Base { - private $_result; - private $_rowCurrent; - private $_cellCurrent; - private $_value; - - function __construct() { - parent::__construct(); - $this->_result = array(); - } - - function getParser(){ - $objectParser = xml_parser_create(); - xml_set_object ($objectParser, $this); - - //Don't alter the case of the data - xml_parser_set_option($objectParser, XML_OPTION_CASE_FOLDING, false); - - xml_set_element_handler($objectParser,"startElement","endElement"); - xml_set_character_data_handler($objectParser, "contentHandler"); - return $objectParser; - } - - function getResult(){ - return $this->_result; - } - - //callback for the start of each element - function startElement($parser_object, $elementname, $attribute) { - if($elementname == "sparql"){ - $this->_result['result'] = array(); - }else if($elementname == "head"){ - $this->_result['result']['variables'] = array(); - }else if($elementname == "variable"){ - $this->_result['result']['variables'][] = $attribute['name']; - }else if($elementname == "results"){ - $this->_rowCurrent = -1; - $this->_result['result']['rows'] = array(); - }else if($elementname == "result"){ - $this->_rowCurrent++; - $this->_result['result']['rows'][] = array(); - }else if($elementname == "binding"){ - $this->_value = ""; - $this->_cellCurrent = $attribute['name']; - }else if($this->_cellCurrent != null){ - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent." type"] = $elementname; - - if(isset($attribute['xml:lang'])) - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent." lang"] = $attribute['xml:lang']; - - if(isset($attribute['datatype'])) - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent." datatype"] = $attribute['datatype']; - } - } - - //callback for the end of each element - function endElement($parser_object, $elementname) { - if($elementname == "binding"){ - - if(strlen(trim($this->_value)) == 0) - return; - - if(!isset($this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent." type"])) - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent." type"]=NULL; - - if($this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent." type"] == "uri"){ - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent] = trim($this->_value); - }elseif($this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent." type"] == "bnode"){ - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent] = trim($this->_value); - }elseif($this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent." type"] == "literal"){ - $value = trim($this->_value); - if(array_key_exists($this->_cellCurrent." datatype",$this->_result['result']['rows'][$this->_rowCurrent])){ - if($this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent." datatype"] == "http://www.w3.org/2001/XMLSchema#double" || - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent." datatype"] == "http://www.w3.org/2001/XMLSchema#decimal" - ){ - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent] = floatval($value); - }elseif($this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent." datatype"] == "http://www.w3.org/2001/XMLSchema#integer" - ){ - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent] = intval($value); - }elseif($this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent." datatype"] == "http://www.w3.org/2001/XMLSchema#boolean" - ){ - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent] = $value === "true" ? true : false; - }else{ - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent] = $value; - } - }else{ - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent] = $value; - } - }else{ - $this->_result['result']['rows'][$this->_rowCurrent][$this->_cellCurrent] = $this->_value; - } - $this->_cellCurrent = null; - $this->_value = ""; - } - } - - //callback for the content within an element - function contentHandler($parser_object,$data) - { - if($this->_cellCurrent != null){ - // echo "DATA". $data." - ".$this->_cellCurrent."\n"; - $this->_value .= $data; - } - } - - function sortResult($array){ - $result = $array; - if(isset($result['result']['rows'])) - usort($result['result']['rows'], 'ParserSparqlResult::mySortResult'); - return $result; - } - - function mySortResult($row1, $row2){ - $result = 0; - $countTab = 0; - if( count($row1) > count($row2)){ - $countTab = count($row1); - }else{ - $countTab = count($row2); - } - - for($i=0; $i < $countTab; $i++){ - if((!isset($row1[$i])) || (!isset($row2[$i]))){ - if(isset($row1[$i]) && isset($row2[$i])){//impossible in theory - $result = 0; - break; - }elseif(!isset($row1[$i])){ - $result = -1; - break; - }elseif(!isset($row2[$i])){ - $result = 1; - break; - } - } - else if($row1[$i] < $row2[$i]){ - $result = 1; - break; - } - else if($row1[$i] < $row2[$i]){ - $result = -1; - break; - } - } - return $result; - } - - public static function compare($rs1,$rs2,$ordered=false,$distinct=false) { - $difference=array(); - //A/ Check the variables lists in the header are the same. - if(! isset($rs1['result']['variables']) && ! isset($rs2['result']['variables'])){ - return $difference; //return true ; - }elseif (! isset($rs1['result']['variables']) || ! isset($rs2['result']['variables']) ) { - $difference[1]=$rs1['result']['variables']; - $difference[2]=$rs2['result']['variables']; - return $difference; //return false ; - } - - //Check if there are blanknodes////////////////////// - //ref : http://blog.datagraph.org/2010/03/rdf-isomorphism - -// 1.Compare graph sizes and all statements without blank nodes. If they do not match, fail. -//1.1 remove blank nodes - $clone1WithoutBlanknodes = NULL; - $clone2WithoutBlanknodes = NULL; - if($distinct){ - $clone1WithoutBlanknodes = $rs1['result']['rows']; - $clone2WithoutBlanknodes = $rs2['result']['rows']; - }else{ - $clone1WithoutBlanknodes = ToolsBlankNode::removeDuplicate($rs1['result']['rows']); - $clone2WithoutBlanknodes = ToolsBlankNode::removeDuplicate($rs2['result']['rows']); - } - - $bnodesInRs1=array(); - $bnodesInRs2=array(); - - // echo "AVANT"; - // print_r($clone1); - // print_r($clone2); - foreach ($clone1WithoutBlanknodes as $key=>&$row) { - $arrayVariableTypeBnode = array_keys( $row , "bnode") ; - foreach ($arrayVariableTypeBnode as $variableTypeBnode) { - $variableArray = split(" ",$variableTypeBnode); - $variable=$variableArray[0]; - $bnodesInRs1[] = $row[$variable] ; - $row[$variable] = "BLANKNODE";//remove - } - } - foreach ( $clone2WithoutBlanknodes as $key=>&$row) { - $arrayVariableTypeBnode = array_keys( $row , "bnode") ; - foreach ($arrayVariableTypeBnode as $variableTypeBnode) { - $variableArray = split(" ",$variableTypeBnode); - $variable=$variableArray[0]; - $bnodesInRs2[] = $row[$variable] ; - $row[$variable] = "BLANKNODE";//remove - } - } - - //print_r($clone1WithoutBlanknodes); - //print_r($clone2WithoutBlanknodes); -//1.2 compare - if($ordered){ - $difference = ToolsBlankNode::array_diff_assoc_recursive( $clone1WithoutBlanknodes, $clone2WithoutBlanknodes); - }else{ - $difference = ToolsBlankNode::array_diff_assoc_unordered( $clone1WithoutBlanknodes, $clone2WithoutBlanknodes) ; - } - - //Check if there are blank nodes - if((count($bnodesInRs1) == 0 && count($bnodesInRs2) == 0 ) || count($difference) != 0) - return $difference; - - //With blank nodes - $bnodesInRs1=array_values(array_unique($bnodesInRs1)); - $bnodesInRs2=array_values(array_unique($bnodesInRs2)); - if(count($bnodesInRs1) != count($bnodesInRs2)) { - $difference[1]="Nb bnode :".count($bnodesInRs1); - $difference[2]="Nb bnode :".count($bnodesInRs2); - return $difference; //return false ; - } - -// echo "BLANKNODE\n"; -// print_r($bnodesInRs1); -// print_r($bnodesInRs2); - $clone1 = $rs1['result']['rows']; - // print_r($clone1); - //$clone2 = $rs2['result']['rows']; - // 2.Repeat, for each graph: - $arrayPermutationsBnode = ToolsBlankNode::AllPermutations($bnodesInRs2); - //echo "PERMUTATION\n"; - //print_r($arrayPermutationsBnode ); - // exit(); - foreach ( $arrayPermutationsBnode as $permute) { - $clone2 = $rs2['result']['rows']; - - //print_r($clone2); - foreach ( $clone2 as $key=>&$row) { - $arrayVariableTypeBnode = array_keys( $row , "bnode") ; - foreach ($arrayVariableTypeBnode as $variableTypeBnode) { - $variableArray = split(" ",$variableTypeBnode); - $variable=$variableArray[0]; - - $row[$variable] = $bnodesInRs1[array_search($row[$variable] ,$permute)]; - } - } - //print_r($clone2); - //$difference = self::sub_array_diff_assoc_unordered( $clone1,$clone2) ; - if($ordered){ - $difference = ToolsBlankNode::array_diff_assoc_recursive($clone1,$clone2); - }else{ - $difference = ToolsBlankNode::array_diff_assoc_unordered($clone1,$clone2) ; - } - - if(count($difference) == 0){ - return $difference; //true - } - } - - return $difference; - } -/* - private static function sub_array_diff_assoc_unordered( $rows1, $rows2) { - $difference=array(); - - //B/ Check the result set have the same number of rows. - if(count($rows1) != count($rows2)) { - $difference[1]="Nb rows :".count($rows1); - $difference[2]="Nb rows :".count($rows2); - return $difference; //return false ; - } - - //C/ Pick a row from the test results, scan the expected results - // to find a row with same variable/value bindings, and remove - // from the expected results. If all test rows, match then - // (because of B) the result sets have the same rows. - // - //return equivalent(convert(rs1), convert(rs2), new BNodeIso(NodeUtils.sameValue)) ; - $clone1 = $rows1; - $clone2 = $rows2; - - // echo "AVANT"; - // print_r($clone1); - // print_r($clone2); - foreach ($rows1 as $key1=>&$value1) { - $tmpclone2 = $clone2; - foreach ($tmpclone2 as $key2=>&$value2) { - - //echo "-------------"; - //print_r($value1); - //print_r($value2); - if(count(array_diff_assoc($value1,$value2)) == 0 && - count(array_diff_assoc($value2,$value1)) == 0 ){ - unset($clone1[$key1]); - unset($clone2[$key2]); - break; - } - } - //echo "-------------APRES"; - //print_r($clone1); - //print_r($clone2); - } - - if(count($clone1) != 0 || - count($clone2) != 0 ){ - $difference[1]=$clone1; - $difference[2]=$clone2; - $difference[1]=$clone1; - $difference[2]=$clone2; - return $difference; //return false ; - } - return $difference; - } - */ -} - diff --git a/vendor/bordercloud/sparql/ParserTurtle.php b/vendor/bordercloud/sparql/ParserTurtle.php deleted file mode 100644 index e4623e6..0000000 --- a/vendor/bordercloud/sparql/ParserTurtle.php +++ /dev/null @@ -1,335 +0,0 @@ - <?php -/** - * @git g...@github.com:BorderCloud/SPARQL.git - * @author Karima Rafes <karima.ra...@bordercloud.com> - * @license http://creativecommons.org/licenses/by-sa/4.0/ -*/ - -class ParserTurtle { - - static function turtle_to_array($turtle,$baseGraph,$idMD5 = false){ - $tabResult = array(); - $tabResult["prefix"] = array(); - $tabResult["prefix"]["base"] = $baseGraph; - $tabResult["triples"] = array(); - - preg_match_all("/((?:(?:\"|').*(?:\"|')(?:\^\^[^\s]*)?|a|<[^\s]*>|[^\s]*:[^\s]+|;|,|@prefix\s*[^\s]*\s*:\s*<[^\s<>]+>|\s*\r?\n?)+\s?\.)/i",$turtle, $matches, PREG_SET_ORDER); - - foreach ($matches as $val) { - //// http://answers.semanticweb.com/questions/2025/what-is-the-meaning-of-base-and-prefix-in-turtle-documents - - if(preg_match("/^\s*@base\s*<([^\s<>]+)>\s*\.\s*$/i", $val[0], $valMatches)){ - $tabResult["prefix"]["base"] = $valMatches[1]; - }elseif(preg_match("/^\s*@prefix\s*([^\s]+)?\s*:\s*<([^\s<>]+)>\s*\.\s*$/i", $val[0], $valMatches)){ - $namePrefix = $valMatches[1] == "" ? "empty" : $valMatches[1]; - $tabResult["prefix"][$namePrefix] = $valMatches[2]; - }elseif(preg_match("/^\s*(<[^\s]*>|[^\s]*:[^\s]+)\s*(.*)\s*\.$/is", $val[0], $valMatches)){ - $object = ParserTurtle::relativeToExplicitURI($valMatches[1],$tabResult["prefix"]) ; - preg_match_all("/\s*(a|<[^\s\,\;]*>|[^\s]*:[^\s\;]+)\s*((?:(?:<[^\s\,\;]*>|[^\s]*:[^\s\;]+|(?:\"(?:\\\\\"|[^\"])*\"|'(?:\\\\'|[^'])*')(?:\^\^[^\s\;]*)?|\s*),?)+\s*);?/is",$valMatches[2], $propertyMatches, PREG_SET_ORDER); - foreach ($propertyMatches as $propertyVal) { - - $property =""; - if($propertyVal[1] == "a"){ - $property = "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>" ; - }else{ - $property = ParserTurtle::relativeToExplicitURI($propertyVal[1],$tabResult["prefix"]) ; - } - preg_match_all("/(<[^\s\,\;]*>|[^\s]*:[^\s\,]+|(?:\"(?:\\\\\"|[^\"])*\"|'(?:\\\\'|[^'])*')(?:\^\^[^\s\,]*)?)\s*,?/is",$propertyVal[2], $valueMatches, PREG_SET_ORDER); - foreach ($valueMatches as $valueVal) { - $value = ParserTurtle::relativeToExplicitURI($valueVal[1],$tabResult["prefix"]) ; - //echo "s=>".$object." p=>".$property." o=>".$value."\n"; - if($idMD5) - $tabResult["triples"][md5($object.$property.$value)] = array("s"=>$object,"p"=>$property,"o"=>$value); - else - $tabResult["triples"][] = array("s"=>$object,"p"=>$property,"o"=>$value); - } - } - } - } - return $tabResult; - } - - static function relativeToExplicitURI($uri,$prefix){ - $result = $uri; - if(preg_match("/^(\"(?:\\\"|[^\"])*\"|'(?:\\'|[^'])*')(?:\^\^([^\s]*))?$/i",$uri, $matches)){//<> - if(isset($matches[2])){ - $type = ParserTurtle::relativeToExplicitURI($matches[2],$prefix); - $value = $matches[1]; - if($type == "http://www.w3.org/2001/XMLSchema#double" || - $type == "http://www.w3.org/2001/XMLSchema#decimal" ){ - $value = floatval($value); - }elseif($type == "http://www.w3.org/2001/XMLSchema#integer"){ - $value = intval($value); - //}elseif($type == "http://www.w3.org/2001/XMLSchema#boolean"){ - // $value = $value === "true" ? true : false; - } - $result = "\"".$value."\"^^".$type; - }else{ - $value = $matches[1]; - if (ToolsConvert::isTrueFloat($value)) { - $value = floatval($value); - } elseif (is_int($value)) { - $value = intval($value); - } - $result = $value; - } - - }elseif(preg_match("/^<>$/i",$uri, $matches)){//<> - $result = "<".$prefix["base"].">"; - }elseif(preg_match("/^<#([^:]+)>$/i",$uri, $matches)){//<#truc> - $result = "<".$prefix["base"].$matches[1].">"; - }elseif(preg_match("/^<([^:]+)>$/i",$uri, $matches)){//<truc> - $len = strlen( $prefix["base"]); - $prefixbase = substr( $prefix["base"], 0, strrpos ($prefix["base"] , "/")); - $result = "<".$prefixbase.$matches[1].">"; - }elseif(preg_match("/^:([^\s]*)$/i",$uri, $matches)){//:truc - $result = "<".$prefix["empty"].$matches[1].">"; - }elseif(preg_match("/^([^:_]*):([^><]*)$/i",$uri, $matches)){//x:truc - $result = "<".$prefix[$matches[1]].$matches[2].">"; - }else{ - $value = $uri; - if (ToolsConvert::isTrueFloat($value)) { - $value = floatval($value); - } elseif (is_int($value)) { - $value = intval($value); - } - $result = $value; - } - return $result; - } - - static function mySortTriples($itm1, $itm2){ - if($itm1["s"] > $itm2["s"]){ - return 1; - } - else if($itm1["s"] < $itm2["s"]){ - return -1; - } - else{ - if($itm1["p"] > $itm2["p"]){ - return 1; - } - else if($itm1["p"] < $itm2["p"]){ - return -1; - } - else{ - if($itm1["o"] > $itm2["o"]){ - return 1; - } - else if($itm1["o"] < $itm2["o"]){ - return -1; - } - else{ - return 0; - } - } - } - } - - static function sortTriples($arrayTurtle){ - $result = $arrayTurtle; - array_multisort($result["prefix"],SORT_ASC,SORT_STRING); - - usort($result["triples"], 'ParserTurtle::mySortTriples'); - - return $result; - } - - static function getKey($arrayTurtle, $s,$p){ - $result = null; - if(!EMPTY($arrayTurtle)){ - foreach ($arrayTurtle["triples"] as $key=>$triple) { - if("<".$s.">" == $triple["s"] && "<".$p.">" == $triple["p"] ){ - $result = $key; - break; - } - } - } - return $key; - } - static function getTriple($arrayTurtle, $s,$p){ - $result = null; - if(!EMPTY($arrayTurtle)){ - foreach ($arrayTurtle["triples"] as $key=>$triple) { - if("<".$s.">" == $triple["s"] && "<".$p.">" == $triple["p"] ){ - $result = $triple; - preg_match( '@^(?:<tel\:([^<>]+)>|<mailto\:([^<>]+)>|<([^<>]+)>|([^\"<>]+)|\"(.*)\"[^\"]*)$@i',$triple["o"], $matches); -//\<mailto\:([^\<\>])+\>|\<([^\<\>])+\>| -//print_r($triple["o"]); - //print_r($matches); - foreach ($matches as $key=>$match) { - if($key != 0 && ! EMPTY($match)){ - $result["value"] = $match; - break; - } - } - break; - } - } - } - return $result; - } - - public static function compare($rs1,$rs2,$ordered=false,$distinct=false) { - $difference=array(); - $rs1Triples = NULL; - $rs2Triples = NULL; - - if($distinct){ - $rs1Triples = $rs1["triples"]; - $rs2Triples = $rs2["triples"]; - }else{ - $rs1Triples = ToolsBlankNode::removeDuplicate($rs1["triples"]); - $rs2Triples = ToolsBlankNode::removeDuplicate($rs2["triples"]); - } - - //B/ Check the result set have the same number of rows. - if(count($rs1Triples) != count($rs2Triples)) { - $difference[1]="Nb rows :".count($rs1Triples); - $difference[2]="Nb rows :".count($rs2Triples); - return $difference; //return false ; - } - - //Check if there are blanknodes////////////////////// - //ref : http://blog.datagraph.org/2010/03/rdf-isomorphism - -// 1.Compare graph sizes and all statements without blank nodes. If they do not match, fail. -//1.1 remove blank nodes - $clone1WithoutBlanknodes =$rs1Triples; - $clone2WithoutBlanknodes = $rs2Triples; - $bnodesInRs1=array(); - $bnodesInRs2=array(); - $patternBlankNode = '/^_:/'; - - // echo "AVANT"; - // print_r($clone1); - // print_r($clone2); - foreach ($clone1WithoutBlanknodes as &$row) { - foreach ($row as $key=>&$value) { - if (preg_match($patternBlankNode, $value)) { - $bnodesInRs1[] = $value ; - $value = "BLANKNODE";//remove - } - } - } - foreach ($clone2WithoutBlanknodes as &$row) { - foreach ($row as $key=>&$value) { - if (preg_match($patternBlankNode, $value)) { - $bnodesInRs2[] = $value ; - $value = "BLANKNODE";//remove - } - } - } - - //print_r($clone1WithoutBlanknodes); - //print_r($clone2WithoutBlanknodes); -//1.2 compare - if($ordered){ - $difference = ToolsBlankNode::array_diff_assoc_recursive( $clone1WithoutBlanknodes, $clone2WithoutBlanknodes); - }else{ - $difference = ToolsBlankNode::array_diff_assoc_unordered( $clone1WithoutBlanknodes, $clone2WithoutBlanknodes) ; - } - - //Check if there are blank nodes - if((count($bnodesInRs1) == 0 && count($bnodesInRs2) == 0 ) || count($difference) != 0) - return $difference; - - //With blank nodes - $bnodesInRs1=array_values(array_unique($bnodesInRs1)); - $bnodesInRs2=array_values(array_unique($bnodesInRs2)); - if(count($bnodesInRs1) != count($bnodesInRs2)) { - $difference[1]="Nb bnode :".count($bnodesInRs1); - $difference[2]="Nb bnode :".count($bnodesInRs2); - return $difference; //return false ; - } - - //echo "BLANKNODE\n"; - //print_r($bnodesInRs1); - //print_r($bnodesInRs2); - $clone1 = $rs1Triples; - // print_r($clone1); - // 2.Repeat, for each graph: - $arrayPermutationsBnode = ToolsBlankNode::AllPermutations($bnodesInRs2); - //echo "PERMUTATION\n"; - //print_r($arrayPermutationsBnode ); - //exit(); - foreach ( $arrayPermutationsBnode as $permute) { - //print_r($permute); - $clone2 = $rs2Triples; - foreach ( $clone2 as $key=>&$row) { - $arrayVariableTypeBnode = array_keys( $row , "bnode") ; - foreach ($arrayVariableTypeBnode as $variableTypeBnode) { - $variableArray = split(" ",$variableTypeBnode); - $variable=$variableArray[0]; - - $row[$variable] = $bnodesInRs1[array_search($row[$variable] ,$permute)]; - } - } - - //print_r($clone2); - //$difference = self::sub_array_diff_assoc_unordered( $clone1,$clone2) ; - if($ordered){ - $difference = ToolsBlankNode::array_diff_assoc_recursive($clone1,$clone2); - }else{ - $difference = ToolsBlankNode::array_diff_assoc_unordered($clone1,$clone2) ; - } - if(count($difference) == 0){ - return $difference; //true - } - } - - return $difference; - } - /* - public static function array_diff_assoc_unordered( $rs1, $rs2) { - $difference=array(); - $rs1Triples = $rs1["triples"]; - $rs2Triples = $rs2["triples"]; - - //B/ Check the result set have the same number of rows. - if(count($rs1Triples) != count($rs2Triples)) { - $difference[1]="Nb rows :".count($rs1Triples); - $difference[2]="Nb rows :".count($rs2Triples); - return $difference; //return false ; - } - - //C/ Pick a row from the test results, scan the expected results - // to find a row with same variable/value bindings, and remove - // from the expected results. If all test rows, match then - // (because of B) the result sets have the same rows. - // - //return equivalent(convert(rs1), convert(rs2), new BNodeIso(NodeUtils.sameValue)) ; - $clone1 = $rs1Triples; - $clone2 = $rs2Triples; -// echo "AVANT"; -// print_r($clone1); -// print_r($clone2); - foreach ($rs1Triples as $key1=>&$value1) { - $tmpclone2 = $clone2; - foreach ($tmpclone2 as $key2=>&$value2) { - -// echo "-------------"; -// print_r($value1); -// print_r($value2); - if(count(array_diff_assoc($value1,$value2)) == 0 && - count(array_diff_assoc($value2,$value1)) == 0 ){ - unset($clone1[$key1]); - unset($clone2[$key2]); - break; - } - } -// echo "-------------APRES"; -// print_r($clone1); -// print_r($clone2); - } - - if(count($clone1) != 0 || - count($clone2) != 0 ){ - $difference[1]=$clone1; - $difference[2]=$clone2; - return $difference; //return false ; - } - - return $difference; - }*/ -} diff --git a/vendor/bordercloud/sparql/README.md b/vendor/bordercloud/sparql/README.md index af76222..e012344 100644 --- a/vendor/bordercloud/sparql/README.md +++ b/vendor/bordercloud/sparql/README.md @@ -1,28 +1,32 @@ -## Lib Sparql 1.1 HTTP Client +[![Build Status](https://travis-ci.org/BorderCloud/SPARQL.svg?branch=master)](https://travis-ci.org/BorderCloud/SPARQL) -###Installation -This project assumes you have composer installed. -Simply add: - "require" : { - - "BorderCloud/SPARQL" : "*" - - } +## Lib Sparql 1.1 HTTP Client + +Very simple SparqlClient for PHP. + +Thanks to [contributors](https://github.com/BorderCloud/SPARQL/graphs/contributors). + +### Installation + +This project assumes you have composer installed. Simply add new dependency via Composer: +```sh +composer require bordercloud/sparql +``` To your composer.json, and then you can simply install with: - - composer install +```sh +composer install +``` ### Test the lib with a php script : query You can test your first query sparql with DBPEDIA via a command line : -``` +```sh ./query -r -e http://dbpedia.org/sparql -f ./example/queryReadDBpedia.rq ``` And the doc of this script with virtuoso, 4store, Allegrograph, Fuseki and Sesame : - ``` USAGE : query [-r|-w][-e URL|--endpointQueryAndUpdate=URL] [--file=FILE|-f FILE] @@ -30,7 +34,7 @@ -r READ ONLY -w WRITE ONLY - -e, --endpointQueryAndUpdate=URL Put url of endpoint to do query or + -e, --endpointQueryAndUpdate=URL Put url of endpoint to do query or update : URL/sparql/?query=... URL/update/?update=... (POST) @@ -38,19 +42,19 @@ URL?query=... -u, --endpointUpdateOnly=URL Put url of endpoint to do query : URL?update=... (POST) - --nameParameterQuery=PARAMETER Change the name of parameter in + --nameParameterQuery=PARAMETER Change the name of parameter in the request http to read. (by default : query) - --nameParameterUpdate=PARAMETER Change the name of parameter in + --nameParameterUpdate=PARAMETER Change the name of parameter in the request http to write. (by default : update) -f,--file=File File of the query. -t, --typeOutput=TYPE Type of response: table,txt,csv,tsv,ttl,srx,srj (by default : table) - + -l, --login=LOGIN Server login -p, --password=PASSWORD Server password - + -v, --verbose Mode verbose -d, --debug Mode debug @@ -98,131 +102,162 @@ Send a simple query to Wikidata : ```php <?php +use BorderCloud\SPARQL\SparqlClient; -require_once('../Endpoint.php'); +require_once ('../vendor/autoload.php'); -$endpoint ="https://query.wikidata.org/sparql"; -$sp_readonly = new Endpoint($endpoint); +$endpoint = "https://query.wikidata.org/sparql"; +$sc = new SparqlClient(); +$sc->setEndpointRead($endpoint); +//$sc->setMethodHTTPRead("GET"); $q = "select * where {?x ?y ?z.} LIMIT 5"; -$rows = $sp_readonly->query($q, 'rows'); -$err = $sp_readonly->getErrors(); +$rows = $sc->query($q, 'rows'); +$err = $sc->getErrors(); if ($err) { - print_r($err); - throw new Exception(print_r($err,true)); + print_r($err); + throw new Exception(print_r($err, true)); } -foreach($rows["result"]["variables"] as $variable){ - printf("%-20.20s",$variable); - echo '|'; - } - echo "\n"; +foreach ($rows["result"]["variables"] as $variable) { + printf("%-20.20s", $variable); + echo '|'; +} +echo "\n"; -foreach ($rows["result"]["rows"] as $row){ - foreach($rows["result"]["variables"] as $variable){ - printf("%-20.20s",$row[$variable]); +foreach ($rows["result"]["rows"] as $row) { + foreach ($rows["result"]["variables"] as $variable) { + printf("%-20.20s", $row[$variable]); echo '|'; - } - echo "\n"; - } -?> + } + echo "\n"; +} ``` Send a simple query to DBpedia : ```php <?php +use BorderCloud\SPARQL\SparqlClient; -require_once('bordercloud/Endpoint.php'); +require_once ('../vendor/autoload.php'); - $endpoint ="http://dbpedia.org/sparql"; - $sp_readonly = new Endpoint($endpoint); - $q = "select * where {?x ?y ?z.} LIMIT 5"; - $rows = $sp_readonly->query($q, 'rows'); - $err = $sp_readonly->getErrors(); - if ($err) { - print_r($err); - throw new Exception(print_r($err,true)); +$endpoint = "http://dbpedia.org/sparql"; +$sc = new SparqlClient(); +$sc->setEndpointRead($endpoint); +$q = "select * where {?x ?y ?z.} LIMIT 5"; +$rows = $sc->query($q, 'rows'); +$err = $sc->getErrors(); +if ($err) { + print_r($err); + throw new Exception(print_r($err, true)); +} + +foreach ($rows["result"]["variables"] as $variable) { + printf("%-20.20s", $variable); + echo '|'; +} +echo "\n"; + +foreach ($rows["result"]["rows"] as $row) { + foreach ($rows["result"]["variables"] as $variable) { + printf("%-20.20s", $row[$variable]); + echo '|'; } - - foreach($rows["result"]["variables"] as $variable){ - printf("%-20.20s",$variable); - echo '|'; - } - echo "\n"; - - foreach ($rows["result"]["rows"] as $row){ - foreach($rows["result"]["variables"] as $variable){ - printf("%-20.20s",$row[$variable]); - echo '|'; - } - echo "\n"; - } -?> + echo "\n"; +} ``` Send a simple query via an endpoint sparql-auth (with OpenLink Virtuoso Open-Source Edition) : ```php <?php +use BorderCloud\SPARQL\SparqlClient; -require_once('../Endpoint.php'); +require_once ('../vendor/autoload.php'); - $endpoint = "https://example.com/sparql-auth"; - $sp_ReadAndWrite = new Endpoint($endpoint,false); - - $sp_ReadAndWrite->setLogin("login"); - $sp_ReadAndWrite->setPassword("password"); - - $q = "select * where {?x ?y ?z.} LIMIT 5"; - $rows = $sp_ReadAndWrite->query($q, 'rows'); - $err = $sp_ReadAndWrite->getErrors(); - if ($err) { - print_r($err); - throw new Exception(print_r($err,true)); +$endpoint = "https://example.com/sparql-auth"; +$sc = new SparqlClient(); +$sc->setEndpointRead($endpoint); +//$sc->setEndpointWrite($endpoint); +$sc->setLogin("login"); +$sc->setPassword("password"); + +$q = "select * where {?x ?y ?z.} LIMIT 5"; +$rows = $sp_ReadAndWrite->query($q, 'rows'); +$err = $sp_ReadAndWrite->getErrors(); +if ($err) { + print_r($err); + throw new Exception(print_r($err, true)); +} + +foreach ($rows["result"]["variables"] as $variable) { + printf("%-20.20s", $variable); + echo '|'; +} +echo "\n"; + +foreach ($rows["result"]["rows"] as $row) { + foreach ($rows["result"]["variables"] as $variable) { + printf("%-20.20s", $row[$variable]); + echo '|'; } - - foreach($rows["result"]["variables"] as $variable){ - printf("%-20.20s",$variable); - echo '|'; - } - echo "\n"; - - foreach ($rows["result"]["rows"] as $row){ - foreach($rows["result"]["variables"] as $variable){ - printf("%-20.20s",$row[$variable]); - echo '|'; - } - echo "\n"; - } -?> + echo "\n"; +} ``` -### Documentation API -[API](doc/Endpoint.md) +### Documentation API +* [SparqlClient](doc/BorderCloud-SPARQL-SparqlClient.md) +* [API](doc/ApiIndex.md) -### Copy Sources and tests +### Copy Sources and tests + TODO !! +```sh git clone http://github.com/BorderCloud/SPARQL.git +``` -### Contact +### Contact If you have remarks, questions, or suggestions, please send them to karima.ra...@bordercloud.com -### Release-Notes +### Release-Notes + +* V2.0.0@DEV +** Compatibility : PHP 7.1 and psr-4 +** Rename the class Endpoint to SparqlClient and simplify the constructor. You can set the endpoints only by their setters. +** Rename several functions (PHP Lint) +** Update PHPDoc +** Add the function SparqlClient->getLastErreur() : can read the SPARQL syntax error directly, if the pattern of error exists (Add the pattern of Wikidata and Virtuoso) +** Move files and add tests + phpunit.xml. SparqlClient is coverage to 82% for the moment (coverage with Virtuoso and Wikidata). +** Enable Travis in GitHub * V1.2.1.0 Add fix for Wikidata and other * V1.1.0.0 version SPARQL.Pro lib PHP by Karima Rafes <karima.ra...@bordercloud.com> -### license +### license + SPARQL.Pro lib PHP (c)2014 by Karima Rafes - BorderCloud SPARQL.Pro lib PHP is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. You should have received a copy of the license along with this -work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>. +work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>. -### Compile DOC -php vendor/phpdocumentor/phpdocumentor/bin/phpdoc --template="xml" -f Base.php -f ConversionMimetype.php -f Endpoint.php -f ParserCSV.php -f ToolsConvert.php -f Curl.php -f Net.php -f ParserSparqlResult.php -f Namespace.php -f ParserTurtle.php -f ToolsBlankNode.php +### Compile DOC + +```sh +php vendor/phpdocumentor/phpdocumentor/bin/phpdoc --directory=src --template="xml" vendor/evert/phpdoc-md/bin/phpdocmd ./output/structure.xml doc +``` + +### Git... +```sh +git pull +git push +git tag -a 2.0.1@dev -m "version dev" +git push --tags +``` + + diff --git a/vendor/bordercloud/sparql/ToolsBlankNode.php b/vendor/bordercloud/sparql/ToolsBlankNode.php deleted file mode 100644 index 31b5523..0000000 --- a/vendor/bordercloud/sparql/ToolsBlankNode.php +++ /dev/null @@ -1,165 +0,0 @@ -<?php -/** - * @git g...@github.com:BorderCloud/SPARQL.git - * @author Karima Rafes <karima.ra...@bordercloud.com> - * @license http://creativecommons.org/licenses/by-sa/4.0/ -*/ -class ToolsBlankNode { - - public static function removeDuplicate($set) - { - $find = false; - $result = array(); - foreach ($set as $key1=>$value1) { - $find = false; - foreach ($result as $key2=>$value2) { - if(count(array_diff_assoc($value1,$value2)) == 0 ){ - $find = true; - break; - } - } - if(! $find) - $result[] = $value1; - - } - return $result; - } - - public static function AllPermutations($set) - { - $solutions=array(); - $solutions[]=$set; - $n=count($set); - $p=array_keys($set); - $i=1; - - while ($i<$n) - { - if ($p[$i]>0){ - $p[$i]--; - $j=0; - if ($i%2==1) - $j=$p[$i]; - //swap - $tmp=$set[$j]; - $set[$j]=$set[$i]; - $set[$i]=$tmp; - $i=1; - $solutions[]=$set; - } - elseif ($p[$i]==0){ - $p[$i]=$i; - $i++; - } - } - return $solutions; - } - - - public static function array_diff_assoc_unordered( $rows1, $rows2) { - $difference=array(); - - //B/ Check the result set have the same number of rows. - if(count($rows1) != count($rows2)) { - $difference[1]="Nb rows :".count($rows1); - $difference[2]="Nb rows :".count($rows2); - return $difference; //return false ; - } - - //C/ Pick a row from the test results, scan the expected results - // to find a row with same variable/value bindings, and remove - // from the expected results. If all test rows, match then - // (because of B) the result sets have the same rows. - // - //return equivalent(convert(rs1), convert(rs2), new BNodeIso(NodeUtils.sameValue)) ; - $clone1 = $rows1; - $clone2 = $rows2; - - // echo "AVANT"; - // print_r($clone1); - // print_r($clone2); - foreach ($rows1 as $key1=>&$value1) { - $tmpclone2 = $clone2; - foreach ($tmpclone2 as $key2=>&$value2) { - - //echo "-------------"; - //print_r($value1); - //print_r($value2); - if(count(array_diff_assoc($value1,$value2)) == 0 && - count(array_diff_assoc($value2,$value1)) == 0 ){ - unset($clone1[$key1]); - unset($clone2[$key2]); - break; - } - } - //echo "-------------APRES"; - //print_r($clone1); - //print_r($clone2); - } - - if(count($clone1) != 0 || - count($clone2) != 0 ){ - $difference[1]=$clone1; - $difference[2]=$clone2; - $difference[1]=$clone1; - $difference[2]=$clone2; - return $difference; //return false ; - } - return $difference; - } - - public static function array_diff_assoc_recursive($array1, $array2) { - $difference=array(); - foreach($array1 as $key => $value) { - if( is_array($value) ) { - if( !isset($array2[$key]) || !is_array($array2[$key]) ) { - $difference[1][$key] = $value; - $difference[2][$key] = "Not set"; - } else { - $new_diff = self::array_diff_assoc_recursive($value, $array2[$key]); - if( count($new_diff)>0 ){ - $difference[1][$key] = $new_diff[1]; - $difference[2][$key] = $new_diff[2]; - } - } - } else if( !array_key_exists($key,$array2)) { - $difference[1][$key] = $value; - $difference[2][$key] = "Key doesnt exist"; - } else if($array2[$key] !== $value) { - $difference[1][$key] = $value; - $difference[2][$key] = $array2[$key]; - } - } - return $difference; - } - /* - function array_diff_assoc_recursive_with_blanknode($array1, $array2) { - $difference=array(); - $node = array(); - foreach($array1 as $key => $value) { - if( is_array($value) ) { - if( !isset($array2[$key]) || !is_array($array2[$key]) ) { - $difference[$key] = $value; - } else { - $new_diff = Tools::array_diff_assoc_recursive_with_blanknode($value, $array2[$key]); - if( !empty($new_diff) ) - $difference[$key] = $new_diff; - } - } else if( !array_key_exists($key,$array2) ) { - $difference[$key] = $value; - } else if( $array2[$key] !== $value && floatval($array2[$key]) !== floatval($value)) { - if(isset($value[0]) && $value[0] == "_"){//(array_key_exists("type",$array1) && $array1["type"] == "bnode"){ - if(!array_key_exists($value,$node )){ - $node[$value] = $array2[$key]; - }else if($node[$value] !== $array2[$key] ){ - $difference[$key] = $value; - } - }else{ - $difference[$key] = $value; - } - } - } - return $difference; - } - */ -} \ No newline at end of file diff --git a/vendor/bordercloud/sparql/ToolsConvert.php b/vendor/bordercloud/sparql/ToolsConvert.php deleted file mode 100644 index 6ff57ea..0000000 --- a/vendor/bordercloud/sparql/ToolsConvert.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php -/** - * @git g...@github.com:BorderCloud/SPARQL.git - * @author Karima Rafes <karima.ra...@bordercloud.com> - * @license http://creativecommons.org/licenses/by-sa/4.0/ -*/ -class ToolsConvert { - - public static function isTrueFloat($val) - { - $pattern = '/^[+-]?(\d*\.\d+([eE]?[+-]?\d+)?|\d+[eE][+-]?\d+)$/'; - //echo 'Val:'. $val."\n"; - //var_dump(is_float($val) || preg_match($pattern, trim($val))); - return (is_float($val) || preg_match($pattern, trim($val))); - } -} \ No newline at end of file diff --git a/vendor/bordercloud/sparql/composer.json b/vendor/bordercloud/sparql/composer.json index d63fcd4..439e5a0 100644 --- a/vendor/bordercloud/sparql/composer.json +++ b/vendor/bordercloud/sparql/composer.json @@ -1,31 +1,46 @@ { - "name": "bordercloud/sparql", - "type": "library", - "description": "Lib PHP very easy for SPARQL 1.1", - "keywords": ["SPARQL","RDF"], - "homepage": "https://github.com/BorderCloud/SPARQL", - "license": "CC-BY-SA-4.0", - "version": "1.2.1", - "authors": [ - { - "name": "Karima Rafes", - "email": "karima.ra...@bordercloud.com", - "homepage": "http://www.bordercloud.com/", - "role": "Developer" - } - ], - "require": { - "php": ">=5.3.0" - }, - - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/BorderCloud/SPARQL" - } - ], - "require-dev": { - "evert/phpdoc-md" : "0.0.*", - "phpdocumentor/phpdocumentor": "2.*" - } + "name" : "bordercloud/sparql", + "type" : "library", + "description" : "Lib PHP very easy for SPARQL 1.1", + "keywords" : [ + "SPARQL", + "RDF" + ], + "homepage" : "https://github.com/BorderCloud/SPARQL", + "license" : "CC-BY-SA-4.0", + "version" : "2.0.1@dev", + "authors" : [{ + "name" : "Karima Rafes", + "email" : "karima.ra...@bordercloud.com", + "homepage" : "http://www.bordercloud.com/", + "role" : "Developer" + } + ], + "require" : { + "php" : ">=5.2" + }, + "repositories" : [{ + "type" : "vcs", + "url" : "https://github.com/BorderCloud/SPARQL" + } + ], + "require-dev" : { + "evert/phpdoc-md": "^0.2.0@dev", + "twig/twig": "~1.3@dev", + "phpdocumentor/phpdocumentor":"2.9.0@dev", + "michelf/php-markdown": "^1.7", + "phpunit/phpunit": "^6.3" + }, + "autoload" : { + "psr-4" : { + "BorderCloud\\SPARQL\\" : "src/", + "BorderCloud\\SPARQL\\Tests\\" : "tests/" + } + }, + "bin" : [ + "bin/query" + ], + "config" : { + "bin-dir" : "bin" + } } diff --git a/vendor/bordercloud/sparql/query b/vendor/bordercloud/sparql/query deleted file mode 100755 index c106a24..0000000 --- a/vendor/bordercloud/sparql/query +++ /dev/null @@ -1,414 +0,0 @@ -#!/usr/bin/php -<?php - -require_once 'Endpoint.php'; -//require_once 'Test.php'; - -//List of servers available that you can test with this script - -$usage = " -USAGE : query [-r|-w][-e URL|--endpointQueryAndUpdate=URL] - [--file=FILE|-f FILE] - [-v|-verbose] - - -r READ ONLY - -w WRITE ONLY - -e, --endpointQueryAndUpdate=URL Put url of endpoint to do query or - update : - URL/sparql/?query=... - URL/update/?update=... (POST) - -q, --endpointQueryOnly=URL Put url of endpoint to do query : - URL?query=... - -u, --endpointUpdateOnly=URL Put url of endpoint to do query : - URL?update=... (POST) - --nameParameterQuery=PARAMETER Change the name of parameter in - the request http to read. - (by default : query) - --nameParameterUpdate=PARAMETER Change the name of parameter in - the request http to write. - (by default : update) - -f,--file=File File of the query. - -t, --typeOutput=TYPE Type of response: table,txt,csv,tsv,ttl,srx,srj - (by default : table) - - -l, --login=LOGIN Server login - -p, --password=PASSWORD Server password - - -v, --verbose Mode verbose - -d, --debug Mode debug - -EXAMPLE : Virtuoso -./query -w -e http://localhost/tests/ -f ./example/queryWrite1.rq - -./query -r -e http://localhost/tests/ -f ./example/queryRead1.rq - -EXAMPLE : 4Store -./query -w -e http://localhost/ -f ./example/queryWrite1.rq - -./query -r -e http://localhost/ -f ./example/queryRead1.rq - -EXAMPLE : Sesame -./query -w -q http://localhost/openrdf-sesame/repositories/tests \ - -u http://localhost/openrdf-sesame/repositories/tests/statements \ --f ./example/queryWrite1.rq - -./query -r -q http://localhost/openrdf-sesame/repositories/tests \ - -u http://localhost/openrdf-sesame/repositories/tests/statements \ --f ./example/queryRead1.rq - -EXAMPLE : Fuseki -./query -w -q http://localhost/tests/query \ --u http://localhost/tests/update \ --f ./example/queryWrite1.rq - -./query -r -q http://localhost/tests/query \ --u http://localhost/tests/update \ --f ./example/queryRead1.rq - -EXAMPLE : Allegrograph -./query -w -q http://localhost/repositories/tests \ --u http://localhost/repositories/tests \ ---nameParameterUpdate=query \ --f ./example/queryWrite1.rq - -./query -r -q http://localhost/repositories/tests \ --u http://localhost/repositories/tests \ ---nameParameterUpdate=query \ --f ./example/queryRead1.rq - -"; - -// Variables - inputs -$modeVerbose = false; -$modeDebug = false; -$modeRead = false; -$modeWrite = false; - -$triplestore = "standard"; -$endpointQueryAndUpdate = ""; -$endpointQueryOnly = ""; -$endpointUpdateOnly = ""; -$nameParameterQuery = "query"; -$nameParameterUpdate = "update"; -$endpointLogin = ""; -$endpointPassword = ""; - -$modeRead = false; -$modeWrite = false; - -$filename= ""; -$typeOutput="table"; -$type=""; - -//Client web -$CURL = new Curl($modeDebug); - -if(count($argv) < 2){ - echo $usage; - exit(); -} - -for($i = 1; $i < count($argv); $i++) { - $param=explode("=",$argv[$i]); - - switch($param[0]){ - case "-h": - case "--help": - echo $usage; - exit(); - case "-v": - case "--verbose": - $modeVerbose = true; - break; - case "-r": - case "--read": - $modeRead = true; - break; - case "-w": - case "--write": - $modeWrite = true; - break; - case "-d": - case "--debug": - $modeDebug = true; - $modeVerbose = true; - break; -////////////////////////////////////////////////////////////////////////////////// - case "-e": - if(! array_key_exists($i + 1, $argv)){ - echo "ERROR : forget parameter after -e (see --help)\n"; - exit(); - } - $endpointQueryAndUpdate = $argv[$i + 1]; - if(! filter_var($endpointQueryAndUpdate, FILTER_VALIDATE_URL)){ - echo "ERROR : The URL of endpoint is not valid\n"; - exit(); - } - $i++; - break; - case "--endpointQueryAndUpdate": - if(! array_key_exists(1, $param)){ - echo "ERROR : forget parameter after --endpointQueryAndUpdate (see --help)\n"; - exit(); - } - $endpointQueryAndUpdate = $param[1]; - if(! filter_var($endpointQueryAndUpdate, FILTER_VALIDATE_URL)){ - echo "ERROR : The URL of endpoint is not valid\n"; - exit(); - } - break; - case "-q": - if(! array_key_exists($i + 1, $argv)){ - echo "ERROR : forget parameter after -q (see --help)\n"; - exit(); - } - $endpointQueryOnly = $argv[$i + 1]; - if(! filter_var($endpointQueryOnly, FILTER_VALIDATE_URL)){ - echo "ERROR : The URL of endpoint is not valid\n"; - exit(); - } - $i++; - break; - case "--endpointQueryOnly": - if(! array_key_exists(1, $param)){ - echo "ERROR : forget parameter after --endpointQueryOnly (see --help)\n"; - exit(); - } - $endpointQueryOnly = $param[1]; - if(! filter_var($endpointQueryOnly, FILTER_VALIDATE_URL)){ - echo "ERROR : The URL of endpoint is not valid\n"; - exit(); - } - break; - case "-u": - if(! array_key_exists($i + 1, $argv)){ - echo "ERROR : forget parameter after -u (see --help)\n"; - exit(); - } - $endpointUpdateOnly = $argv[$i + 1]; - if(! filter_var($endpointUpdateOnly, FILTER_VALIDATE_URL)){ - echo "ERROR : The URL of endpoint is not valid\n"; - exit(); - } - $i++; - break; - case "--endpointUpdateOnly": - if(! array_key_exists(1, $param)){ - echo "ERROR : forget parameter after --endpointUpdateOnly (see --help)\n"; - exit(); - } - $endpointUpdateOnly = $param[1]; - if(! filter_var($endpointUpdateOnly, FILTER_VALIDATE_URL)){ - echo "ERROR : The URL of endpoint is not valid\n"; - exit(); - } - break; - case "--nameParameterQuery": - if(! array_key_exists(1, $param)){ - echo "ERROR : forget parameter after --nameParameterQuery (see --help)\n"; - exit(); - } - $nameParameterQuery = $param[1]; - break; - case "--nameParameterUpdate": - if(! array_key_exists(1, $param)){ - echo "ERROR : forget parameter after --nameParameterUpdate (see --help)\n"; - exit(); - } - $nameParameterUpdate = $param[1]; - break; - case "-f": - if(! array_key_exists($i + 1, $argv)){ - echo "ERROR : forget parameter after -f (see --help)\n"; - exit(); - } - $filename = $argv[$i + 1]; - if(! file_exists($filename)){ - echo "The file $filename does not exist"; - exit(); - } - $i++; - break; - case "--file": - if(! array_key_exists(1, $param)){ - echo "ERROR : forget parameter after --endpointQueryOnly (see --help)\n"; - exit(); - } - $filename = $param[1]; - if(! file_exists($filename)){ - echo "The file $filename does not exist"; - exit(); - } - break; - case "-t": - if(! array_key_exists($i + 1, $argv)){ - echo "ERROR : forget parameter after -t (see --help)\n"; - exit(); - } - $typeOutput = $argv[$i + 1]; - $i++; - break; - case "--typeOutput": - if(! array_key_exists(1, $param)){ - echo "ERROR : forget parameter after --typeOutput (see --help)\n"; - exit(); - } - $typeOutput = $param[1]; - break; - - case "-l": - if(! array_key_exists($i + 1, $argv)){ - echo "ERROR : forget parameter after -l (see --help)\n"; - exit(); - } - $endpointLogin = $argv[$i + 1]; - $i++; - break; - case "--login": - if(! array_key_exists(1, $param)){ - echo "ERROR : forget parameter after --login (see --help)\n"; - exit(); - } - $endpointLogin = $param[1]; - break; - case "-p": - if(! array_key_exists($i + 1, $argv)){ - echo "ERROR : forget parameter after -p (see --help)\n"; - exit(); - } - $endpointPassword = $argv[$i + 1]; - $i++; - break; - case "--password": - if(! array_key_exists(1, $param)){ - echo "ERROR : forget parameter after --password (see --help)\n"; - exit(); - } - $endpointPassword = $param[1]; - break; - default: - //echo $usage; exit(); - echo "ERROR usage ! (".$param[0]."?)"; - echo $usage; exit(); - } -} - -if($modeDebug){ - ini_set('display_errors','On'); -}else{ - ini_set('error_log','/dev/null'); - ini_set('display_errors','Off'); -} - -/////////////// INIT ENDPOINT -$ENDPOINT = null; -if($endpointQueryOnly == "" && $endpointUpdateOnly == "" && $endpointQueryAndUpdate == ""){ - echo "ERROR : The endpoint didn't find\n"; exit(); -}elseif($endpointQueryAndUpdate != ""){ - $ENDPOINT = new Endpoint($endpointQueryAndUpdate,$modeRead,$modeDebug); -}elseif($endpointQueryOnly == "" || $endpointUpdateOnly == ""){ - echo "ERROR : The endpoint SPARQL query or update didn't find\n"; exit(); -}else{ - $ENDPOINT = new Endpoint($endpointQueryOnly,$modeRead,$modeDebug); - $ENDPOINT->setEndpointQuery($endpointQueryOnly); - $ENDPOINT->setEndpointUpdate($endpointUpdateOnly); - $ENDPOINT->setNameParameterQueryRead($nameParameterQuery); - $ENDPOINT->setNameParameterQueryWrite($nameParameterUpdate); -} - -if($endpointLogin != "" && $endpointPassword != ""){ - $ENDPOINT->setLogin($endpointLogin); - $ENDPOINT->setPassword($endpointPassword); -} - - -switch($typeOutput){ - case "txt": - $type = "text/plain"; - break; - case "csv": - $type = "text/csv; charset=utf-8"; - break; - case "tsv": - $type = "text/tab-separated-values; charset=utf-8"; - break; - case "ttl": - $type = "text/turtle"; - break; - case "table": - case "srx": - $type = "application/sparql-results+xml"; - break; - case "srj": - $type = "application/sparql-results+json"; - break; - default : - $type = $typeOutput; -} - -if($modeVerbose){ -echo " -Configuration : -- Endpoint query : ".$ENDPOINT->getEndpointQuery()." -- Endpoint update : ".$ENDPOINT->getEndpointUpdate()." -- Mode verbose : ".($modeVerbose?"ON":"OFF")." -- Mode debug : ".($modeDebug?"ON":"OFF")." -- Type output : ".$type." -- Endpoint login : ".$ENDPOINT->getLogin()." -- Endpoint password : ".$ENDPOINT->getPassword()." -"; -} - -///////// - -$ENDPOINT->ResetErrors(); - -//queryRead -/* - -*/ - - - -if($typeOutput === "table"){ - $rows = $ENDPOINT->query( file_get_contents($filename), 'rows'); - $err = $ENDPOINT->getErrors(); - - if ($err) { - echo "ERROR \n"; - print_r($err,true); - exit(1); - } - - foreach($rows["result"]["variables"] as $variable){ - printf("%-20.20s",$variable); - echo '|'; - } - echo "\n"; - - foreach ($rows["result"]["rows"] as $row){ - foreach($rows["result"]["variables"] as $variable){ - printf("%-20.20s",$row[$variable]); - echo '|'; - } - echo "\n"; - } - }else{ - if($modeRead) - $response = $ENDPOINT->queryRead( file_get_contents($filename),$type); - elseif ($modeWrite) - $response = $ENDPOINT->queryUpdate( file_get_contents($filename),$type); - else{ - echo "ERROR : forget parameter after -r or -w (see --help)\n"; - exit(1); - } - - $err = $ENDPOINT->getErrors(); - - if ($err) { - echo "ERROR \n"; - print_r($err,true); - exit(1); - } - echo $response; - } -- To view, visit https://gerrit.wikimedia.org/r/374797 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I0dc0c88b173fc8c5052161428b24e3d35c33adb8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/LinkedWiki Gerrit-Branch: master Gerrit-Owner: Karima Rafes <karima.ra...@gmail.com> Gerrit-Reviewer: Karima Rafes <karima.ra...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits