简体   繁体   English

如何使用EasyRdf获取SPARQL查询结果

[英]How to fetch SPARQL query result using EasyRdf

Using EasyRdf, I want to fetch query result. 我想使用EasyRdf来获取查询结果。 I used below code in codeigniter: 我在codeigniter中使用了以下代码:

$this->load->library('rdf');
EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns');
EasyRdf_Namespace::set('srt', 'http://persuratan-semweb.dev/ontologies/surat.owl');
$sparql = new EasyRdf_Sparql_Client('http://localhost:3030/surat_single/sparql');

$query = "SELECT * WHERE { "
            . "?surat rdf:type srt:Surat . "
            . "?surat srt:sifat_surat ?sifat_surat . "
            . "?surat srt:nomor_surat ?nomor_surat . }";
$result = $sparql->query($query);

echo "jumlah data: " . $result->numRows() . "<br>";
echo "<br>";

foreach ($result as $row) {
    echo $row->sifat_surat . " " .$row->sifat_surat . " " . $row->nomor_surat ."<br>";
}

print_r($result);

The output I got are: 我得到的输出是:

jumlah data: 0

EasyRdf_Sparql_Result Object ( 
    [type:EasyRdf_Sparql_Result:private] => bindings
    [boolean:EasyRdf_Sparql_Result:private] =>
    [ordered:EasyRdf_Sparql_Result:private] =>
    [distinct:EasyRdf_Sparql_Result:private] =>
    [fields:EasyRdf_Sparql_Result:private] => Array ( 
        [0] => surat
        [1] => sifat_surat 
        [2] => nomor_surat 
    ) 
    [storage:ArrayIterator:private] => Array ( )
)

I also try Joshua's solution given here , but got similar output. 我也尝试此处给出的Joshua解决方案,但得到了类似的输出。 I also try my query in Fuseki endpoint (I'm using Fuseki triplestore) and got this result . 我也尝试在Fuseki端点中查询(我正在使用Fuseki Triplestore),并得到此结果 I'm completely beginer in semantic web. 我完全是语义网的初学者。

I don't know whether it's the answer or not, but these namespaces don't look right to me: 我不知道这是否是答案,但是这些命名空间在我看来并不正确:

EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns');
EasyRdf_Namespace::set('srt', 'http://persuratan-semweb.dev/ontologies/surat.owl');

The rdf namespace should have a # at the end, and you should probably have one for your OWL file, too: rdf名称空间的末尾应带有#,并且您的OWL文件也可能也应带有一个:

EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
EasyRdf_Namespace::set('srt', 'http://persuratan-semweb.dev/ontologies/surat.owl#');

But that said, there's no reason you can't try a simpler query first. 但这就是说,没有理由您不能首先尝试更简单的查询。 Why not just run 为什么不跑

SELECT ?s ?p ?o { ?s ?p ?o }

to be sure that you can get results, and what the data is. 确保您可以获得结果以及数据是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM