@@ -0,0 +1,3773 @@
+package org.geneontology.minerva.json;%0A%0Aimport com.google.gson.Gson;%0Aimport com.google.gson.JsonArray;%0Aimport com.google.gson.JsonElement;%0Aimport com.google.gson.JsonObject;%0Aimport org.geneontology.minerva.curie.CurieHandler;%0Aimport org.openrdf.query.GraphQueryResult;%0Aimport org.openrdf.query.QueryEvaluationException;%0Aimport org.openrdf.query.TupleQueryResult;%0Aimport org.openrdf.query.TupleQueryResultHandlerException;%0Aimport org.openrdf.query.resultio.QueryResultIO;%0Aimport org.openrdf.query.resultio.TupleQueryResultFormat;%0Aimport org.openrdf.rio.RDFFormat;%0Aimport org.openrdf.rio.RDFHandlerException;%0Aimport org.semanticweb.owlapi.model.IRI;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0Aimport java.util.Map;%0A%0Apublic class SPARQLResultJSONRenderer %7B%0A%0A    private final CurieHandler curieHandler;%0A%0A    public SPARQLResultJSONRenderer(CurieHandler curieHandler) %7B%0A        this.curieHandler = curieHandler;%0A    %7D%0A%0A    public JsonObject renderResults(TupleQueryResult sparqlResults) throws QueryEvaluationException, IOException, TupleQueryResultHandlerException %7B%0A        ByteArrayOutputStream stream = new ByteArrayOutputStream();%0A        QueryResultIO.write(sparqlResults, TupleQueryResultFormat.JSON, stream);%0A        String json = stream.toString(%22UTF-8%22);%0A        stream.close();%0A        JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);%0A        JsonArray bindings = jsonObject.get(%22results%22).getAsJsonObject().getAsJsonArray(%22bindings%22);%0A        for (JsonElement bindingSet : bindings) %7B%0A            for (Map.Entry%3CString, JsonElement%3E binding : bindingSet.getAsJsonObject().entrySet()) %7B%0A                JsonObject value = binding.getValue().getAsJsonObject();%0A                if (value.getAsJsonPrimitive(%22type%22).getAsString().equals(%22uri%22)) %7B%0A                    String uri = value.getAsJsonPrimitive(%22value%22).getAsString();%0A                    String curie = curieHandler.getCuri(IRI.create(uri));%0A                    value.addProperty(%22value%22, curie);%0A                %7D%0A            %7D%0A        %7D%0A        return jsonObject;%0A    %7D%0A%0A    public JsonObject renderGraph(GraphQueryResult result) throws QueryEvaluationException, IOException, RDFHandlerException %7B%0A        ByteArrayOutputStream stream = new ByteArrayOutputStream();%0A        QueryResultIO.write(result, RDFFormat.RDFJSON, stream);%0A        String json = stream.toString(%22UTF-8%22);%0A        stream.close();%0A        JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);%0A        JsonObject newJsonObject = new JsonObject();%0A        for (Map.Entry%3CString, JsonElement%3E subject : jsonObject.entrySet()) %7B%0A            String subjectCurie = curieHandler.getCuri(IRI.create(subject.getKey()));%0A            JsonObject predicatesAndValues = subject.getValue().getAsJsonObject();%0A            JsonObject newPredicatesAndValues = new JsonObject();%0A            for (Map.Entry%3CString, JsonElement%3E predicate : predicatesAndValues.entrySet()) %7B%0A                String predicateCurie = curieHandler.getCuri(IRI.create(predicate.getKey()));%0A                for (JsonElement value : predicate.getValue().getAsJsonArray()) %7B%0A                    JsonObject valueObj = value.getAsJsonObject();%0A                    if (valueObj.getAsJsonPrimitive(%22type%22).getAsString().equals(%22uri%22)) %7B%0A                        String uri = valueObj.getAsJsonPrimitive(%22value%22).getAsString();%0A                        String curie = curieHandler.getCuri(IRI.create(uri));%0A                        valueObj.addProperty(%22value%22, curie);%0A                    %7D%0A                %7D%0A                newPredicatesAndValues.add(predicateCurie, predicate.getValue());%0A                newJsonObject.add(subjectCurie, newPredicatesAndValues);%0A            %7D%0A        %7D%0A        return newJsonObject;%0A%0A    %7D%0A%0A%7D%0A

Add new file.