use of com.hp.hpl.jena.query.QuerySolution in project goci by EBISPOT.
the class SparqlPussycatSession method loadAssociations.
private List<URI> loadAssociations(SparqlTemplate sparqlTemplate, String queryString, List<Filter> filters) {
List<AssociationLocation> associationLocations = null;
if (filters.size() == 0) {
associationLocations = sparqlTemplate.query(queryString, /*had to add this line in to exclude "NR" bands as they break the AssociationLocation bit below
and can't be rendered anyway*/
new QuerySolutionMapper<AssociationLocation>() {
@Override
public AssociationLocation mapQuerySolution(QuerySolution qs) {
URI association = URI.create(qs.getResource("association").getURI());
String bandName = qs.getLiteral("band").getLexicalForm();
return new AssociationLocation(association, bandName);
}
});
} else if (filters.size() == 1) {
for (Filter filter : filters) {
if (filter.getFilteredType().equals(Association.class)) {
associationLocations = sparqlTemplate.query(queryString, /*had to add this line in to exclude "NR" bands as they break the AssociationLocation bit below
and can't be rendered anyway*/
new QuerySolutionMapper<AssociationLocation>() {
@Override
public AssociationLocation mapQuerySolution(QuerySolution qs) {
URI association = URI.create(qs.getResource("association").getURI());
String bandName = qs.getLiteral("band").getLexicalForm();
return new AssociationLocation(association, bandName);
}
}, filter.getFilteredValues().get(1), filter.getFilteredValues().get(0));
} else if (filter.getFilteredType().equals(Study.class)) {
associationLocations = sparqlTemplate.query(queryString, /*had to add this line in to exclude "NR" bands as they break the AssociationLocation bit below
and can't be rendered anyway*/
new QuerySolutionMapper<AssociationLocation>() {
@Override
public AssociationLocation mapQuerySolution(QuerySolution qs) {
URI association = URI.create(qs.getResource("association").getURI());
String bandName = qs.getLiteral("band").getLexicalForm();
return new AssociationLocation(association, bandName);
}
}, filter.getFilteredRange().to(), filter.getFilteredRange().from());
}
}
} else {
Object pval_min = null, pval_max = null, date_min = null, date_max = null;
for (Filter filter : filters) {
if (filter.getFilteredType().equals(Association.class)) {
pval_min = filter.getFilteredValues().get(0);
pval_max = filter.getFilteredValues().get(1);
} else if (filter.getFilteredType().equals(Publication.class)) {
date_min = filter.getFilteredRange().from();
date_max = filter.getFilteredRange().to();
}
}
associationLocations = sparqlTemplate.query(queryString, /*had to add this line in to exclude "NR" bands as they break the AssociationLocation bit below
and can't be rendered anyway*/
new QuerySolutionMapper<AssociationLocation>() {
@Override
public AssociationLocation mapQuerySolution(QuerySolution qs) {
URI association = URI.create(qs.getResource("association").getURI());
String bandName = qs.getLiteral("band").getLexicalForm();
return new AssociationLocation(association, bandName);
}
}, pval_max, pval_min, date_max, date_min);
}
Collections.sort(associationLocations);
List<URI> associations = new ArrayList<URI>();
for (AssociationLocation al : associationLocations) {
associations.add(al.getAssociation());
}
return associations;
}
use of com.hp.hpl.jena.query.QuerySolution in project goci by EBISPOT.
the class SparqlTemplate method label.
public String label(final URI entity) {
String sparql = getPrefixString().concat("SELECT DISTINCT ?label WHERE { <" + entity.toString() + "> rdfs:label ?label . }");
if (labelCache.containsKey(sparql)) {
return labelCache.get(sparql);
}
String result = query(sparql, new ResultSetMapper<String>() {
@Override
public String mapResultSet(ResultSet rs) {
String result = null;
while (rs.hasNext()) {
if (result != null) {
throw new SparqlQueryException(new DataIntegrityViolationException("More than one rdfs:label for' " + entity.toString() + "'"));
}
QuerySolution qs = rs.next();
result = qs.getLiteral("label").getLexicalForm();
}
if (result == null) {
result = "Annotation tbc";
}
return result;
}
});
labelCache.put(sparql, result);
return result;
}
use of com.hp.hpl.jena.query.QuerySolution in project nextprot-api by calipho-sib.
the class DiffBaseTest method getCountForSparql.
private int getCountForSparql() {
long t0 = System.currentTimeMillis();
String query = sparqlDictionary.getSparqlWithPrefixes(qName);
QueryExecution qExec = sparqlService.queryExecution(query);
com.hp.hpl.jena.query.ResultSet rs = qExec.execSelect();
QuerySolution qs = rs.next();
Literal lit = qs.getLiteral("cnt");
int count = lit.getInt();
timeSPARQL = (int) (System.currentTimeMillis() - t0);
countSPARQL = count;
return countSPARQL;
}
use of com.hp.hpl.jena.query.QuerySolution in project nextprot-api by calipho-sib.
the class RdfHelpServiceImpl method getTripleInfoList.
@Override
public List<TripleInfo> getTripleInfoList(String rdfType) {
String queryBase = sparqlDictionary.getSparqlWithPrefixes("typepred");
Set<TripleInfo> tripleList = new TreeSet<TripleInfo>();
try {
String query = sparqlDictionary.getSparqlOnly("prefix");
query += queryBase.replace(":SomeRdfType", rdfType);
QueryExecution qExec = sparqlService.queryExecution(query);
ResultSet rs = qExec.execSelect();
while (rs.hasNext()) {
QuerySolution sol = rs.next();
TripleInfo ti = new TripleInfo();
String pred = (String) getDataFromSolutionVar(sol, "pred");
String sspl = (String) getDataFromSolutionVar(sol, "subjSample");
String ospl = (String) getDataFromSolutionVar(sol, "objSample", true);
String spl = sspl + " " + pred + " " + ospl + " .";
ti.setTripleSample(spl);
ti.setPredicate(pred);
ti.setSubjectType((String) getDataFromSolutionVar(sol, "subjType"));
String objectType = (String) getDataFromSolutionVar(sol, "objType");
if (objectType.length() == 0) {
objectType = getObjectTypeFromSample(sol, "objSample");
ti.setLiteralType(true);
}
ti.setObjectType(objectType);
ti.setTripleCount(Integer.valueOf((String) getDataFromSolutionVar(sol, "objCount")));
LOGGER.info(ti);
tripleList.add(ti);
}
qExec.close();
} catch (Exception e) {
incrementErrors();
System.err.println("Error with " + rdfType);
e.printStackTrace();
LOGGER.error("Error with " + rdfType, e);
}
return new ArrayList<TripleInfo>(tripleList);
}
use of com.hp.hpl.jena.query.QuerySolution in project eol-globi-data by jhpoelen.
the class StudyImporterForSaproxylic method toInteractions.
public void toInteractions(ResultSet results) throws StudyImporterException {
final InteractionListener listener = new InteractionListenerImpl(nodeFactory, getGeoNamesService(), getLogger());
while (results.hasNext()) {
QuerySolution next = results.next();
Iterator<String> nameIter = next.varNames();
Map<String, String> props = new TreeMap<>();
while (nameIter.hasNext()) {
String key = nameIter.next();
RDFNode rdfNode = next.get(key);
if (rdfNode.isURIResource()) {
props.put(key, next.getResource(key).getURI());
} else {
props.put(key, next.getLiteral(key).getString());
}
}
props.put(StudyImporterForTSV.STUDY_SOURCE_CITATION, getDataset().getCitation());
listener.newLink(props);
}
}
Aggregations