SPARQL { public SPARQL() { try { CacheFrontend cacheFrontend = CacheUtilsH2.createCacheFrontend("./sparql", true, timeToLive); qef = FluentQueryExecutionFactory.http(SPARQLEndpoints.DBPEDIA_ORG).config().withCache(cacheFrontend).end().create(); } catch (RuntimeException e) { log.error("Could not create SPARQL interface! ", e); } } SPARQL();  SPARQL(final String endpoint); Set<RDFNode> sparql(final String query); static Set<String> extractAnswerStrings(final Set<RDFNode> answers); static Results executeSelect(final String query, final String endpoint); static Boolean executeAsk(final String query, final String endpoint); long getCacheTimeToLive(); void setCacheTimeToLive(final long timeToLive); static boolean isValidSparqlQuery(final String sparql); static boolean isEndpointAlive(final String endpoint); public QueryExecutionFactory qef; }
@Test public void dbpediaTest() { log.debug("Trying to query dbpedia...(Timeout 5s)"); String query = "PREFIX dbo: <http: String answer = "[http: String realAnswer = ""; realAnswer = new ThreadedSPARQL(5, SPARQLEndpoints.DBPEDIA_ORG).sparql(query).toString(); Assert.assertTrue("Answersets differ", answer.equals(realAnswer)); }
@Test public void wikidataTest() throws ExecutionException { log.debug("Trying to query wikidata...(Timeout 5s)"); String query = "SELECT DISTINCT ?company WHERE {?company <http: String answer = "[http: String realAnswer = ""; realAnswer = new SPARQL(SPARQLEndpoints.WIKIDATA_ORG).sparql(query).toString(); Assert.assertTrue("Answersets differ", answer.equals(realAnswer)); }