From 136686967a330995045a9d8e729f47710676f546 Mon Sep 17 00:00:00 2001 From: goodb Date: Tue, 25 Jun 2019 13:28:27 -0700 Subject: [PATCH 01/20] very basic service framework in place - now to actually implement search --- minerva-cli/.DS_Store | Bin 0 -> 6148 bytes minerva-server/pom.xml | 5 ++ .../minerva/server/StartUpTool.java | 3 +- .../server/handler/ModelSearchHandler.java | 62 ++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 minerva-cli/.DS_Store create mode 100644 minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java diff --git a/minerva-cli/.DS_Store b/minerva-cli/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b448ec01691ac613cc20409857c0da09227209ed GIT binary patch literal 6148 zcmeHKQEL-H5S~q9n^43&2o<01Mere%#D-cZg(KF7z7Lz4Ir$eD;Ipe!L>V$o`DKI`ot zo}7RFGXJ{x_QRfq!r#=$Bf%y7gd!V^^I;m{C$g)UE`mvx>g*I2wyx8dG@a8HeL|nE z@b(KHRo-%%(6H*IHgES@E{<7Rqk=+&p3;blmGJK?;T7LylI3POnG?r=W56+RodLNY znj6=RPInAA1{?!mfbR!S&=)K%nyUkyDFJ{Dn2kU;AOAp)4M1P8v$QJmXHvx9EDufMcM_K-~`8{QkebyZ)~RxshYQ zG4Nk8pc)6k!2ny5xAn&6_^tKOPS9A`ue5j-0>wPV@a3oY37QeuJyw9eU}+H+i2D#Q MG`P+&aIXyf1>+oybpQYW literal 0 HcmV?d00001 diff --git a/minerva-server/pom.xml b/minerva-server/pom.xml index 7b21bab0..20e19501 100644 --- a/minerva-server/pom.xml +++ b/minerva-server/pom.xml @@ -118,5 +118,10 @@ org.glassfish.jersey.containers jersey-container-servlet-core + + org.glassfish.jersey.media + jersey-media-json-processing + 2.28 + diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java b/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java index 4fc26a0d..f9193a43 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java @@ -379,7 +379,8 @@ public static Server startUp(UndoAwareMolecularModelManager models, MinervaStart SimpleEcoMapper ecoMapper = EcoMapperFactory.createSimple(); JsonOrJsonpSeedHandler seedHandler = new JsonOrJsonpSeedHandler(models, conf.defaultModelState, conf.golrSeedUrl, ecoMapper ); SPARQLHandler sparqlHandler = new SPARQLHandler(models, conf.sparqlEndpointTimeout); - resourceConfig = resourceConfig.registerInstances(batchHandler, seedHandler, sparqlHandler); + ModelSearchHandler searchHandler = new ModelSearchHandler(models, conf.sparqlEndpointTimeout); + resourceConfig = resourceConfig.registerInstances(batchHandler, seedHandler, sparqlHandler, searchHandler); // setup jetty server port, buffers and context path Server server = new Server(); diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java new file mode 100644 index 00000000..f156c759 --- /dev/null +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -0,0 +1,62 @@ +/** + * + */ +package org.geneontology.minerva.server.handler; + +import javax.ws.rs.Consumes; +import javax.ws.rs.FormParam; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.geneontology.minerva.BlazegraphMolecularModelManager; +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.QueryEvaluationException; +import org.openrdf.query.QueryResult; +import org.openrdf.repository.RepositoryException; + +/** + * Respond to queries for models in the running blazegraph instance backing minerva + * + */ +@Path("/modelsearch") +public class ModelSearchHandler { + + private final BlazegraphMolecularModelManager m3; + private final int timeout; + /** + * + */ + public ModelSearchHandler(BlazegraphMolecularModelManager m3, int timeout) { + this.m3 = m3; + this.timeout = timeout; + } + + public class Result { + private Integer id; + private String name; + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Result searchGet(@QueryParam("query") String queryText) { + // return m3.executeModelSearch(queryText, timeout); + //test + //http://127.0.0.1:6800/modelsearch/?query=bla + Result r = new Result(); + r.id = 9; r.name = "fred"; + return r; + } + + @POST + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public String searchPostForm(@FormParam("query") String queryText) { + // return m3.executeSPARQLQuery(queryText, timeout); + return "post pong"; + } + +} From 1c3f5a6062e18633614ae797e1b9308654d6cfff Mon Sep 17 00:00:00 2001 From: goodb Date: Tue, 25 Jun 2019 16:26:13 -0700 Subject: [PATCH 02/20] service working with all model query to local blazegraph --- .../server/handler/ModelSearchHandler.java | 56 ++++++++++++++++--- .../src/main/resources/GetAllModels.rq | 21 +++++++ 2 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 minerva-server/src/main/resources/GetAllModels.rq diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index f156c759..b9e49af9 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -3,6 +3,11 @@ */ package org.geneontology.minerva.server.handler; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.HashSet; +import java.util.Set; + import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; import javax.ws.rs.GET; @@ -12,10 +17,13 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.apache.commons.io.IOUtils; import org.geneontology.minerva.BlazegraphMolecularModelManager; +import org.openrdf.query.BindingSet; import org.openrdf.query.MalformedQueryException; import org.openrdf.query.QueryEvaluationException; import org.openrdf.query.QueryResult; +import org.openrdf.query.TupleQueryResult; import org.openrdf.repository.RepositoryException; /** @@ -35,19 +43,53 @@ public ModelSearchHandler(BlazegraphMolecularModelManager m3, int timeout) { this.timeout = timeout; } - public class Result { - private Integer id; - private String name; + public class ModelSearchResult { + private Integer n; + private Set models; + } + + public class ModelMeta{ + private String id; + private String date; + private String title; + private String state; + private String contributors; + + public ModelMeta(String id, String date, String title, String state, String contributors) { + this.id = id; + this.date = date; + this.title = title; + this.state = state; + this.contributors = contributors; + } } + @GET @Produces(MediaType.APPLICATION_JSON) - public Result searchGet(@QueryParam("query") String queryText) { - // return m3.executeModelSearch(queryText, timeout); + public ModelSearchResult searchGet(@QueryParam("query") String queryText) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + ModelSearchResult r = new ModelSearchResult(); + Set models = new HashSet(); + String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/GetAllModels.rq"), StandardCharsets.UTF_8); + //?id ?date ?title ?state (GROUP_CONCAT(?contributor;separator=";") AS ?contributors + TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 10); + int n_models = 0; + while(result.hasNext()) { + BindingSet bs = result.next(); + String id = bs.getBinding("id").getValue().stringValue(); + String date = bs.getBinding("date").getValue().stringValue(); + String title = bs.getBinding("title").getValue().stringValue(); + String state = bs.getBinding("state").getValue().stringValue(); + String contributors = bs.getBinding("date").getValue().stringValue(); + ModelMeta mm = new ModelMeta(id, date, title, state, contributors); + models.add(mm); + n_models++; + } + r.n = n_models; + r.models = models; + result.close(); //test //http://127.0.0.1:6800/modelsearch/?query=bla - Result r = new Result(); - r.id = 9; r.name = "fred"; return r; } diff --git a/minerva-server/src/main/resources/GetAllModels.rq b/minerva-server/src/main/resources/GetAllModels.rq new file mode 100644 index 00000000..a60be6ea --- /dev/null +++ b/minerva-server/src/main/resources/GetAllModels.rq @@ -0,0 +1,21 @@ +PREFIX owl: +PREFIX rdf: +PREFIX metago: +PREFIX lego: +PREFIX dc: +PREFIX rdfs: +SELECT ?id ?date ?title ?state (GROUP_CONCAT(?contributor;separator=";") AS ?contributors) +WHERE { + GRAPH ?cam { + ?cam dc:title ?title ; + dc:date ?date ; + lego:modelstate ?state ; + dc:contributor ?contributor . + optional { ?cam ?id } + #lpalbou: Baby Proofing the query since oboInOwl#id is not always there + BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . + } + } + GROUP BY ?id ?date ?title ?cam ?state + ORDER BY DESC(?date) + LIMIT 100 \ No newline at end of file From 2a822076adb5bb73916ca47c94d7aec64893e7b3 Mon Sep 17 00:00:00 2001 From: goodb Date: Thu, 27 Jun 2019 10:59:31 -0700 Subject: [PATCH 03/20] parameterized multi-gene and search working though note it currently give multiple responses per model if a single gene class is used on more than one instance within that model. --- minerva-cli/.DS_Store | Bin 6148 -> 6148 bytes .../server/handler/ModelSearchHandler.java | 85 ++++++++++++++++-- .../src/main/resources/GetAllModels.rq | 52 +++++++---- .../src/main/resources/QueryByGeneUriAND.rq | 34 +++++++ .../src/main/resources/QueryByGeneUriOR.rq | 32 +++++++ 5 files changed, 181 insertions(+), 22 deletions(-) create mode 100644 minerva-server/src/main/resources/QueryByGeneUriAND.rq create mode 100644 minerva-server/src/main/resources/QueryByGeneUriOR.rq diff --git a/minerva-cli/.DS_Store b/minerva-cli/.DS_Store index b448ec01691ac613cc20409857c0da09227209ed..2b42bcaeae096ea3b22c740423b28f10df4b2130 100644 GIT binary patch delta 26 icmZoMXffEJ%FM_xS&jMN=8w!`EE5~JHnVg5 contributors; + private HashMap query_match; - public ModelMeta(String id, String date, String title, String state, String contributors) { + public ModelMeta(String id, String date, String title, String state, Set contributors) { this.id = id; this.date = date; this.title = title; this.state = state; this.contributors = contributors; + query_match = new HashMap(); } } @GET @Produces(MediaType.APPLICATION_JSON) - public ModelSearchResult searchGet(@QueryParam("query") String queryText) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + public ModelSearchResult searchGet(@QueryParam("gene_product_class_uri") Set gene_product_class_uris) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + if(gene_product_class_uris!=null) { + return searchByGenes(gene_product_class_uris); + }else { + return getAll(); + } + } + + //examples ?gene_product_class_uri=http://identifiers.org/mgi/MGI:1328355&gene_product_class_uri=http://identifiers.org/mgi/MGI:87986 + public ModelSearchResult searchByGenes(Set gene_product_class_uris) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { ModelSearchResult r = new ModelSearchResult(); Set models = new HashSet(); - String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/GetAllModels.rq"), StandardCharsets.UTF_8); - //?id ?date ?title ?state (GROUP_CONCAT(?contributor;separator=";") AS ?contributors + String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/QueryByGeneUriAND.rq"), StandardCharsets.UTF_8); + Map gp_return = new HashMap(); + String gp_return_list = ""; // + String gp_and_constraints = ""; // + int gp_n = 0; + for(String gp_uri : gene_product_class_uris) { + gp_n++; + gp_return.put("?gp"+gp_n, gp_uri); + gp_return_list = gp_return_list+" ?gp"+gp_n; + gp_and_constraints = gp_and_constraints+"?gp"+gp_n+" rdf:type <"+gp_uri+"> . \n"; + } + sparql = sparql.replaceAll("", gp_return_list); + sparql = sparql.replaceAll("", gp_and_constraints); TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 10); int n_models = 0; while(result.hasNext()) { BindingSet bs = result.next(); + //model meta String id = bs.getBinding("id").getValue().stringValue(); String date = bs.getBinding("date").getValue().stringValue(); String title = bs.getBinding("title").getValue().stringValue(); String state = bs.getBinding("state").getValue().stringValue(); - String contributors = bs.getBinding("date").getValue().stringValue(); + String contribs = bs.getBinding("contributors").getValue().stringValue(); + Set contributors = new HashSet(); + if(contributors!=null) { + for(String c : contribs.split(";")) { + contributors.add(c); + } + } ModelMeta mm = new ModelMeta(id, date, title, state, contributors); + //matching + for(String gp : gp_return.keySet()) { + String gp_ind = bs.getBinding(gp.replace("?", "")).getValue().stringValue(); + mm.query_match.put(gp_return.get(gp), gp_ind); + } models.add(mm); n_models++; } @@ -93,6 +129,41 @@ public ModelSearchResult searchGet(@QueryParam("query") String queryText) throws return r; } + public ModelSearchResult getAll() throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + ModelSearchResult r = new ModelSearchResult(); + Set models = new HashSet(); + String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/GetAllModels.rq"), StandardCharsets.UTF_8); + TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 100); + int n_models = 0; + while(result.hasNext()) { + BindingSet bs = result.next(); + //model meta + String id = bs.getBinding("id").getValue().stringValue(); + String date = bs.getBinding("date").getValue().stringValue(); + String title = bs.getBinding("title").getValue().stringValue(); + String state = bs.getBinding("state").getValue().stringValue(); + String contribs = bs.getBinding("contributors").getValue().stringValue(); + Set contributors = new HashSet(); + if(contributors!=null) { + for(String c : contribs.split(";")) { + contributors.add(c); + } + } + ModelMeta mm = new ModelMeta(id, date, title, state, contributors); + models.add(mm); + n_models++; + } + System.out.println("n models "+n_models); + r.n = n_models; + r.models = models; + result.close(); + //test + //http://127.0.0.1:6800/modelsearch/?query=bla + return r; + } + + + @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) diff --git a/minerva-server/src/main/resources/GetAllModels.rq b/minerva-server/src/main/resources/GetAllModels.rq index a60be6ea..2e6de1ac 100644 --- a/minerva-server/src/main/resources/GetAllModels.rq +++ b/minerva-server/src/main/resources/GetAllModels.rq @@ -1,21 +1,43 @@ PREFIX owl: PREFIX rdf: +#model metadata PREFIX metago: PREFIX lego: -PREFIX dc: -PREFIX rdfs: -SELECT ?id ?date ?title ?state (GROUP_CONCAT(?contributor;separator=";") AS ?contributors) +#PREFIX dc: +#PREFIX rdfs: +#model data +PREFIX part_of: +PREFIX occurs_in: +PREFIX enabled_by: +PREFIX has_input: +PREFIX has_output: +PREFIX causally_upstream_of: +PREFIX provides_direct_input_for: +PREFIX directly_positively_regulates: + +SELECT ?cam ?id ?date ?title ?state ?gp_class (GROUP_CONCAT(?contributor;separator=";") AS ?contributors) WHERE { + GRAPH ?cam { - ?cam dc:title ?title ; - dc:date ?date ; - lego:modelstate ?state ; - dc:contributor ?contributor . - optional { ?cam ?id } - #lpalbou: Baby Proofing the query since oboInOwl#id is not always there - BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . - } - } - GROUP BY ?id ?date ?title ?cam ?state - ORDER BY DESC(?date) - LIMIT 100 \ No newline at end of file + ?cam ?title ; + ?date ; + ?contributor ; + lego:modelstate ?state . + optional { + ?cam ?id + } + #lpalbou: Baby Proofing the query since oboInOwl#id is not always there + BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . + + optional{ + ?mf_ind enabled_by: ?gp_ind . + ?gp_ind rdf:type ?gp_class . + FILTER(?gp_class != owl:NamedIndividual) . + } + } + } + GROUP BY ?id ?date ?title ?cam ?state ?gp_class + ORDER BY desc(?gp_class) ?date + + LIMIT 10 + \ No newline at end of file diff --git a/minerva-server/src/main/resources/QueryByGeneUriAND.rq b/minerva-server/src/main/resources/QueryByGeneUriAND.rq new file mode 100644 index 00000000..9f5e6ca1 --- /dev/null +++ b/minerva-server/src/main/resources/QueryByGeneUriAND.rq @@ -0,0 +1,34 @@ +PREFIX owl: +PREFIX rdf: +#model metadata +PREFIX metago: +PREFIX lego: +#model data +PREFIX part_of: +PREFIX occurs_in: +PREFIX enabled_by: +PREFIX has_input: +PREFIX has_output: +PREFIX causally_upstream_of: +PREFIX provides_direct_input_for: +PREFIX directly_positively_regulates: + +SELECT ?cam ?id ?date ?title ?state (GROUP_CONCAT(?contributor;separator=";") AS ?contributors) +WHERE { + GRAPH ?cam { + ?cam ?title ; + ?date ; + ?contributor ; + lego:modelstate ?state . + BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . + #AND + + #?gp_ind1 rdf:type . + #?gp_ind2 rdf:type . + #?gp_ind3 rdf:type + } + } + GROUP BY ?id ?date ?title ?cam ?state + ORDER BY desc(?date) +limit 10 + \ No newline at end of file diff --git a/minerva-server/src/main/resources/QueryByGeneUriOR.rq b/minerva-server/src/main/resources/QueryByGeneUriOR.rq new file mode 100644 index 00000000..dde86a07 --- /dev/null +++ b/minerva-server/src/main/resources/QueryByGeneUriOR.rq @@ -0,0 +1,32 @@ +PREFIX owl: +PREFIX rdf: +#model metadata +PREFIX metago: +PREFIX lego: +#model data +PREFIX part_of: +PREFIX occurs_in: +PREFIX enabled_by: +PREFIX has_input: +PREFIX has_output: +PREFIX causally_upstream_of: +PREFIX provides_direct_input_for: +PREFIX directly_positively_regulates: + +SELECT ?cam ?id ?date ?title ?state ?gp_ind (GROUP_CONCAT(?contributor;separator=";") AS ?contributors) +WHERE { + GRAPH ?cam { + ?cam ?title ; + ?date ; + ?contributor ; + lego:modelstate ?state . + BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . + ?gp_ind rdf:type ?gp_class . + VALUES(?gp_class ) + #e.g. VALUES ?gp_class { } + } + } + GROUP BY ?id ?date ?title ?cam ?state ?gp_ind + ORDER BY desc(?date) desc(?gp_class) + + \ No newline at end of file From ade67ba7e697e4c2782802f34fa732a297d8e19c Mon Sep 17 00:00:00 2001 From: goodb Date: Thu, 27 Jun 2019 11:15:53 -0700 Subject: [PATCH 04/20] fixed so only one model will be returned on multiple hits e.g. query: http://127.0.0.1:6800/search/?gene_product_class_uri=http://identifiers.org/mgi/MGI:1328355&gene_product_class_uri=http://identifiers.org/mgi/MGI:87986 response: { "n": 1, "models": [ { "id": "gomodel:5ce58dde00001215", "date": "2019-06-26", "title": "Mouse-Aatf-antiapoptosis", "state": "production", "contributors": [ "http://orcid.org/0000-0001-7476-6306" ], "query_match": { "http://identifiers.org/mgi/MGI:1328355": [ "http://model.geneontology.org/5ce58dde00001215/5ce58dde00001312", "http://model.geneontology.org/5ce58dde00001215/5ce58dde00001229" ], "http://identifiers.org/mgi/MGI:87986": [ "http://model.geneontology.org/5ce58dde00001215/5ce58dde00001217" ] } } ] } --- .../server/handler/ModelSearchHandler.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index 89d05d73..df8cf527 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -48,6 +48,9 @@ public ModelSearchHandler(BlazegraphMolecularModelManager m3, int timeout) { public class ModelSearchResult { private Integer n; private Set models; + private void makeModelsDistinct() { + + } } public class ModelMeta{ @@ -56,7 +59,7 @@ public class ModelMeta{ private String title; private String state; private Set contributors; - private HashMap query_match; + private HashMap> query_match; public ModelMeta(String id, String date, String title, String state, Set contributors) { this.id = id; @@ -64,7 +67,7 @@ public ModelMeta(String id, String date, String title, String state, Set this.title = title; this.state = state; this.contributors = contributors; - query_match = new HashMap(); + query_match = new HashMap>(); } } @@ -82,7 +85,7 @@ public ModelSearchResult searchGet(@QueryParam("gene_product_class_uri") Set gene_product_class_uris) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { ModelSearchResult r = new ModelSearchResult(); - Set models = new HashSet(); + Map id_model = new HashMap(); String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/QueryByGeneUriAND.rq"), StandardCharsets.UTF_8); Map gp_return = new HashMap(); String gp_return_list = ""; // @@ -112,17 +115,26 @@ public ModelSearchResult searchByGenes(Set gene_product_class_uris) thro contributors.add(c); } } - ModelMeta mm = new ModelMeta(id, date, title, state, contributors); + ModelMeta mm = id_model.get(id); + if(mm==null) { + mm = new ModelMeta(id, date, title, state, contributors); + } //matching + for(String gp : gp_return.keySet()) { String gp_ind = bs.getBinding(gp.replace("?", "")).getValue().stringValue(); - mm.query_match.put(gp_return.get(gp), gp_ind); + Set matching_inds = mm.query_match.get(gp_return.get(gp)); + if(matching_inds==null) { + matching_inds = new HashSet(); + } + matching_inds.add(gp_ind); + mm.query_match.put(gp_return.get(gp), matching_inds); } - models.add(mm); + id_model.put(id, mm); n_models++; } - r.n = n_models; - r.models = models; + r.n = id_model.size(); + r.models = new HashSet(id_model.values()); result.close(); //test //http://127.0.0.1:6800/modelsearch/?query=bla From 2d602f13d5a69e1fdc76d48b87c0b1d1b628ae0b Mon Sep 17 00:00:00 2001 From: goodb Date: Fri, 28 Jun 2019 10:16:38 -0700 Subject: [PATCH 05/20] generalized query by entity type sparql template works for requests for genes, goterms. Could be generalized further in terms of input parameters - e.g. a generic 'type=.." instead of goterm, gene_product etc. --- .../server/handler/ModelSearchHandler.java | 56 +++++++++++-------- ...QueryByGeneUriAND.rq => QueryByTypeAND.rq} | 12 ++-- 2 files changed, 39 insertions(+), 29 deletions(-) rename minerva-server/src/main/resources/{QueryByGeneUriAND.rq => QueryByTypeAND.rq} (73%) diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index df8cf527..2a9e6e92 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -30,6 +30,7 @@ /** * Respond to queries for models in the running blazegraph instance backing minerva + * Uses Jersey + JSONP * */ @Path("/search") @@ -74,31 +75,41 @@ public ModelMeta(String id, String date, String title, String state, Set @GET @Produces(MediaType.APPLICATION_JSON) - public ModelSearchResult searchGet(@QueryParam("gene_product_class_uri") Set gene_product_class_uris) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { - if(gene_product_class_uris!=null) { - return searchByGenes(gene_product_class_uris); + public ModelSearchResult searchGet( + @QueryParam("gene_product_class_uri") Set gene_product_class_uris, + @QueryParam("goterm") Set goterms + ) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + if(gene_product_class_uris!=null||goterms!=null) { + return search(gene_product_class_uris, goterms); }else { return getAll(); } } //examples ?gene_product_class_uri=http://identifiers.org/mgi/MGI:1328355&gene_product_class_uri=http://identifiers.org/mgi/MGI:87986 - public ModelSearchResult searchByGenes(Set gene_product_class_uris) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + public ModelSearchResult search(Set gene_product_class_uris, Set goterms) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + Set type_uris = new HashSet(); + if(gene_product_class_uris!=null) { + type_uris.addAll(gene_product_class_uris); + } + if(goterms!=null) { + type_uris.addAll(goterms); + } ModelSearchResult r = new ModelSearchResult(); Map id_model = new HashMap(); - String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/QueryByGeneUriAND.rq"), StandardCharsets.UTF_8); - Map gp_return = new HashMap(); - String gp_return_list = ""; // - String gp_and_constraints = ""; // - int gp_n = 0; - for(String gp_uri : gene_product_class_uris) { - gp_n++; - gp_return.put("?gp"+gp_n, gp_uri); - gp_return_list = gp_return_list+" ?gp"+gp_n; - gp_and_constraints = gp_and_constraints+"?gp"+gp_n+" rdf:type <"+gp_uri+"> . \n"; + String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/QueryByTypeAND.rq"), StandardCharsets.UTF_8); + Map ind_return = new HashMap(); + String ind_return_list = ""; // + String types = ""; // + int n = 0; + for(String type_uri : type_uris) { + n++; + ind_return.put("?ind"+n, type_uri); + ind_return_list = ind_return_list+" ?ind"+n; + types = types+"?ind"+n+" rdf:type <"+type_uri+"> . \n"; } - sparql = sparql.replaceAll("", gp_return_list); - sparql = sparql.replaceAll("", gp_and_constraints); + sparql = sparql.replaceAll("", ind_return_list); + sparql = sparql.replaceAll("", types); TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 10); int n_models = 0; while(result.hasNext()) { @@ -119,16 +130,15 @@ public ModelSearchResult searchByGenes(Set gene_product_class_uris) thro if(mm==null) { mm = new ModelMeta(id, date, title, state, contributors); } - //matching - - for(String gp : gp_return.keySet()) { - String gp_ind = bs.getBinding(gp.replace("?", "")).getValue().stringValue(); - Set matching_inds = mm.query_match.get(gp_return.get(gp)); + //matching + for(String ind : ind_return.keySet()) { + String ind_class_match = bs.getBinding(ind.replace("?", "")).getValue().stringValue(); + Set matching_inds = mm.query_match.get(ind_return.get(ind)); if(matching_inds==null) { matching_inds = new HashSet(); } - matching_inds.add(gp_ind); - mm.query_match.put(gp_return.get(gp), matching_inds); + matching_inds.add(ind_class_match); + mm.query_match.put(ind_return.get(ind), matching_inds); } id_model.put(id, mm); n_models++; diff --git a/minerva-server/src/main/resources/QueryByGeneUriAND.rq b/minerva-server/src/main/resources/QueryByTypeAND.rq similarity index 73% rename from minerva-server/src/main/resources/QueryByGeneUriAND.rq rename to minerva-server/src/main/resources/QueryByTypeAND.rq index 9f5e6ca1..8f4da6ca 100644 --- a/minerva-server/src/main/resources/QueryByGeneUriAND.rq +++ b/minerva-server/src/main/resources/QueryByTypeAND.rq @@ -13,7 +13,7 @@ PREFIX causally_upstream_of: PREFIX provides_direct_input_for: PREFIX directly_positively_regulates: -SELECT ?cam ?id ?date ?title ?state (GROUP_CONCAT(?contributor;separator=";") AS ?contributors) +SELECT ?cam ?id ?date ?title ?state (GROUP_CONCAT(?contributor;separator=";") AS ?contributors) WHERE { GRAPH ?cam { ?cam ?title ; @@ -22,13 +22,13 @@ WHERE { lego:modelstate ?state . BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . #AND - - #?gp_ind1 rdf:type . - #?gp_ind2 rdf:type . - #?gp_ind3 rdf:type + + #e.g. + #?ind1 rdf:type . + #?ind2 rdf:type } } - GROUP BY ?id ?date ?title ?cam ?state + GROUP BY ?id ?date ?title ?cam ?state ORDER BY desc(?date) limit 10 \ No newline at end of file From 6839f784c9282e018320a187d3e4d6db230f3c01 Mon Sep 17 00:00:00 2001 From: goodb Date: Fri, 28 Jun 2019 11:33:31 -0700 Subject: [PATCH 06/20] Added search by pmid, further generalized template --- .../server/handler/ModelSearchHandler.java | 280 +++++++++--------- .../src/main/resources/QueryTemplateAND.rq | 35 +++ 2 files changed, 181 insertions(+), 134 deletions(-) create mode 100644 minerva-server/src/main/resources/QueryTemplateAND.rq diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index 2a9e6e92..fa823fe4 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -36,24 +36,24 @@ @Path("/search") public class ModelSearchHandler { - private final BlazegraphMolecularModelManager m3; - private final int timeout; + private final BlazegraphMolecularModelManager m3; + private final int timeout; /** * */ public ModelSearchHandler(BlazegraphMolecularModelManager m3, int timeout) { - this.m3 = m3; - this.timeout = timeout; + this.m3 = m3; + this.timeout = timeout; } - + public class ModelSearchResult { - private Integer n; - private Set models; - private void makeModelsDistinct() { - - } + private Integer n; + private Set models; + private void makeModelsDistinct() { + + } } - + public class ModelMeta{ private String id; private String date; @@ -61,7 +61,7 @@ public class ModelMeta{ private String state; private Set contributors; private HashMap> query_match; - + public ModelMeta(String id, String date, String title, String state, Set contributors) { this.id = id; this.date = date; @@ -71,127 +71,139 @@ public ModelMeta(String id, String date, String title, String state, Set query_match = new HashMap>(); } } - - - @GET - @Produces(MediaType.APPLICATION_JSON) - public ModelSearchResult searchGet( - @QueryParam("gene_product_class_uri") Set gene_product_class_uris, - @QueryParam("goterm") Set goterms - ) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { - if(gene_product_class_uris!=null||goterms!=null) { - return search(gene_product_class_uris, goterms); - }else { - return getAll(); - } - } - - //examples ?gene_product_class_uri=http://identifiers.org/mgi/MGI:1328355&gene_product_class_uri=http://identifiers.org/mgi/MGI:87986 - public ModelSearchResult search(Set gene_product_class_uris, Set goterms) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { - Set type_uris = new HashSet(); - if(gene_product_class_uris!=null) { - type_uris.addAll(gene_product_class_uris); - } - if(goterms!=null) { - type_uris.addAll(goterms); - } - ModelSearchResult r = new ModelSearchResult(); - Map id_model = new HashMap(); - String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/QueryByTypeAND.rq"), StandardCharsets.UTF_8); - Map ind_return = new HashMap(); - String ind_return_list = ""; // - String types = ""; // - int n = 0; - for(String type_uri : type_uris) { - n++; - ind_return.put("?ind"+n, type_uri); - ind_return_list = ind_return_list+" ?ind"+n; - types = types+"?ind"+n+" rdf:type <"+type_uri+"> . \n"; - } - sparql = sparql.replaceAll("", ind_return_list); - sparql = sparql.replaceAll("", types); - TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 10); - int n_models = 0; - while(result.hasNext()) { - BindingSet bs = result.next(); - //model meta - String id = bs.getBinding("id").getValue().stringValue(); - String date = bs.getBinding("date").getValue().stringValue(); - String title = bs.getBinding("title").getValue().stringValue(); - String state = bs.getBinding("state").getValue().stringValue(); - String contribs = bs.getBinding("contributors").getValue().stringValue(); - Set contributors = new HashSet(); - if(contributors!=null) { - for(String c : contribs.split(";")) { - contributors.add(c); - } - } - ModelMeta mm = id_model.get(id); - if(mm==null) { - mm = new ModelMeta(id, date, title, state, contributors); - } - //matching - for(String ind : ind_return.keySet()) { - String ind_class_match = bs.getBinding(ind.replace("?", "")).getValue().stringValue(); - Set matching_inds = mm.query_match.get(ind_return.get(ind)); - if(matching_inds==null) { - matching_inds = new HashSet(); - } - matching_inds.add(ind_class_match); - mm.query_match.put(ind_return.get(ind), matching_inds); - } - id_model.put(id, mm); - n_models++; - } - r.n = id_model.size(); - r.models = new HashSet(id_model.values()); - result.close(); - //test - //http://127.0.0.1:6800/modelsearch/?query=bla - return r; - } - - public ModelSearchResult getAll() throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { - ModelSearchResult r = new ModelSearchResult(); - Set models = new HashSet(); - String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/GetAllModels.rq"), StandardCharsets.UTF_8); - TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 100); - int n_models = 0; - while(result.hasNext()) { - BindingSet bs = result.next(); - //model meta - String id = bs.getBinding("id").getValue().stringValue(); - String date = bs.getBinding("date").getValue().stringValue(); - String title = bs.getBinding("title").getValue().stringValue(); - String state = bs.getBinding("state").getValue().stringValue(); - String contribs = bs.getBinding("contributors").getValue().stringValue(); - Set contributors = new HashSet(); - if(contributors!=null) { - for(String c : contribs.split(";")) { - contributors.add(c); - } - } - ModelMeta mm = new ModelMeta(id, date, title, state, contributors); - models.add(mm); - n_models++; - } - System.out.println("n models "+n_models); - r.n = n_models; - r.models = models; - result.close(); - //test - //http://127.0.0.1:6800/modelsearch/?query=bla - return r; - } - - - - @POST - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public String searchPostForm(@FormParam("query") String queryText) { - // return m3.executeSPARQLQuery(queryText, timeout); - return "post pong"; - } + + + @GET + @Produces(MediaType.APPLICATION_JSON) + public ModelSearchResult searchGet( + @QueryParam("gene_product_class_uri") Set gene_product_class_uris, + @QueryParam("goterm") Set goterms, + @QueryParam("pmid") Set pmids + ) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + if(gene_product_class_uris!=null + ||goterms!=null + ||pmids!=null) { + return search(gene_product_class_uris, goterms, pmids); + }else { + return getAll(); + } + } + + //examples ?gene_product_class_uri=http://identifiers.org/mgi/MGI:1328355&gene_product_class_uri=http://identifiers.org/mgi/MGI:87986 + public ModelSearchResult search(Set gene_product_class_uris, Set goterms, Setpmids) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + Set type_uris = new HashSet(); + if(gene_product_class_uris!=null) { + type_uris.addAll(gene_product_class_uris); + } + if(goterms!=null) { + type_uris.addAll(goterms); + } + ModelSearchResult r = new ModelSearchResult(); + Map id_model = new HashMap(); + String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/QueryTemplateAND.rq"), StandardCharsets.UTF_8); + Map ind_return = new HashMap(); + String ind_return_list = ""; // + String types = ""; // + int n = 0; + for(String type_uri : type_uris) { + n++; + ind_return.put("?ind"+n, type_uri); + ind_return_list = ind_return_list+" ?ind"+n; + types = types+"?ind"+n+" rdf:type <"+type_uri+"> . \n"; + } + String pmid_constraints = ""; // + if(pmids!=null) { + for(String pmid : pmids) { + n++; + ind_return.put("?ind"+n, pmid); + ind_return_list = ind_return_list+" ?ind"+n; + pmid_constraints = pmid_constraints+"?ind"+n+" ?pmid FILTER (?pmid=\""+pmid+"\"^^xsd:string) .\n"; + } + } + sparql = sparql.replaceAll("", ind_return_list); + sparql = sparql.replaceAll("", types); + sparql = sparql.replaceAll("", pmid_constraints); + + TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 10); + while(result.hasNext()) { + BindingSet bs = result.next(); + //model meta + String id = bs.getBinding("id").getValue().stringValue(); + String date = bs.getBinding("date").getValue().stringValue(); + String title = bs.getBinding("title").getValue().stringValue(); + String state = bs.getBinding("state").getValue().stringValue(); + String contribs = bs.getBinding("contributors").getValue().stringValue(); + Set contributors = new HashSet(); + if(contributors!=null) { + for(String c : contribs.split(";")) { + contributors.add(c); + } + } + ModelMeta mm = id_model.get(id); + if(mm==null) { + mm = new ModelMeta(id, date, title, state, contributors); + } + //matching + for(String ind : ind_return.keySet()) { + String ind_class_match = bs.getBinding(ind.replace("?", "")).getValue().stringValue(); + Set matching_inds = mm.query_match.get(ind_return.get(ind)); + if(matching_inds==null) { + matching_inds = new HashSet(); + } + matching_inds.add(ind_class_match); + mm.query_match.put(ind_return.get(ind), matching_inds); + } + id_model.put(id, mm); + } + r.n = id_model.size(); + r.models = new HashSet(id_model.values()); + result.close(); + //test + //http://127.0.0.1:6800/modelsearch/?query=bla + return r; + } + + public ModelSearchResult getAll() throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + ModelSearchResult r = new ModelSearchResult(); + Set models = new HashSet(); + String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/GetAllModels.rq"), StandardCharsets.UTF_8); + TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 100); + int n_models = 0; + while(result.hasNext()) { + BindingSet bs = result.next(); + //model meta + String id = bs.getBinding("id").getValue().stringValue(); + String date = bs.getBinding("date").getValue().stringValue(); + String title = bs.getBinding("title").getValue().stringValue(); + String state = bs.getBinding("state").getValue().stringValue(); + String contribs = bs.getBinding("contributors").getValue().stringValue(); + Set contributors = new HashSet(); + if(contributors!=null) { + for(String c : contribs.split(";")) { + contributors.add(c); + } + } + ModelMeta mm = new ModelMeta(id, date, title, state, contributors); + models.add(mm); + n_models++; + } + System.out.println("n models "+n_models); + r.n = n_models; + r.models = models; + result.close(); + //test + //http://127.0.0.1:6800/modelsearch/?query=bla + return r; + } + + + + @POST + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public String searchPostForm(@FormParam("query") String queryText) { + // return m3.executeSPARQLQuery(queryText, timeout); + return "post pong"; + } } diff --git a/minerva-server/src/main/resources/QueryTemplateAND.rq b/minerva-server/src/main/resources/QueryTemplateAND.rq new file mode 100644 index 00000000..1ca1579e --- /dev/null +++ b/minerva-server/src/main/resources/QueryTemplateAND.rq @@ -0,0 +1,35 @@ +PREFIX owl: +PREFIX rdf: +#model metadata +PREFIX metago: +PREFIX lego: +#model data +PREFIX part_of: +PREFIX occurs_in: +PREFIX enabled_by: +PREFIX has_input: +PREFIX has_output: +PREFIX causally_upstream_of: +PREFIX provides_direct_input_for: +PREFIX directly_positively_regulates: + +SELECT ?cam ?id ?date ?title ?state (GROUP_CONCAT(?contributor;separator=";") AS ?contributors) +WHERE { + GRAPH ?cam { + ?cam ?title ; + ?date ; + ?contributor ; + lego:modelstate ?state . + BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . + #AND + + + #e.g. + #?ind1 rdf:type . + #?ind2 rdf:type + } + } + GROUP BY ?id ?date ?title ?cam ?state + ORDER BY desc(?date) +limit 10 + \ No newline at end of file From dfad545046f337def1948ab68d45e12ed3de51ac Mon Sep 17 00:00:00 2001 From: goodb Date: Fri, 28 Jun 2019 14:21:26 -0700 Subject: [PATCH 07/20] added text search over titles - starting Jetty refactor --- minerva-server/pom.xml | 9 +++++++++ .../minerva/server/StartUpTool.java | 7 +++++-- .../server/handler/ModelSearchHandler.java | 17 ++++++++++++----- .../src/main/resources/QueryTemplateAND.rq | 2 ++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/minerva-server/pom.xml b/minerva-server/pom.xml index 20e19501..406d1931 100644 --- a/minerva-server/pom.xml +++ b/minerva-server/pom.xml @@ -81,38 +81,47 @@ org.eclipse.jetty jetty-server + 9.4.19.v20190610 org.eclipse.jetty jetty-servlet + 9.4.19.v20190610 org.eclipse.jetty jetty-util + 9.4.19.v20190610 org.eclipse.jetty jetty-io + 9.4.19.v20190610 org.eclipse.jetty jetty-jmx + 9.4.19.v20190610 org.eclipse.jetty jetty-jndi + 9.4.19.v20190610 org.eclipse.jetty jetty-rewrite + 9.4.19.v20190610 org.eclipse.jetty jetty-webapp + 9.4.19.v20190610 org.eclipse.jetty jetty-xml + 9.4.19.v20190610 org.glassfish.jersey.containers diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java b/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java index f9193a43..451e5faf 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java @@ -2,7 +2,8 @@ import org.apache.log4j.Logger; import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.nio.SelectChannelConnector; +import org.eclipse.jetty.server.ServerConnector; +//old jetty import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.geneontology.minerva.ModelReaderHelper; @@ -385,7 +386,9 @@ public static Server startUp(UndoAwareMolecularModelManager models, MinervaStart // setup jetty server port, buffers and context path Server server = new Server(); // create connector with port and custom buffer sizes - SelectChannelConnector connector = new SelectChannelConnector(); + //old jetty + //SelectChannelConnector connector = new SelectChannelConnector(); + ServerConnector connector = new ServerConnector(); connector.setPort(conf.port); connector.setRequestHeaderSize(conf.requestHeaderSize); connector.setRequestBufferSize(conf.requestBufferSize); diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index fa823fe4..04df5632 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -78,19 +78,21 @@ public ModelMeta(String id, String date, String title, String state, Set public ModelSearchResult searchGet( @QueryParam("gene_product_class_uri") Set gene_product_class_uris, @QueryParam("goterm") Set goterms, - @QueryParam("pmid") Set pmids + @QueryParam("pmid") Set pmids, + @QueryParam("title") String title ) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { if(gene_product_class_uris!=null ||goterms!=null - ||pmids!=null) { - return search(gene_product_class_uris, goterms, pmids); + ||pmids!=null + ||title!=null) { + return search(gene_product_class_uris, goterms, pmids, title); }else { return getAll(); } } //examples ?gene_product_class_uri=http://identifiers.org/mgi/MGI:1328355&gene_product_class_uri=http://identifiers.org/mgi/MGI:87986 - public ModelSearchResult search(Set gene_product_class_uris, Set goterms, Setpmids) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + public ModelSearchResult search(Set gene_product_class_uris, Set goterms, Setpmids, String title_search) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { Set type_uris = new HashSet(); if(gene_product_class_uris!=null) { type_uris.addAll(gene_product_class_uris); @@ -120,10 +122,15 @@ public ModelSearchResult search(Set gene_product_class_uris, Set pmid_constraints = pmid_constraints+"?ind"+n+" ?pmid FILTER (?pmid=\""+pmid+"\"^^xsd:string) .\n"; } } + String title_search_constraint = ""; + if(title_search!=null) { + title_search_constraint = "?title \""+title_search+"\" .\n"; + } sparql = sparql.replaceAll("", ind_return_list); sparql = sparql.replaceAll("", types); sparql = sparql.replaceAll("", pmid_constraints); - + sparql = sparql.replaceAll("", title_search_constraint); + TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 10); while(result.hasNext()) { BindingSet bs = result.next(); diff --git a/minerva-server/src/main/resources/QueryTemplateAND.rq b/minerva-server/src/main/resources/QueryTemplateAND.rq index 1ca1579e..296899d4 100644 --- a/minerva-server/src/main/resources/QueryTemplateAND.rq +++ b/minerva-server/src/main/resources/QueryTemplateAND.rq @@ -22,11 +22,13 @@ WHERE { lego:modelstate ?state . BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . #AND + #e.g. #?ind1 rdf:type . #?ind2 rdf:type + #?title "mouse" . } } GROUP BY ?id ?date ?title ?cam ?state From 64ac72744dc5ea7b089b330e105c6cfce92aee4b Mon Sep 17 00:00:00 2001 From: goodb Date: Mon, 1 Jul 2019 11:19:27 -0700 Subject: [PATCH 08/20] upgrade to jetty 9.4 Not much difference really. All tests in minerva server pass. Local testing with Noctua stack is working without error. Note that there is no longer a way to set conf.requestBufferSize . See here for info. on the upgrade. --- minerva-server/pom.xml | 9 --------- .../minerva/server/StartUpTool.java | 20 +++++++++++++++---- pom.xml | 19 +++++++++--------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/minerva-server/pom.xml b/minerva-server/pom.xml index 406d1931..20e19501 100644 --- a/minerva-server/pom.xml +++ b/minerva-server/pom.xml @@ -81,47 +81,38 @@ org.eclipse.jetty jetty-server - 9.4.19.v20190610 org.eclipse.jetty jetty-servlet - 9.4.19.v20190610 org.eclipse.jetty jetty-util - 9.4.19.v20190610 org.eclipse.jetty jetty-io - 9.4.19.v20190610 org.eclipse.jetty jetty-jmx - 9.4.19.v20190610 org.eclipse.jetty jetty-jndi - 9.4.19.v20190610 org.eclipse.jetty jetty-rewrite - 9.4.19.v20190610 org.eclipse.jetty jetty-webapp - 9.4.19.v20190610 org.eclipse.jetty jetty-xml - 9.4.19.v20190610 org.glassfish.jersey.containers diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java b/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java index 451e5faf..897cc707 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java @@ -1,9 +1,11 @@ package org.geneontology.minerva.server; import org.apache.log4j.Logger; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; -//old jetty import org.eclipse.jetty.server.nio.SelectChannelConnector; +//import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.geneontology.minerva.ModelReaderHelper; @@ -388,10 +390,20 @@ public static Server startUp(UndoAwareMolecularModelManager models, MinervaStart // create connector with port and custom buffer sizes //old jetty //SelectChannelConnector connector = new SelectChannelConnector(); - ServerConnector connector = new ServerConnector(); + //new jetty + + + //old jetty - they must be configured somewhere else in new jetty + //connector.setRequestHeaderSize(conf.requestHeaderSize); + //connector.setRequestBufferSize(conf.requestBufferSize); + //new jetty - does not have setRequestBufferSize at all + //seems to push defaults harder here. + //to change request header size need to create a new connector and manipulate httpconfiguration + HttpConfiguration http_config = new HttpConfiguration(); + http_config.setRequestHeaderSize(conf.requestHeaderSize); + ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(http_config)); connector.setPort(conf.port); - connector.setRequestHeaderSize(conf.requestHeaderSize); - connector.setRequestBufferSize(conf.requestBufferSize); + server.addConnector(connector); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); diff --git a/pom.xml b/pom.xml index 90e41bf3..cc1a2084 100644 --- a/pom.xml +++ b/pom.xml @@ -188,47 +188,48 @@ org.eclipse.jetty jetty-server - 7.5.4.v20111024 + + 9.4.19.v20190610 org.eclipse.jetty jetty-servlet - 7.5.4.v20111024 + 9.4.19.v20190610 org.eclipse.jetty jetty-util - 7.5.4.v20111024 + 9.4.19.v20190610 org.eclipse.jetty jetty-io - 7.5.4.v20111024 + 9.4.19.v20190610 org.eclipse.jetty jetty-jmx - 7.5.4.v20111024 + 9.4.19.v20190610 org.eclipse.jetty jetty-jndi - 7.5.4.v20111024 + 9.4.19.v20190610 org.eclipse.jetty jetty-rewrite - 7.5.4.v20111024 + 9.4.19.v20190610 org.eclipse.jetty jetty-webapp - 7.5.4.v20111024 + 9.4.19.v20190610 org.eclipse.jetty jetty-xml - 7.5.4.v20111024 + 9.4.19.v20190610 org.glassfish.jersey.containers From 0dd7203500b89d6dcd63f4f9921038549bf308d8 Mon Sep 17 00:00:00 2001 From: goodb Date: Tue, 2 Jul 2019 15:16:20 -0700 Subject: [PATCH 09/20] implemented text search over title field Added parameter to API and sparql template. Updgraded jetty dependency to 9.2.3.v20140905 . (from 7). Note that jetty 9.4 will break it. --- .../BlazegraphMolecularModelManager.java | 1 + .../minerva/server/StartUpTool.java | 5 +--- .../server/handler/ModelSearchHandler.java | 2 +- pom.xml | 26 ++++++++++--------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/minerva-core/src/main/java/org/geneontology/minerva/BlazegraphMolecularModelManager.java b/minerva-core/src/main/java/org/geneontology/minerva/BlazegraphMolecularModelManager.java index c86dcff4..2ce5ac13 100644 --- a/minerva-core/src/main/java/org/geneontology/minerva/BlazegraphMolecularModelManager.java +++ b/minerva-core/src/main/java/org/geneontology/minerva/BlazegraphMolecularModelManager.java @@ -135,6 +135,7 @@ private BigdataSailRepository initializeRepository(String pathToJournal) { properties.setProperty(Options.FILE, pathToJournal); BigdataSail sail = new BigdataSail(properties); BigdataSailRepository repository = new BigdataSailRepository(sail); + repository.initialize(); return repository; } catch (RepositoryException e) { diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java b/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java index 897cc707..0fde600c 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java @@ -389,10 +389,7 @@ public static Server startUp(UndoAwareMolecularModelManager models, MinervaStart Server server = new Server(); // create connector with port and custom buffer sizes //old jetty - //SelectChannelConnector connector = new SelectChannelConnector(); - //new jetty - - + //SelectChannelConnector connector = new SelectChannelConnector(); //old jetty - they must be configured somewhere else in new jetty //connector.setRequestHeaderSize(conf.requestHeaderSize); //connector.setRequestBufferSize(conf.requestBufferSize); diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index 04df5632..c079c260 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -91,7 +91,7 @@ public ModelSearchResult searchGet( } } - //examples ?gene_product_class_uri=http://identifiers.org/mgi/MGI:1328355&gene_product_class_uri=http://identifiers.org/mgi/MGI:87986 + //examples ?gene_product_class_uri=http://identifiers.org/mgi/MGI:1328355&gene_product_class_uri=http://identifiers.org/mgi/MGI:87986&title=mouse public ModelSearchResult search(Set gene_product_class_uris, Set goterms, Setpmids, String title_search) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { Set type_uris = new HashSet(); if(gene_product_class_uris!=null) { diff --git a/pom.xml b/pom.xml index cc1a2084..06655cf2 100644 --- a/pom.xml +++ b/pom.xml @@ -189,47 +189,48 @@ org.eclipse.jetty jetty-server - 9.4.19.v20190610 + + 9.2.3.v20140905 org.eclipse.jetty jetty-servlet - 9.4.19.v20190610 + 9.2.3.v20140905 org.eclipse.jetty jetty-util - 9.4.19.v20190610 + 9.2.3.v20140905 org.eclipse.jetty jetty-io - 9.4.19.v20190610 + 9.2.3.v20140905 org.eclipse.jetty jetty-jmx - 9.4.19.v20190610 + 9.2.3.v20140905 org.eclipse.jetty jetty-jndi - 9.4.19.v20190610 + 9.2.3.v20140905 org.eclipse.jetty jetty-rewrite - 9.4.19.v20190610 + 9.2.3.v20140905 org.eclipse.jetty jetty-webapp - 9.4.19.v20190610 + 9.2.3.v20140905 org.eclipse.jetty jetty-xml - 9.4.19.v20190610 + 9.2.3.v20140905 org.glassfish.jersey.containers @@ -252,10 +253,11 @@ 3.2.1-fixit - com.blazegraph - bigdata-core - 2.1.4 + com.blazegraph + bigdata-core + 2.1.4 + org.openrdf.sesame From c9f947de58c8eb19a6deed98e12767b929159747 Mon Sep 17 00:00:00 2001 From: goodb Date: Wed, 3 Jul 2019 11:27:04 -0700 Subject: [PATCH 10/20] implemented search by logical OR on model state --- .../server/handler/ModelSearchHandler.java | 34 ++++++++++++++++--- .../src/main/resources/QueryTemplateAND.rq | 3 +- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index c079c260..3ef81361 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -79,20 +79,29 @@ public ModelSearchResult searchGet( @QueryParam("gene_product_class_uri") Set gene_product_class_uris, @QueryParam("goterm") Set goterms, @QueryParam("pmid") Set pmids, - @QueryParam("title") String title + @QueryParam("title") String title, + @QueryParam("state") Set state ) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { if(gene_product_class_uris!=null ||goterms!=null ||pmids!=null - ||title!=null) { - return search(gene_product_class_uris, goterms, pmids, title); + ||title!=null + ||state!=null) { + return search(gene_product_class_uris, goterms, pmids, title, state); }else { return getAll(); } } - //examples ?gene_product_class_uri=http://identifiers.org/mgi/MGI:1328355&gene_product_class_uri=http://identifiers.org/mgi/MGI:87986&title=mouse - public ModelSearchResult search(Set gene_product_class_uris, Set goterms, Setpmids, String title_search) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + //examples + //http://127.0.0.1:6800/search/? + //?gene_product_class_uri=http://identifiers.org/mgi/MGI:1328355 + //&gene_product_class_uri=http://identifiers.org/mgi/MGI:87986 + //&goterm=http://purl.obolibrary.org/obo/GO_0030968 + //&title=mouse + //&pmid=PMID:19911006 + //&state=development&state=review {development, production, closed, review, delete} or operator + public ModelSearchResult search(Set gene_product_class_uris, Set goterms, Setpmids, String title_search,Set state_search) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { Set type_uris = new HashSet(); if(gene_product_class_uris!=null) { type_uris.addAll(gene_product_class_uris); @@ -126,10 +135,25 @@ public ModelSearchResult search(Set gene_product_class_uris, Set if(title_search!=null) { title_search_constraint = "?title \""+title_search+"\" .\n"; } + String state_search_constraint = ""; + if(state_search!=null&&state_search.size()>0) { + String allowed_states = ""; + int c = 0; + for(String s : state_search) { + c++; + allowed_states+="\""+s+"\""; + if(c", ind_return_list); sparql = sparql.replaceAll("", types); sparql = sparql.replaceAll("", pmid_constraints); sparql = sparql.replaceAll("", title_search_constraint); + sparql = sparql.replaceAll("", state_search_constraint); TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 10); while(result.hasNext()) { diff --git a/minerva-server/src/main/resources/QueryTemplateAND.rq b/minerva-server/src/main/resources/QueryTemplateAND.rq index 296899d4..a2549f30 100644 --- a/minerva-server/src/main/resources/QueryTemplateAND.rq +++ b/minerva-server/src/main/resources/QueryTemplateAND.rq @@ -22,9 +22,10 @@ WHERE { lego:modelstate ?state . BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . #AND - + + #e.g. #?ind1 rdf:type . #?ind2 rdf:type From be34ffbb9ecf663b24640bf60ae5bafeece6adc6 Mon Sep 17 00:00:00 2001 From: goodb Date: Wed, 3 Jul 2019 12:19:52 -0700 Subject: [PATCH 11/20] added group query and return element still leaving as union in the query. --- .../server/handler/ModelSearchHandler.java | 64 +++++++++++++++++-- .../src/main/resources/QueryTemplateAND.rq | 7 +- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index 3ef81361..0c7d795b 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -60,14 +60,16 @@ public class ModelMeta{ private String title; private String state; private Set contributors; + private Set groups; private HashMap> query_match; - public ModelMeta(String id, String date, String title, String state, Set contributors) { + public ModelMeta(String id, String date, String title, String state, Set contributors, Set groups) { this.id = id; this.date = date; this.title = title; this.state = state; this.contributors = contributors; + this.groups = groups; query_match = new HashMap>(); } } @@ -80,14 +82,18 @@ public ModelSearchResult searchGet( @QueryParam("goterm") Set goterms, @QueryParam("pmid") Set pmids, @QueryParam("title") String title, - @QueryParam("state") Set state + @QueryParam("state") Set state, + @QueryParam("contributor") Set contributor, + @QueryParam("group") Set group ) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { if(gene_product_class_uris!=null ||goterms!=null ||pmids!=null ||title!=null - ||state!=null) { - return search(gene_product_class_uris, goterms, pmids, title, state); + ||state!=null + ||contributor!=null + ||group!=null) { + return search(gene_product_class_uris, goterms, pmids, title, state, contributor, group); }else { return getAll(); } @@ -101,7 +107,9 @@ public ModelSearchResult searchGet( //&title=mouse //&pmid=PMID:19911006 //&state=development&state=review {development, production, closed, review, delete} or operator - public ModelSearchResult search(Set gene_product_class_uris, Set goterms, Setpmids, String title_search,Set state_search) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + public ModelSearchResult search( + Set gene_product_class_uris, Set goterms, Setpmids, + String title_search,Set state_search, Set contributor_search, Set group_search) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { Set type_uris = new HashSet(); if(gene_product_class_uris!=null) { type_uris.addAll(gene_product_class_uris); @@ -149,11 +157,39 @@ public ModelSearchResult search(Set gene_product_class_uris, Set // FILTER (?state IN ("production", , "development", "review", "closed", "delete" )) state_search_constraint = "FILTER (?state IN ("+allowed_states+")) . \n"; } + String contributor_search_constraint = ""; + if(contributor_search!=null&&contributor_search.size()>0) { + String allowed_contributors = ""; + int c = 0; + for(String contributor : contributor_search) { + c++; + allowed_contributors+="\""+contributor+"\""; + if(c0) { + String allowed_group = ""; + int c = 0; + for(String group : group_search) { + c++; + allowed_group+="\""+group+"\""; + if(c", ind_return_list); sparql = sparql.replaceAll("", types); sparql = sparql.replaceAll("", pmid_constraints); sparql = sparql.replaceAll("", title_search_constraint); sparql = sparql.replaceAll("", state_search_constraint); + sparql = sparql.replaceAll("", contributor_search_constraint); + sparql = sparql.replaceAll("", group_search_constraint); TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 10); while(result.hasNext()) { @@ -164,15 +200,22 @@ public ModelSearchResult search(Set gene_product_class_uris, Set String title = bs.getBinding("title").getValue().stringValue(); String state = bs.getBinding("state").getValue().stringValue(); String contribs = bs.getBinding("contributors").getValue().stringValue(); + String groups_ = bs.getBinding("groups").getValue().stringValue(); Set contributors = new HashSet(); if(contributors!=null) { for(String c : contribs.split(";")) { contributors.add(c); } } + Set groups = new HashSet(); + if(groups_!=null) { + for(String c : groups_.split(";")) { + groups.add(c); + } + } ModelMeta mm = id_model.get(id); if(mm==null) { - mm = new ModelMeta(id, date, title, state, contributors); + mm = new ModelMeta(id, date, title, state, contributors, groups); } //matching for(String ind : ind_return.keySet()) { @@ -208,13 +251,20 @@ public ModelSearchResult getAll() throws MalformedQueryException, QueryEvaluatio String title = bs.getBinding("title").getValue().stringValue(); String state = bs.getBinding("state").getValue().stringValue(); String contribs = bs.getBinding("contributors").getValue().stringValue(); + String groups_ = bs.getBinding("groups").getValue().stringValue(); Set contributors = new HashSet(); if(contributors!=null) { for(String c : contribs.split(";")) { contributors.add(c); } } - ModelMeta mm = new ModelMeta(id, date, title, state, contributors); + Set groups = new HashSet(); + if(groups_!=null) { + for(String c : groups_.split(";")) { + groups.add(c); + } + } + ModelMeta mm = new ModelMeta(id, date, title, state, contributors, groups); models.add(mm); n_models++; } diff --git a/minerva-server/src/main/resources/QueryTemplateAND.rq b/minerva-server/src/main/resources/QueryTemplateAND.rq index a2549f30..dce4704c 100644 --- a/minerva-server/src/main/resources/QueryTemplateAND.rq +++ b/minerva-server/src/main/resources/QueryTemplateAND.rq @@ -13,17 +13,20 @@ PREFIX causally_upstream_of: PREFIX provides_direct_input_for: PREFIX directly_positively_regulates: -SELECT ?cam ?id ?date ?title ?state (GROUP_CONCAT(?contributor;separator=";") AS ?contributors) +SELECT ?cam ?id ?date ?title ?state (GROUP_CONCAT(?contributor;separator=";") AS ?contributors) (GROUP_CONCAT(?group;separator=";") AS ?groups) WHERE { GRAPH ?cam { ?cam ?title ; ?date ; - ?contributor ; + ?contributor ; + ?group ; lego:modelstate ?state . BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . #AND + + #e.g. From 224ccdc089ba36cef5c0750b32f3a4d3155d0c4f Mon Sep 17 00:00:00 2001 From: goodb Date: Wed, 3 Jul 2019 13:22:26 -0700 Subject: [PATCH 12/20] Added a date search parameter returns models more recent than the requested date. Date must be in 10 character format: yyyy-mm-dd e.g. 2019-03-05 --- .../server/handler/ModelSearchHandler.java | 17 +++++++++++++---- .../src/main/resources/QueryTemplateAND.rq | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index 0c7d795b..d761f3c8 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -84,7 +85,8 @@ public ModelSearchResult searchGet( @QueryParam("title") String title, @QueryParam("state") Set state, @QueryParam("contributor") Set contributor, - @QueryParam("group") Set group + @QueryParam("group") Set group, + @QueryParam("date") String date ) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { if(gene_product_class_uris!=null ||goterms!=null @@ -92,8 +94,9 @@ public ModelSearchResult searchGet( ||title!=null ||state!=null ||contributor!=null - ||group!=null) { - return search(gene_product_class_uris, goterms, pmids, title, state, contributor, group); + ||group!=null + ||date!=null) { + return search(gene_product_class_uris, goterms, pmids, title, state, contributor, group, date); }else { return getAll(); } @@ -109,7 +112,7 @@ public ModelSearchResult searchGet( //&state=development&state=review {development, production, closed, review, delete} or operator public ModelSearchResult search( Set gene_product_class_uris, Set goterms, Setpmids, - String title_search,Set state_search, Set contributor_search, Set group_search) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + String title_search,Set state_search, Set contributor_search, Set group_search, String date_search) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { Set type_uris = new HashSet(); if(gene_product_class_uris!=null) { type_uris.addAll(gene_product_class_uris); @@ -183,6 +186,11 @@ public ModelSearchResult search( } contributor_search_constraint = "FILTER (?group IN ("+allowed_group+")) . \n"; } + String date_constraint = ""; + if(date_search!=null&&date_search.length()==10) { + //e.g. 2019-06-26 + date_constraint = "FILTER (?date > '"+date_search+"') \n"; + } sparql = sparql.replaceAll("", ind_return_list); sparql = sparql.replaceAll("", types); sparql = sparql.replaceAll("", pmid_constraints); @@ -190,6 +198,7 @@ public ModelSearchResult search( sparql = sparql.replaceAll("", state_search_constraint); sparql = sparql.replaceAll("", contributor_search_constraint); sparql = sparql.replaceAll("", group_search_constraint); + sparql = sparql.replaceAll("", date_constraint); TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 10); while(result.hasNext()) { diff --git a/minerva-server/src/main/resources/QueryTemplateAND.rq b/minerva-server/src/main/resources/QueryTemplateAND.rq index dce4704c..7a1c5e20 100644 --- a/minerva-server/src/main/resources/QueryTemplateAND.rq +++ b/minerva-server/src/main/resources/QueryTemplateAND.rq @@ -27,6 +27,7 @@ WHERE { + #e.g. From 053c9fd286889c81b24347878eaf37f1704987b8 Mon Sep 17 00:00:00 2001 From: goodb Date: Wed, 3 Jul 2019 13:51:39 -0700 Subject: [PATCH 13/20] implemented paging using offset and limit Allows client to iterate through result blocks of arbitrary size. Client decides how many to add to a 'page' in their context. e.g. to iterate through results 2 at a time, query like this, in order: http://127.0.0.1:6800/search/?date=2019-03-06&offset=0&limit=2 http://127.0.0.1:6800/search/?date=2019-03-06&offset=2&limit=2 etc. you will get the same thing you would get from the following request, but in two steps instead of one. http://127.0.0.1:6800/search/?date=2019-03-06&offset=0&limit=4 --- .../server/handler/ModelSearchHandler.java | 28 +++++++++++++++---- .../src/main/resources/QueryTemplateAND.rq | 5 ++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index d761f3c8..a97d7c7c 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -86,7 +86,9 @@ public ModelSearchResult searchGet( @QueryParam("state") Set state, @QueryParam("contributor") Set contributor, @QueryParam("group") Set group, - @QueryParam("date") String date + @QueryParam("date") String date, + @QueryParam("offset") int offset, + @QueryParam("limit") int limit ) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { if(gene_product_class_uris!=null ||goterms!=null @@ -96,9 +98,9 @@ public ModelSearchResult searchGet( ||contributor!=null ||group!=null ||date!=null) { - return search(gene_product_class_uris, goterms, pmids, title, state, contributor, group, date); + return search(gene_product_class_uris, goterms, pmids, title, state, contributor, group, date, offset, limit); }else { - return getAll(); + return getAll(offset, limit); } } @@ -112,7 +114,9 @@ public ModelSearchResult searchGet( //&state=development&state=review {development, production, closed, review, delete} or operator public ModelSearchResult search( Set gene_product_class_uris, Set goterms, Setpmids, - String title_search,Set state_search, Set contributor_search, Set group_search, String date_search) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + String title_search,Set state_search, Set contributor_search, Set group_search, String date_search, + int offset, int limit) + throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { Set type_uris = new HashSet(); if(gene_product_class_uris!=null) { type_uris.addAll(gene_product_class_uris); @@ -191,6 +195,18 @@ public ModelSearchResult search( //e.g. 2019-06-26 date_constraint = "FILTER (?date > '"+date_search+"') \n"; } + String offset_constraint = ""; + if(offset!=0) { + offset_constraint = "OFFSET "+offset+"\n"; + } + String limit_constraint = ""; + if(limit!=0) { + limit_constraint = "LIMIT "+limit+"\n"; + } + if(offset==0&&limit==0) { + limit_constraint = "LIMIT 1000\n"; + } + sparql = sparql.replaceAll("", ind_return_list); sparql = sparql.replaceAll("", types); sparql = sparql.replaceAll("", pmid_constraints); @@ -199,6 +215,8 @@ public ModelSearchResult search( sparql = sparql.replaceAll("", contributor_search_constraint); sparql = sparql.replaceAll("", group_search_constraint); sparql = sparql.replaceAll("", date_constraint); + sparql = sparql.replaceAll("", limit_constraint); + sparql = sparql.replaceAll("", offset_constraint); TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 10); while(result.hasNext()) { @@ -246,7 +264,7 @@ public ModelSearchResult search( return r; } - public ModelSearchResult getAll() throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + public ModelSearchResult getAll(int offset, int limit) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { ModelSearchResult r = new ModelSearchResult(); Set models = new HashSet(); String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/GetAllModels.rq"), StandardCharsets.UTF_8); diff --git a/minerva-server/src/main/resources/QueryTemplateAND.rq b/minerva-server/src/main/resources/QueryTemplateAND.rq index 7a1c5e20..3df60f7c 100644 --- a/minerva-server/src/main/resources/QueryTemplateAND.rq +++ b/minerva-server/src/main/resources/QueryTemplateAND.rq @@ -37,6 +37,7 @@ WHERE { } } GROUP BY ?id ?date ?title ?cam ?state - ORDER BY desc(?date) -limit 10 + ORDER BY desc(?date) ?id + + \ No newline at end of file From c9288a0247a0cd77655e68900a4bbdd19b30236d Mon Sep 17 00:00:00 2001 From: goodb Date: Wed, 3 Jul 2019 13:54:22 -0700 Subject: [PATCH 14/20] cleaning up --- .../server/handler/ModelSearchHandler.java | 2 +- ...lateAND.rq => ModelSearchQueryTemplate.rq} | 0 .../src/main/resources/QueryByGeneUriOR.rq | 32 ----------------- .../src/main/resources/QueryByTypeAND.rq | 34 ------------------- 4 files changed, 1 insertion(+), 67 deletions(-) rename minerva-server/src/main/resources/{QueryTemplateAND.rq => ModelSearchQueryTemplate.rq} (100%) delete mode 100644 minerva-server/src/main/resources/QueryByGeneUriOR.rq delete mode 100644 minerva-server/src/main/resources/QueryByTypeAND.rq diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index a97d7c7c..2ae202b9 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -126,7 +126,7 @@ public ModelSearchResult search( } ModelSearchResult r = new ModelSearchResult(); Map id_model = new HashMap(); - String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/QueryTemplateAND.rq"), StandardCharsets.UTF_8); + String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/ModelSearchQueryTemplate.rq"), StandardCharsets.UTF_8); Map ind_return = new HashMap(); String ind_return_list = ""; // String types = ""; // diff --git a/minerva-server/src/main/resources/QueryTemplateAND.rq b/minerva-server/src/main/resources/ModelSearchQueryTemplate.rq similarity index 100% rename from minerva-server/src/main/resources/QueryTemplateAND.rq rename to minerva-server/src/main/resources/ModelSearchQueryTemplate.rq diff --git a/minerva-server/src/main/resources/QueryByGeneUriOR.rq b/minerva-server/src/main/resources/QueryByGeneUriOR.rq deleted file mode 100644 index dde86a07..00000000 --- a/minerva-server/src/main/resources/QueryByGeneUriOR.rq +++ /dev/null @@ -1,32 +0,0 @@ -PREFIX owl: -PREFIX rdf: -#model metadata -PREFIX metago: -PREFIX lego: -#model data -PREFIX part_of: -PREFIX occurs_in: -PREFIX enabled_by: -PREFIX has_input: -PREFIX has_output: -PREFIX causally_upstream_of: -PREFIX provides_direct_input_for: -PREFIX directly_positively_regulates: - -SELECT ?cam ?id ?date ?title ?state ?gp_ind (GROUP_CONCAT(?contributor;separator=";") AS ?contributors) -WHERE { - GRAPH ?cam { - ?cam ?title ; - ?date ; - ?contributor ; - lego:modelstate ?state . - BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . - ?gp_ind rdf:type ?gp_class . - VALUES(?gp_class ) - #e.g. VALUES ?gp_class { } - } - } - GROUP BY ?id ?date ?title ?cam ?state ?gp_ind - ORDER BY desc(?date) desc(?gp_class) - - \ No newline at end of file diff --git a/minerva-server/src/main/resources/QueryByTypeAND.rq b/minerva-server/src/main/resources/QueryByTypeAND.rq deleted file mode 100644 index 8f4da6ca..00000000 --- a/minerva-server/src/main/resources/QueryByTypeAND.rq +++ /dev/null @@ -1,34 +0,0 @@ -PREFIX owl: -PREFIX rdf: -#model metadata -PREFIX metago: -PREFIX lego: -#model data -PREFIX part_of: -PREFIX occurs_in: -PREFIX enabled_by: -PREFIX has_input: -PREFIX has_output: -PREFIX causally_upstream_of: -PREFIX provides_direct_input_for: -PREFIX directly_positively_regulates: - -SELECT ?cam ?id ?date ?title ?state (GROUP_CONCAT(?contributor;separator=";") AS ?contributors) -WHERE { - GRAPH ?cam { - ?cam ?title ; - ?date ; - ?contributor ; - lego:modelstate ?state . - BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . - #AND - - #e.g. - #?ind1 rdf:type . - #?ind2 rdf:type - } - } - GROUP BY ?id ?date ?title ?cam ?state - ORDER BY desc(?date) -limit 10 - \ No newline at end of file From bbe8677bb25d63dcba74099f7f6d1cdbda20a7eb Mon Sep 17 00:00:00 2001 From: goodb Date: Wed, 3 Jul 2019 14:00:35 -0700 Subject: [PATCH 15/20] shortened gene search query param to gp --- .../geneontology/minerva/server/handler/ModelSearchHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index 2ae202b9..6ac0a208 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -79,7 +79,7 @@ public ModelMeta(String id, String date, String title, String state, Set @GET @Produces(MediaType.APPLICATION_JSON) public ModelSearchResult searchGet( - @QueryParam("gene_product_class_uri") Set gene_product_class_uris, + @QueryParam("gp") Set gene_product_class_uris, @QueryParam("goterm") Set goterms, @QueryParam("pmid") Set pmids, @QueryParam("title") String title, From 14a4c8fa8e9b9e57094910f22182045046fc6104 Mon Sep 17 00:00:00 2001 From: goodb Date: Wed, 3 Jul 2019 22:55:36 -0700 Subject: [PATCH 16/20] refactored search handler slightly - added exception catch and display --- .../minerva/server/StartUpTool.java | 2 +- .../server/handler/ModelSearchHandler.java | 144 +++++++++++------- 2 files changed, 90 insertions(+), 56 deletions(-) diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java b/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java index 0fde600c..b302871f 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/StartUpTool.java @@ -86,7 +86,7 @@ public static class MinervaStartUpConfig { public String prefixesFile = null; - public int sparqlEndpointTimeout = 10; + public int sparqlEndpointTimeout = 100; } public static void main(String[] args) throws Exception { diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index 6ac0a208..0274dd43 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -50,9 +50,9 @@ public ModelSearchHandler(BlazegraphMolecularModelManager m3, int timeout) { public class ModelSearchResult { private Integer n; private Set models; - private void makeModelsDistinct() { - - } + private String message; + private String error; + private String sparql; } public class ModelMeta{ @@ -89,19 +89,18 @@ public ModelSearchResult searchGet( @QueryParam("date") String date, @QueryParam("offset") int offset, @QueryParam("limit") int limit - ) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { - if(gene_product_class_uris!=null - ||goterms!=null - ||pmids!=null - ||title!=null - ||state!=null - ||contributor!=null - ||group!=null - ||date!=null) { - return search(gene_product_class_uris, goterms, pmids, title, state, contributor, group, date, offset, limit); - }else { - return getAll(offset, limit); - } + ){ + // if(gene_product_class_uris!=null + // ||goterms!=null + // ||pmids!=null + // ||title!=null + // ||state!=null + // ||contributor!=null + // ||group!=null + // ||date!=null) { + ModelSearchResult result = new ModelSearchResult(); + result = search(gene_product_class_uris, goterms, pmids, title, state, contributor, group, date, offset, limit); + return result; } //examples @@ -115,8 +114,7 @@ public ModelSearchResult searchGet( public ModelSearchResult search( Set gene_product_class_uris, Set goterms, Setpmids, String title_search,Set state_search, Set contributor_search, Set group_search, String date_search, - int offset, int limit) - throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException { + int offset, int limit) { Set type_uris = new HashSet(); if(gene_product_class_uris!=null) { type_uris.addAll(gene_product_class_uris); @@ -126,7 +124,13 @@ public ModelSearchResult search( } ModelSearchResult r = new ModelSearchResult(); Map id_model = new HashMap(); - String sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/ModelSearchQueryTemplate.rq"), StandardCharsets.UTF_8); + String sparql=""; + try { + sparql = IOUtils.toString(ModelSearchHandler.class.getResourceAsStream("/ModelSearchQueryTemplate.rq"), StandardCharsets.UTF_8); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } Map ind_return = new HashMap(); String ind_return_list = ""; // String types = ""; // @@ -206,7 +210,7 @@ public ModelSearchResult search( if(offset==0&&limit==0) { limit_constraint = "LIMIT 1000\n"; } - + sparql = sparql.replaceAll("", ind_return_list); sparql = sparql.replaceAll("", types); sparql = sparql.replaceAll("", pmid_constraints); @@ -217,48 +221,78 @@ public ModelSearchResult search( sparql = sparql.replaceAll("", date_constraint); sparql = sparql.replaceAll("", limit_constraint); sparql = sparql.replaceAll("", offset_constraint); - - TupleQueryResult result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 10); - while(result.hasNext()) { - BindingSet bs = result.next(); - //model meta - String id = bs.getBinding("id").getValue().stringValue(); - String date = bs.getBinding("date").getValue().stringValue(); - String title = bs.getBinding("title").getValue().stringValue(); - String state = bs.getBinding("state").getValue().stringValue(); - String contribs = bs.getBinding("contributors").getValue().stringValue(); - String groups_ = bs.getBinding("groups").getValue().stringValue(); - Set contributors = new HashSet(); - if(contributors!=null) { - for(String c : contribs.split(";")) { - contributors.add(c); - } + r.sparql = sparql; + + TupleQueryResult result; + try { + result = (TupleQueryResult) m3.executeSPARQLQuery(sparql, 10); + } catch (MalformedQueryException | QueryEvaluationException | RepositoryException e) { + if(e instanceof MalformedQueryException) { + r.message = "Malformed Query"; + }else if(e instanceof QueryEvaluationException) { + r.message = "Query Evaluation Problem - probably a time out"; + }else if(e instanceof RepositoryException) { + r.message = "Repository Exception"; } - Set groups = new HashSet(); - if(groups_!=null) { - for(String c : groups_.split(";")) { - groups.add(c); + r.error = e.getMessage(); + e.printStackTrace(); + return r; + } + + try { + while(result.hasNext()) { + BindingSet bs = result.next(); + //model meta + String id = bs.getBinding("id").getValue().stringValue(); + String date = bs.getBinding("date").getValue().stringValue(); + String title = bs.getBinding("title").getValue().stringValue(); + String state = bs.getBinding("state").getValue().stringValue(); + String contribs = bs.getBinding("contributors").getValue().stringValue(); + String groups_ = bs.getBinding("groups").getValue().stringValue(); + Set contributors = new HashSet(); + if(contributors!=null) { + for(String c : contribs.split(";")) { + contributors.add(c); + } } - } - ModelMeta mm = id_model.get(id); - if(mm==null) { - mm = new ModelMeta(id, date, title, state, contributors, groups); - } - //matching - for(String ind : ind_return.keySet()) { - String ind_class_match = bs.getBinding(ind.replace("?", "")).getValue().stringValue(); - Set matching_inds = mm.query_match.get(ind_return.get(ind)); - if(matching_inds==null) { - matching_inds = new HashSet(); + Set groups = new HashSet(); + if(groups_!=null) { + for(String c : groups_.split(";")) { + groups.add(c); + } } - matching_inds.add(ind_class_match); - mm.query_match.put(ind_return.get(ind), matching_inds); + ModelMeta mm = id_model.get(id); + if(mm==null) { + mm = new ModelMeta(id, date, title, state, contributors, groups); + } + //matching + for(String ind : ind_return.keySet()) { + String ind_class_match = bs.getBinding(ind.replace("?", "")).getValue().stringValue(); + Set matching_inds = mm.query_match.get(ind_return.get(ind)); + if(matching_inds==null) { + matching_inds = new HashSet(); + } + matching_inds.add(ind_class_match); + mm.query_match.put(ind_return.get(ind), matching_inds); + } + id_model.put(id, mm); } - id_model.put(id, mm); + } catch (QueryEvaluationException e) { + r.message = "Query Evaluation Problem - probably a time out"; + r.error = e.getMessage(); + e.printStackTrace(); + return r; } r.n = id_model.size(); r.models = new HashSet(id_model.values()); - result.close(); + try { + result.close(); + } catch (QueryEvaluationException e) { + r.message = "Query Evaluation Problem - can't close result set"; + r.error = e.getMessage(); + e.printStackTrace(); + return r; + } //test //http://127.0.0.1:6800/modelsearch/?query=bla return r; From 5a22aef0b55fc2d3352fd031b30de5ebea295a02 Mon Sep 17 00:00:00 2001 From: goodb Date: Wed, 3 Jul 2019 23:11:07 -0700 Subject: [PATCH 17/20] sped up queries by removing id in order by --- .../src/main/resources/ModelSearchQueryTemplate.rq | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/minerva-server/src/main/resources/ModelSearchQueryTemplate.rq b/minerva-server/src/main/resources/ModelSearchQueryTemplate.rq index 3df60f7c..a219001e 100644 --- a/minerva-server/src/main/resources/ModelSearchQueryTemplate.rq +++ b/minerva-server/src/main/resources/ModelSearchQueryTemplate.rq @@ -22,7 +22,6 @@ WHERE { ?group ; lego:modelstate ?state . BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . - #AND @@ -30,14 +29,10 @@ WHERE { - #e.g. - #?ind1 rdf:type . - #?ind2 rdf:type - #?title "mouse" . } } GROUP BY ?id ?date ?title ?cam ?state - ORDER BY desc(?date) ?id + ORDER BY desc(?date) \ No newline at end of file From a21d12369481745332da61cc64540bb0449d127b Mon Sep 17 00:00:00 2001 From: goodb Date: Wed, 3 Jul 2019 23:34:14 -0700 Subject: [PATCH 18/20] substantial speed improvement on text query not all models have provided_by or modelstate annotations. This really impacts the text search service. By making these fields optional, made the searches with text much faster. Works nicely even on full noctua-dev model set. --- minerva-server/src/main/resources/ModelSearchQueryTemplate.rq | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/minerva-server/src/main/resources/ModelSearchQueryTemplate.rq b/minerva-server/src/main/resources/ModelSearchQueryTemplate.rq index a219001e..416d66d0 100644 --- a/minerva-server/src/main/resources/ModelSearchQueryTemplate.rq +++ b/minerva-server/src/main/resources/ModelSearchQueryTemplate.rq @@ -19,8 +19,8 @@ WHERE { ?cam ?title ; ?date ; ?contributor ; - ?group ; - lego:modelstate ?state . + optional{?cam ?group } . + optional{?cam lego:modelstate ?state } . BIND(IF(bound(?id), ?id, concat("gomodel:", substr(str(?cam), 31))) as ?id) . From 4c6c78ab934e2b30fcdcfa7fd64a680f4e74663b Mon Sep 17 00:00:00 2001 From: goodb Date: Mon, 8 Jul 2019 12:53:03 -0700 Subject: [PATCH 19/20] dealt with missing values on optional parameters --- .../minerva/server/handler/ModelSearchHandler.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index 0274dd43..36ad5a8a 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -22,6 +22,7 @@ import org.apache.commons.io.IOUtils; import org.geneontology.minerva.BlazegraphMolecularModelManager; +import org.openrdf.query.Binding; import org.openrdf.query.BindingSet; import org.openrdf.query.MalformedQueryException; import org.openrdf.query.QueryEvaluationException; @@ -246,9 +247,18 @@ public ModelSearchResult search( String id = bs.getBinding("id").getValue().stringValue(); String date = bs.getBinding("date").getValue().stringValue(); String title = bs.getBinding("title").getValue().stringValue(); - String state = bs.getBinding("state").getValue().stringValue(); String contribs = bs.getBinding("contributors").getValue().stringValue(); - String groups_ = bs.getBinding("groups").getValue().stringValue(); + //optional values (some are empty) + Binding state_binding = bs.getBinding("state"); + String state = ""; + if(state_binding!=null) { + state = state_binding.getValue().stringValue(); + } + Binding group_binding = bs.getBinding("groups"); + String groups_ = ""; + if(group_binding!=null) { + groups_ = group_binding.getValue().stringValue(); + } Set contributors = new HashSet(); if(contributors!=null) { for(String c : contribs.split(";")) { From 737cb862f75d4c4ea27d1152840c75ce7413ae82 Mon Sep 17 00:00:00 2001 From: goodb Date: Tue, 9 Jul 2019 14:57:30 -0700 Subject: [PATCH 20/20] added goterm and gp search by curi e.g. http://127.0.0.1:6800/search/?gp=WB:WBGene00002245 http://127.0.0.1:6800/search/?goterm=GO:0030968 --- .../server/handler/ModelSearchHandler.java | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java index 36ad5a8a..8318ea20 100644 --- a/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java +++ b/minerva-server/src/main/java/org/geneontology/minerva/server/handler/ModelSearchHandler.java @@ -5,9 +5,11 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -22,6 +24,8 @@ import org.apache.commons.io.IOUtils; import org.geneontology.minerva.BlazegraphMolecularModelManager; +import org.geneontology.minerva.MolecularModelManager.UnknownIdentifierException; +import org.geneontology.minerva.curie.CurieHandler; import org.openrdf.query.Binding; import org.openrdf.query.BindingSet; import org.openrdf.query.MalformedQueryException; @@ -29,6 +33,7 @@ import org.openrdf.query.QueryResult; import org.openrdf.query.TupleQueryResult; import org.openrdf.repository.RepositoryException; +import org.semanticweb.owlapi.model.IRI; /** * Respond to queries for models in the running blazegraph instance backing minerva @@ -91,14 +96,6 @@ public ModelSearchResult searchGet( @QueryParam("offset") int offset, @QueryParam("limit") int limit ){ - // if(gene_product_class_uris!=null - // ||goterms!=null - // ||pmids!=null - // ||title!=null - // ||state!=null - // ||contributor!=null - // ||group!=null - // ||date!=null) { ModelSearchResult result = new ModelSearchResult(); result = search(gene_product_class_uris, goterms, pmids, title, state, contributor, group, date, offset, limit); return result; @@ -113,17 +110,35 @@ public ModelSearchResult searchGet( //&pmid=PMID:19911006 //&state=development&state=review {development, production, closed, review, delete} or operator public ModelSearchResult search( - Set gene_product_class_uris, Set goterms, Setpmids, + Set gene_product_ids, Set goterms, Setpmids, String title_search,Set state_search, Set contributor_search, Set group_search, String date_search, int offset, int limit) { - Set type_uris = new HashSet(); - if(gene_product_class_uris!=null) { - type_uris.addAll(gene_product_class_uris); + ModelSearchResult r = new ModelSearchResult(); + Set type_ids = new HashSet(); + if(gene_product_ids!=null) { + type_ids.addAll(gene_product_ids); } if(goterms!=null) { - type_uris.addAll(goterms); + type_ids.addAll(goterms); + } + CurieHandler curie_handler = m3.getCuriHandler(); + Set type_uris = new HashSet(); + for(String curi : type_ids) { + if(curi.startsWith("http")) { + type_uris.add(curi); + }else { + try { + IRI iri = curie_handler.getIRI(curi); + if(iri!=null) { + type_uris.add(iri.toString()); + } + } catch (UnknownIdentifierException e) { + r.error += e.getMessage()+" \n "; + e.printStackTrace(); + return r; + } + } } - ModelSearchResult r = new ModelSearchResult(); Map id_model = new HashMap(); String sparql=""; try {