dongzanghui4624 2019-04-23 23:18
浏览 100

如何使用php使用sparql查询本地本体

I am working on a semantic web project where I want to query an ontology to retrieve saved classes or instances in this ontology using php to display them in a web page. I find some examples but they did not work in my case

So I have tried two libs in php once called ARC2.php and the other sparqllib.php but I got no results

require_once( "sparqllib.php" );
$db = sparql_connect( "http://sparql.data.southampton.ac.uk/" );
if( !$db ) { print sparql_errno() . ": " . sparql_error(). "
"; exit; }
sparql_ns( "rooms","http://vocab.deri.ie/rooms#" ); 
$sparql = "SELECT DISTINCT * WHERE { ?room a rooms:Building . ?room rdfs:label ?label } LIMIT 5";
$result = sparql_query( $sparql ); 

/////////////////////////////////

include_once('semsol/ARC2.php');  
$dbpconfig = array(
  "remote_store_endpoint" => "http://dbpedia.org/sparql",
);
$store = ARC2::getRemoteStore($dbpconfig); 
if ($errs = $store->getErrors()) {
     echo "<h1>getRemoteSotre error<h1>" ;
}
$query = '';
$rows = $store->query($query, 'rows');

So with the first one i have got an error look like this : -1: Didn't even see a sparql element, is this really an endpoint? because i don't even know how to remplace $db = sparql_connect( "" ); with my local ontology or what ? And for the second code i don't know if i got an empety result or no result knowing that my query is coorect need help please

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程