Could not handle ?university dbpedia-owl:count in ARC2

时间:2015-06-26 10:19:01

标签: php sparql dbpedia

I'm using simple SPARQL query to get a list of universities for selected country. and that some of SPARQL code

SELECT ?name ?type 
WHERE 
  {   ?university  a                    <http://schema.org/CollegeOrUniversity>
    { ?university  dbpedia-owl:country  dbpedia:France }
    UNION
    { ?university  dbpprop:country      dbpedia:France }
    OPTIONAL
    { ?university  dbpprop:name         ?name          .
         FILTER (LANGMATCHES(LANG(?name), 'fr'))       }
    OPTIONAL
    { ?university  dbpedia-owl:type     ?type          } 

To show a result in PHP side, I'm using ARC2 library to use PHP to query SPARQL endpoints and generate HTML pages. All steps from the doc is ok.

Here that full PHP code with SPARQL query server side:

<html>
  <body>

  <?php
  include_once('semsol/ARC2.php'); /* ARC2 static class inclusion */ 

  $dbpconfig = array(
  "remote_store_endpoint" => "http://dbpedia.org/sparql",
   );

  $store = ARC2::getRemoteStore($dbpconfig); 

  if ($errs = $store->getErrors()) {
     echo "<h1>getRemoteSotre error<h1>" ;
  }

  $query = '
        PREFIX     foaf:  <http://xmlns.com/foaf/0.1/> 
        PREFIX       dc:  <http://purl.org/dc/elements/1.1>
        PREFIX      rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
        PREFIX  address:  <http://www.w3.org/Addressing/schemes.html>
        PREFIX     rdfs:  <http://www.w3.org/2000/01/rdf-schema#>


      SELECT ?name ?type 
             WHERE {
                       ?university  a                     <http://schema.org/CollegeOrUniversity>
                     { ?university  dbpedia-owl:country   dbpedia:France }
                   UNION
                     { ?university  dbpprop:country       dbpedia:France }
                   OPTIONAL
                     { ?university  dbpprop:name          ?name          .
                          FILTER (LANGMATCHES(LANG(?name), 'fr'))        }
                   OPTIONAL
                     { ?university  dbpedia-owl:type      ?type          }  
                   }
             ORDER BY ?name
          ';


  $rows = $store->query($query, 'rows'); /* execute the query */

  if ($errs = $store->getErrors()) {
     echo "Query errors" ;
     print_r($errs);
  }

  /* display the results in an HTML table */
  echo "<table border='1'>" ;
  foreach( $rows as $row ) { /* loop for each returned row */
         print "<tr><td>" .$row['l'] . "</td><td>" . $row['c']. "</td></tr>";
  }
  echo "</table>"

  ?>
  </body>
</html>

but when I run my code on server side that's error handling

Query errorsArray ( [0] => Incomplete or invalid Group Graph pattern. Could not handle " ?university dbpedia-owl:count" in ARC2_SPARQLPlusParser [1] => Incomplete or invalid Group Graph pattern. Could not handle " { ?univers" in ARC2_SPARQLPlusParser )

So is there any solution? Many thanks

1 个答案:

答案 0 :(得分:1)

您的查询不包含 dbpedia-owl dbpedia dbpprop 的前缀。当您以交互方式使用Web服务时,这些是自动定义的,但是当您远程连接时,仍然需要包含它们。您可以看到在浏览器中定义的full list of prefixes

猜测发生的事情是,当你到达 dbpedia-owl:count 时,它会意识到它是 count ,是一个合法的SPARQL关键字,然后意识到 dbpedia-owl:没有意义。 (但我不熟悉ARC的解析器;这只是猜测。)

我希望您也可以通过以下方式遇到问题:

$query = '...'fr'...';

我不是PHP用户,因此我不确定如何处理,但看起来就像那些单引号需要转义,或者你需要使用双引号。< / p>