use of com.hp.hpl.jena.sparql.core.Var 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.sparql.core.Var in project stanbol by apache.
the class RdfIndexingSource method debug.
public void debug() {
String entityVar = "s";
String fieldVar = "p";
String valueVar = "o";
StringBuilder qb = new StringBuilder();
qb.append(String.format("SELECT ?%s ?%s ?%s \n", entityVar, fieldVar, // for the select
valueVar));
qb.append("{ \n");
qb.append(String.format(" ?%s ?%s ?%s . \n", entityVar, fieldVar, // for the where
valueVar));
qb.append("} \n");
log.debug("EntityDataIterator Query: \n" + qb.toString());
Query q = QueryFactory.create(qb.toString(), Syntax.syntaxARQ);
ResultSet rs = QueryExecutionFactory.create(q, indexingDataset.toDataset()).execSelect();
Var s = Var.alloc(entityVar);
Var p = Var.alloc(fieldVar);
Var o = Var.alloc(valueVar);
while (rs.hasNext()) {
Binding b = rs.nextBinding();
log.debug("{} {} {}", new Object[] { b.get(s), b.get(p), b.get(o) });
}
}
Aggregations