Extract data from DBpedia (connecting sparql endpoint from java)

IvetX :

I need to extract some data from DBpedia. I know that I can use http://dbpedia.org/snorql/ and write a query there and then see a result. But is there any tool/class to connect DBpedia endpoint from java, write query in a code and then get result in a file?

Jeen Broekstra :

Yes, there are several, of which Apache Jena and Eclipse RDF4J are probably the most well-known.

Here's a simple example executing a SPARQL query on the DBPedia endpoint from Java and printing the result, using RDF4J:

  Repository endpoint = new SPARQLRepository("http://dbpedia.org/sparql");
  try (RepositoryConnection conn = endpoint.getConnection()) {
        TupleQueryResult result = conn.prepareTupleQuery("SELECT * WHERE { ?s ?p ?o } LIMIT 10").evaluate();
        result.forEach(System.out::println);
  }

To get the result in a file is of course also possible. I suggest you have a look at the project documentation to find out more about the possibilities.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=378690&siteId=1