I need to make a query in dbpedia and from that query return name, genre and other information of a certain singer. I am able to do this, however my code returns the entire tuple, I wanted to be able to separate the information by column. Can someone help me? Here is the code:
<?php
require_once('sparqllib.php');
$db = sparql_connect('http://dbpedia.org/sparql');
$query = " PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX owl: <http://dbpedia.org/ontology/>
PREFIX rsc: <http://dbpedia.org/resource/>
SELECT ?name ?hometown ?origin ?genre ?bandMember ?currentMembers ?associatedMusicalArtist
WHERE {
rsc:Arctic_Monkeys dbpedia2:name ?name.
rsc:Arctic_Monkeys owl:hometown ?hometown.
rsc:Arctic_Monkeys dbpedia2:origin ?origin .
rsc:Arctic_Monkeys dbpedia2:currentMembers ?currentMembers .
rsc:Arctic_Monkeys owl:genre ?genre .
rsc:Arctic_Monkeys owl:bandMember ?bandMember .
rsc:Arctic_Monkeys owl:associatedMusicalArtist ?associatedMusicalArtist .
FILTER ((LANG(?name) = 'en') AND (LANG(?origin) = 'en')).
}";
$result = sparql_query($query);
$fields = sparql_field_array($result);
while($row = sparql_fetch_array($result))
{
foreach($fields as $field)
{
print"$row[$field] \n";
}
}
?>