コード例 #1
0
 public function testInsertWhenOffline()
 {
     global $EndPoint4store, $modeDebug, $prefixSparql, $prefixTurtle, $graph1, $graph2;
     $sp = new Endpoint($EndPoint4store, false, $modeDebug);
     $q = $prefixSparql . " \n\n\t\t\tINSERT DATA {  \n\t\t\t\tGRAPH <" . $graph1 . "> {    \n\t\t\t\ta:A b:Name \"Test2\" .   \n\t\t\t\ta:A b:Name \"Test3\" .   \n\t\t\t\ta:A b:Name \"Test4\" .  \n    \t\t}}";
     $res = $sp->query($q, 'raw');
     $err = $sp->getErrors();
     if ($err) {
         //print_r($err);
     }
     $this->assertTrue(count($err) > 0);
     $this->assertFalse($res);
 }
コード例 #2
0
PREFIX theme: <http://data.sparql.pro/w/Q> 
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>   
            
INSERT 
  { GRAPH <http://sparql.pro/lodTest> { 
       theme:2223 
         a skos:Concept ;
         rdfs:label "Physique"@fr ;
         rdfs:label "Physics"@en .
      }
}  
EOT;
$sp_ReadAndWrite->ResetErrors();
$rows = $sp_ReadAndWrite->query($q, 'raw');
$err = $sp_ReadAndWrite->getErrors();
if ($err) {
    print_r($err);
}
/*
 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 '|';
        }
コード例 #3
0
<?php

/** 
 * @version 0.4.1
 * @package Bourdercloud/PHP4store
 * @copyright (c) 2011 Bourdercloud.com
 * @author Karima Rafes <*****@*****.**>
 * @license http://www.opensource.org/licenses/mit-license.php
 */
/** 
 * @ignore
 */
//require_once('php4store/Endpoint.php');
require '../lib/php4store/Endpoint.php';
$endpoint = "http://dbpedia.org/";
// READ ONLY  ******************************************
$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));
}
var_dump($rows);
コード例 #4
0
 public function execute($par = null)
 {
     global $wgOut, $wgScriptPath;
     $queryWithoutPrefix = isset($_REQUEST["queryWithoutPrefix"]) ? stripslashes($_REQUEST["queryWithoutPrefix"]) : "";
     $query = isset($_REQUEST["query"]) ? stripslashes($_REQUEST["query"]) : "";
     $endpoint = isset($_REQUEST["endpoint"]) ? stripslashes(trim($_REQUEST["endpoint"])) : "http://dbpedia.org/sparql";
     $output = isset($_REQUEST["output"]) ? stripslashes($_REQUEST["output"]) : "";
     $titleRequest = isset($_REQUEST["titleRequest"]) ? stripslashes($_REQUEST["titleRequest"]) : "";
     $description = isset($_REQUEST["description"]) ? stripslashes($_REQUEST["description"]) : "";
     // $wgOut->addHTML( isset($_REQUEST["query"])?stripslashes($_REQUEST["query"]):"Vide");
     // $wgOut->addHTML(print_r($_REQUEST,true));
     // $wgOut->addHTML(print_r($queryWithoutPrefix,true));
     // $wgOut->addHTML(print_r($query,true));
     // $wgOut->addHTML(print_r($output,true));
     if ($query != "" && $output == "save" && $titleRequest != "") {
         if ($this->pageExists($titleRequest)) {
             $wgOut->addHTML("<h2>" . wfMsg('specialsparqlquery_error_title_exists_yet') . "</h2> \n");
             $wgOut->addHTML();
         } else {
             $this->savePage($titleRequest, $this->template($query, $description));
             $wgOut->addWikiText(wfMsg('specialsparqlquery_your_query_saved_here') . "[[{$titleRequest}]]");
         }
     }
     if ($query == "" || $output == "save" || $output == "wiki") {
         $wgOut->addWikiText(wfMsg('specialsparqlquery_mainpage'));
         $wgOut->addHTML("<pre>" . htmlentities($this->prefix(), ENT_QUOTES, 'UTF-8') . "</pre>");
         $wgOut->addHTML("<form method='post' name='formQuery'>");
         $wgOut->addHTML("<input type='hidden' name='output' value='wiki'>");
         $wgOut->addHTML("<input type='hidden' name='prefix' value='" . htmlentities($this->prefix(), ENT_QUOTES, 'UTF-8') . " '>");
         $wgOut->addHTML("<input type='hidden' name='query' >");
         $wgOut->addHTML(wfMsg('specialsparqlquery_endpointsparql') . " : <input type='text' name='endpoint' size='50' value='" . $endpoint . " '>");
         $wgOut->addHTML("<textarea name='queryWithoutPrefix' cols='25' rows='15'>");
         $strQuery = $queryWithoutPrefix != "" ? $queryWithoutPrefix : $this->exampleSparql(0);
         $wgOut->addHTML($strQuery);
         $wgOut->addHTML("</textarea>");
         $wgOut->addHTML("<br/>");
         $wgOut->addHTML("<script language='javascript' type='text/javascript' src='" . $wgScriptPath . "/extensions/LinkedWiki/js/bordercloud.js'></script>");
         $wgOut->addHTML("<SCRIPT>\r\n<!-- \r\nfunction validAndSendQuery(){\r\n\tvar query = document.formQuery.prefix.value + ' ' + document.formQuery.queryWithoutPrefix.value;\r\n\tif(! document.formQuery.toXML.checked){\r\n\t\tdocument.formQuery.query.value= query;\r\n\t\tdocument.formQuery.submit();\r\n\t}else{\t\t\r\n\t\twindow.open('" . $endpoint . "?query=' + escape(query.replace('\\n','')));\r\n\t}\r\n}\r\nfunction validWithJS(){\r\n\tvar query = document.formQuery.prefix.value + ' ' + document.formQuery.queryWithoutPrefix.value;\r\n\r\n\tbcValidateSPARQL('" . $endpoint . "',query);\r\n}\r\n//-->\r\n</SCRIPT>");
         $wgOut->addHTML("<input type='button' value='" . wfMsg('specialsparqlquery_sendquery') . "'  onClick='validAndSendQuery();' />");
         $wgOut->addHTML("<input type='button' value='(R&D) Validation (js)'  onClick='validWithJS();' />");
         $wgOut->addHTML("   Xml : <input type='checkbox'  name='toXML' />");
         $wgOut->addHTML(" </form>");
         $wgOut->addHTML("<div  id='bc_div'></div>");
         $wgOut->addHTML("<div style='display: none;'>");
         $wgOut->addHTML("<img id='canvas-image-wait' src='" . $wgScriptPath . "/extensions/LinkedWiki/js/wait.png'></img>");
         $wgOut->addHTML("</div>");
         if ($queryWithoutPrefix != "") {
             $sp = new Endpoint($endpoint);
             $rs = $sp->query($query);
             $errs = $sp->getErrors();
             if ($errs) {
                 $wgOut->addHTML("<h1>ERROR(s)</h1>\n");
                 foreach ($errs as $err) {
                     if (is_array($err)) {
                         foreach ($err as $suberr) {
                             $wgOut->addHTML("<pre>{$suberr}.</pre> \n");
                         }
                     } else {
                         if (preg_match("/bcjeton/i", $err) && (preg_match("/insert/i", $strQuery) || preg_match("/delete/i", $strQuery))) {
                             $wgOut->addHTML("<pre>You have not the right to write in the dataset.</pre> \n");
                         } else {
                             $wgOut->addHTML("<pre>{$err}.</pre> \n");
                         }
                     }
                 }
             } else {
                 //						//efSparqlParserFunction_simple( $querySparqlWiki,$endpoint ,$classHeaders = '',$headers = '', $debug = null)
                 $arr = efSparqlParserFunction_simple($query, $endpoint, '', '', null);
                 $wgOut->addWikiText($arr[0]);
                 $wgOut->addWikiText("==" . wfMsg('specialsparqlquery_usethisquery') . "==");
                 $wgOut->addWikiText(wfMsg('specialsparqlquery_usethisquery_tutorial'));
                 $wgOut->addHTML("<pre>{{#sparql:" . htmlentities($query, ENT_QUOTES, 'UTF-8') . "\n|endpoint=" . htmlentities($endpoint, ENT_QUOTES, 'UTF-8') . "}}</pre>");
             }
             //$wgOut->addWikiText("==".wfMsg('specialsparqlquery_linkxml')."==");
             //$queryurl= $endpoint."?query=".urlencode( str_replace('\n','',$query));
             //$wgOut->addHTML("<a href='$queryurl'>".htmlentities( $queryurl, ENT_QUOTES, 'UTF-8')."</a>");
         }
     }
     $this->setHeaders();
 }
