Search in sources :

Example 1 with QuerySolutionMapper

use of uk.ac.ebi.spot.goci.sparql.pussycat.query.QuerySolutionMapper 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;
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) QuerySolutionMapper(uk.ac.ebi.spot.goci.sparql.pussycat.query.QuerySolutionMapper) Association(uk.ac.ebi.spot.goci.model.Association) QuerySolution(com.hp.hpl.jena.query.QuerySolution) Filter(uk.ac.ebi.spot.goci.pussycat.lang.Filter)

Aggregations

QuerySolution (com.hp.hpl.jena.query.QuerySolution)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Association (uk.ac.ebi.spot.goci.model.Association)1 Filter (uk.ac.ebi.spot.goci.pussycat.lang.Filter)1 QuerySolutionMapper (uk.ac.ebi.spot.goci.sparql.pussycat.query.QuerySolutionMapper)1