简体   繁体   中英

How to fetch SPARQL query result using EasyRdf

Using EasyRdf, I want to fetch query result. I used below code in 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. I also try my query in Fuseki endpoint (I'm using Fuseki triplestore) and got this result . 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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