Leon D'souza
Leon D'souza

Reputation: 30

Can't fetch data from dbpedia using SPARQL Query

I'm trying to fetch information about countries from dbpedia using the following code. However, I dont get any. Also the way to find such information of possible.

public void getCountriesInformation() throws FileNotFoundException, IOException {
    {   
        System.out.println(listOfCountries);
        ParameterizedSparqlString qs = new ParameterizedSparqlString("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n "
                + "SELECT * {     ?Subject rdf:type <http://dbpedia.org/page/" + listOfCountries.get(0) +"> .     ?Subject ?Predicate ?Object } ORDER BY ?Subject LIMIT 10000 OFFSET 10000");

        QueryExecution exec = QueryExecutionFactory.sparqlService("https://dbpedia.org/sparql", qs.asQuery());
        //exec.setTimeout(10000000);
        exec.setTimeout(10, TimeUnit.MINUTES);
        ResultSet results = exec.execSelect();
        ResultSetFormatter.outputAsCSV(new FileOutputStream(new File("C:/Users/leons/Desktop/CountryData.csv")), results);
        //ResultSetFormatter.out(results);
    }
    //CSVCountryNameFetcher countryNameFetcher = new CSVCountryNameFetcher();
    //countryNameFetcher.fetchDataFromCSV();
}

Upvotes: 0

Views: 136

Answers (1)

UninformedUser
UninformedUser

Reputation: 8465

The whole query is wrong:

  1. countries are resource in DBpedia, thus, they will not occur in a triple in object position with the predicate rdf:type. This wouldn't make any sense.

  2. The namespace of DBpedia is http://dbpedia.org/resource/

An example query would be

SELECT * WHERE {
  <http://dbpedia.org/resource/France> ?p ?o .
}

Upvotes: 1

Related Questions