How to get the result of the query separated by columns?

3

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";
      }
    }
?>
    
asked by anonymous 11.05.2014 / 15:59

2 answers

1

Just put the column by its index.

print ( $row['name']."\n".$row['origin'] );

I do not know in Linux, but in Windows for \n break the line, you need the nl2br function.

Getting:

print nl2br( ( $row['name']."\n".$row['origin'] ) );
    
14.05.2014 / 04:25
-1

How about trying with Freebase.com ?

{ "id": null, "name": "Arctic Monkeys", "type": "/ music / artist" }

Freebase also uses Wikipedia data and all requests are in JSON, so it's easy to ask for any specific information.

    
12.05.2014 / 05:42