@Override public void abort() { try { close(); } catch (Exception ex) { log.warn("Error during abort", ex); } }
QueryEngineHTTP qe = new QueryEngineHTTP("http://drugbank.bio2rdf.org/sparql", pss.toString()); System.out.println(ResultSetFormatter.asText(qe.execSelect())); qe.close();
@Override public void sparqlConstructQuery(String queryStr, Model model) throws RDFServiceException { QueryEngineHTTP qeh = new QueryEngineHTTP( readEndpointURI, queryStr); try { qeh.execConstruct(model); } finally { qeh.close(); } }
/** * Performs a SPARQL ASK query against the knowledge base. The query may have * an embedded graph identifier. * * @param queryStr - the SPARQL query to be executed against the RDF store * * @return boolean - the result of the SPARQL query */ @Override public boolean sparqlAskQuery(String queryStr) throws RDFServiceException { QueryEngineHTTP qeh = new QueryEngineHTTP( readEndpointURI, queryStr); try { return qeh.execAsk(); } finally { qeh.close(); } }
void std_query() { String query = "select distinct ?super where {?super (^skos:broader){0,3} category:Nationalist_parties, category:New_Delhi}"; QueryEngineHTTP qe = new QueryEngineHTTP("http://dbpedia.org/sparql", query); try { com.hp.hpl.jena.query.ResultSet results = qe.execSelect(); while(results.hasNext()) { QuerySolution s=results.nextSolution(); String strg=s.getResource("?super").toString(); System.out.println("########### Standard Sparql Result #########"); System.out.println(strg); } //ResultSetFormatter.out(System.out, results, query); } finally { qe.close(); } }
@Override public void sparqlSelectQuery(String queryStr, ResultSetConsumer consumer) throws RDFServiceException { QueryEngineHTTP qeh = new QueryEngineHTTP( readEndpointURI, queryStr); try { consumer.processResultSet(qeh.execSelect()); } finally { qeh.close(); } }
/** * Performs a SPARQL describe query against the knowledge base. The query may have * an embedded graph identifier. * * @param queryStr - the SPARQL query to be executed against the RDF store * @param resultFormat - type of serialization for RDF result of the SPARQL query * * @return InputStream - the result of the query * */ @Override public InputStream sparqlDescribeQuery(String queryStr, RDFServiceImpl.ModelSerializationFormat resultFormat) throws RDFServiceException { Model model = ModelFactory.createDefaultModel(); QueryEngineHTTP qeh = new QueryEngineHTTP( readEndpointURI, queryStr); try { qeh.execDescribe(model); } finally { qeh.close(); } ByteArrayOutputStream serializedModel = new ByteArrayOutputStream(); model.write(serializedModel,getSerializationFormatString(resultFormat)); InputStream result = new ByteArrayInputStream(serializedModel.toByteArray()); return result; }
/** * Performs a SPARQL construct query against the knowledge base. The query may have * an embedded graph identifier. * * @param queryStr - the SPARQL query to be executed against the RDF store * @param resultFormat - type of serialization for RDF result of the SPARQL query */ @Override public InputStream sparqlConstructQuery(String queryStr, RDFServiceImpl.ModelSerializationFormat resultFormat) throws RDFServiceException { Model model = ModelFactory.createDefaultModel(); //Query query = QueryFactory.create(queryStr); //QueryExecution qe = QueryExecutionFactory.sparqlService(readEndpointURI, queryStr); QueryEngineHTTP qeh = new QueryEngineHTTP( readEndpointURI, queryStr); try { qeh.execConstruct(model); } finally { qeh.close(); } ByteArrayOutputStream serializedModel = new ByteArrayOutputStream(); model.write(serializedModel,getSerializationFormatString(resultFormat)); InputStream result = new ByteArrayInputStream(serializedModel.toByteArray()); return result; }
private Model execModel(Model model) { Pair<InputStream, Lang> p = execConstructWorker(modelContentType) ; try(InputStream in = p.getLeft()) { Lang lang = p.getRight() ; RDFDataMgr.read(model, in, lang); } catch (IOException ex) { IO.exception(ex); } finally { this.close(); } return model; }
private Dataset execDataset(Dataset dataset) { Pair<InputStream, Lang> p = execConstructWorker(datasetContentType); try(InputStream in = p.getLeft()) { Lang lang = p.getRight() ; RDFDataMgr.read(dataset, in, lang); } catch (IOException ex) { IO.exception(ex); } finally { this.close(); } return dataset; }
return false ; finally { this.close(); }
public static void main(String[] args) { FileManager.get().addLocatorClassLoader(ExampleARQ_01.class.getClassLoader()); String apikey = System.getenv("KASABI_API_KEY"); String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX italy: <http://data.kasabi.com/dataset/italy/schema/>" + "SELECT ?region WHERE { " + " ?region rdf:type italy:Region" + "}"; Query query = QueryFactory.create(queryString); QueryEngineHTTP qexec = (QueryEngineHTTP)QueryExecutionFactory.createServiceRequest("http://api.kasabi.com/dataset/italy/apis/sparql", query); qexec.addParam("apikey", apikey); try { ResultSet results = qexec.execSelect(); while ( results.hasNext() ) { QuerySolution soln = results.nextSolution(); Resource region = soln.getResource("region"); System.out.println(region.getURI()); } } finally { qexec.close(); } }
@Override public JsonArray execJson() { checkNotClosed(); HttpQuery httpQuery = makeHttpQuery(); httpQuery.setAccept(WebContent.contentTypeJSON); JsonArray result = new JsonArray(); try(InputStream in = httpQuery.exec()) { JsonValue v = JSON.parseAny(in); if ( ! v.isArray() ) throw new QueryExecException("Return from a JSON query isn't an array"); result = v.getAsArray(); } catch (IOException e) { IO.exception(e); } finally { this.close(); } return result; }