コード例 #5
0
ファイル: LinkedWiki.php プロジェクト: aissatech/LinkedWiki
function efSparqlParserFunction_tableCell($querySparqlWiki, $endpoint, $debug = null)
{
    $specialC = array("&#39;");
    $replaceC = array("'");
    $querySparql = str_replace($specialC, $replaceC, $querySparqlWiki);
    $str = "";
    $sp = new Endpoint($endpoint);
    $rs = $sp->query($querySparqlWiki);
    $errs = $sp->getErrors();
    if ($errs) {
        $strerr = "";
        foreach ($errs as $err) {
            $strerr .= "'''Error #sparql :" . $err . "'''<br/>";
        }
        return $strerr;
    }
    $lignegrise = false;
    $variables = $rs['result']['variables'];
    $str = "";
    foreach ($rs['result']['rows'] as $row) {
        $str .= "\n";
        $separateur = "| ";
        foreach ($variables as $variable) {
            if ($row[$variable . " type"] == "uri") {
                $str .= $separateur . efSparqlParserFunction_uri2Link($row[$variable]);
            } else {
                $str .= $separateur . $row[$variable];
            }
            $separateur = " || ";
        }
        $str .= "\n|- \n";
    }
    if ($debug != null && $debug == "YES") {
        $str .= "INPUT WIKI : " . $querySparqlWiki . "\n";
        $str .= "Query : " . $querySparql . "\n";
        $str .= print_r($rs, true);
        $str .= print_r($rs, true);
        return array("<pre>" . $str . "</pre>", 'noparse' => true, 'isHTML' => false);
    }
    return array($str, 'noparse' => false, 'isHTML' => false);
}
コード例 #6
0
 static function insert($turtle, $graph, $endpoint)
 {
     $sp_write = new Endpoint($endpoint, false);
     $q = "INSERT DATA {  \n\t\t\t\t\t\tGRAPH <" . $graph . "> {    \n\t\t\t\t\t\t{$turtle}\n\t\t    \t\t}}";
     $res = $sp_write->query($q, 'raw');
     $err = $sp_write->getErrors();
     if ($err) {
         throw new Exception(self::buildMessage($err));
     }
     if (!$res) {
         $msg = "Query insert new triples return: False without errors";
         throw new Exception($msg);
     }
 }