use of com.hp.hpl.jena.query.QueryParseException in project nextprot-api by calipho-sib.
the class SparqlServiceImpl method findEntries.
@Override
@Cacheable("sparql")
public List<String> findEntries(String sparql, String sparqlEndpointUrl, String sparqlTitle) {
String query = SparqlUtils.buildQuery(prefix, sparql);
List<String> results = new ArrayList<String>();
QueryExecution qExec = null;
try {
qExec = QueryExecutionFactory.sparqlService(sparqlEndpointUrl, query);
} catch (QueryParseException qe) {
String msg = ExceptionUtils.fixLineNumberInErrorMessage(qe.getLocalizedMessage());
throw new NextProtException("Malformed SPARQL: " + msg);
}
ResultSet rs = qExec.execSelect();
/**
* This give an empty graph....
* Model m = rs.getResourceModel();
* Graph g = m.getGraph();
* System.err.println("The graph is" + g);
*/
Var x = Var.alloc("entry");
while (rs.hasNext()) {
Binding b = rs.nextBinding();
Node entryNode = b.get(x);
if (entryNode == null) {
qExec.close();
throw new NextProtException("Bind your protein result to a variable called ?entry. Example: \"?entry :classifiedWith cv:KW-0813.\"");
} else if (entryNode.toString().indexOf(ENTRY_SUFFIX_URI) == -1) {
qExec.close();
throw new NextProtException("Any entry found in the output, however was found: " + entryNode.toString());
}
String entry = entryNode.toString().replace(ENTRY_SUFFIX_URI, "").trim();
results.add(entry);
}
qExec.close();
return results;
}
use of com.hp.hpl.jena.query.QueryParseException in project nextprot-api by calipho-sib.
the class SparqlServiceImpl method sparqlSelect.
@Override
public SparqlResult sparqlSelect(String sparql, String sparqlEndpointUrl, int timeout, String queryTitle, String testId, ResultsFormat format) {
SparqlResult result = null;
try {
QueryExecution qExec = QueryExecutionFactory.sparqlService(sparqlEndpointUrl, sparql);
qExec.setTimeout(timeout);
ResultSet rs = qExec.execSelect();
result = SparqlUtils.convertResultToFormat(rs, format);
qExec.close();
} catch (QueryParseException qe) {
String msg = ExceptionUtils.fixLineNumberInErrorMessage(qe.getLocalizedMessage());
throw new NextProtException("Malformed SPARQL: " + msg);
}
return result;
}
Aggregations