Commits

Anonymous committed 3897439

Fix up item info SPARQL query to play nicely with 4store

  • Participants
  • Parent commits 69cc165

Comments (0)

Files changed (2)

File chempound-api/src/main/java/net/chempound/datastore/QueriedItemInfoMapper.java

-package net.chempound.datastore;
-
-import com.hp.hpl.jena.query.QuerySolution;
-import com.hp.hpl.jena.rdf.model.RDFNode;
-import net.chempound.bean.ItemInfo;
-import net.chempound.bean.ItemInfoBuilder;
-
-import java.net.URI;
-
-/**
- * @author Sam Adams
- */
-public class QueriedItemInfoMapper implements QuerySolutionMapper<ItemInfo> {
-
-    private final URI uri;
-
-    public QueriedItemInfoMapper(final URI uri) {
-        this.uri = uri;
-    }
-
-    @Override
-    public ItemInfo map(final QuerySolution querySolution) {
-        final RDFNode title = querySolution.get("title");
-        final RDFNode thumbnail = querySolution.get("thumbnail");
-        final RDFNode dataType = querySolution.get("type");
-        final ItemInfoBuilder builder = new ItemInfoBuilder(uri);
-        if (title != null) {
-            builder.setTitle(title.asLiteral().getString());
-        }
-        if (thumbnail != null) {
-            builder.setThumbnailUri(thumbnail.asResource().getURI());
-        }
-        if (dataType != null) {
-            builder.setDataType(dataType.asLiteral().getString());
-        }
-        return builder.build();
-    }
-
-}

File chempound-app/src/main/java/net/chempound/datastore/AbstractTripleStore.java

              "PREFIX ore: <" + ORE_NS + ">\n" +
              "PREFIX foaf: <" + FOAF_NS + ">\n" +
              "" +
-             "SELECT ?title ?type ?thumbnail" +
+             "SELECT DISTINCT ?uri ?title ?type ?thumbnail" +
              "  WHERE {" +
              "    ?uri a <http://wwmm.ch.cam.ac.uk/chempound/terms/Item> ." +
              "    OPTIONAL {" +
              "    OPTIONAL {" +
              "      ?uri dct:type [ rdfs:label ?type ] ." +
              "    }" +
+             "    FILTER (?uri = ?URI) " +
              "  }"
     );
 
              "PREFIX rdf: <" + RDF_NS + ">\n" +
              "PREFIX dct: <" + DCTERMS_NS + ">\n" +
              "" +
-             "SELECT ?mime" +
+             "SELECT DISTINCT ?mime" +
              "  WHERE {" +
              "    ?uri dct:format [" +
              "          a dct:IMT ;" +
     protected static final Query QUERY_REM_AGGREGATION = QueryFactory.create("" +
         "PREFIX ore: <" + ORE_NS + ">\n" +
         "" +
-        "SELECT ?aggr" +
+        "SELECT DISTINCT ?aggr" +
         "  WHERE {" +
         "    ?rem ore:describes ?aggr" +
         "  }"
     @Override
     public final ItemInfo getItemInfo(final URI uri) {
         final QuerySolutionMap initialBinding = new QuerySolutionMap();
-        initialBinding.add("uri", ResourceFactory.createResource(uri.toString()));
-        return executeSelectFirst(QUERY_ITEM_INFO, initialBinding, new QueriedItemInfoMapper(uri));
+        initialBinding.add("URI", ResourceFactory.createResource(uri.toString()));
+        return executeSelectFirst(QUERY_ITEM_INFO, initialBinding, new ItemInfoMapper());
     }
 
     @Override