Skip to content

Commit

Permalink
fixed BASE URI for SPARQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrelarmande committed Aug 30, 2024
1 parent 78d18cd commit edf34a0
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions agrold-javaweb/src/main/java/agrold/webservices/dao/TaxonDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,37 @@
public class TaxonDAO {

public static final String TAXON_TYPE_URI2 = "http://purl.obolibrary.org/obo/NCBITaxon_species";
public static final String TAXON_TYPE_URI = "http://www.southgreen.fr/agrold/resource/Taxon";
public static final String TAXON_TYPE_URI = "http://purl.agrold.org/vocabulary/Taxon";
public static final String[] TYPEURIs = new String[]{TAXON_TYPE_URI, TAXON_TYPE_URI2};

// return URIs and agrold_vocabulary:description of all genes in Agrold
public static String getTaxons(int page, int pageSize, String resultFormat) throws IOException {

String sparqlQuery = "PREFIX agrold:<http://www.southgreen.fr/agrold/vocabulary/> \n"
+ "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n"
+ "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "SELECT distinct ?taxonId ?taxonName (group_concat(distinct ?d;separator=\"; \") as ?Description) (?taxon AS ?URI)\n"
+ "WHERE {\n"
+ " OPTIONAL {?taxon rdfs:label ?taxonName .}\n"
+ " OPTIONAL { ?taxon agrold:has_trait ?d} \n"
+ " ?taxon rdf:type|rdfs:subClassOf ?type.\n"
+ " FILTER(?type IN (<"+TAXON_TYPE_URI+">,<"+TAXON_TYPE_URI2+">))\n"
+ " BIND(REPLACE(str(?taxon), '^.*(#|/)', \"\") AS ?taxonId) .\n"
+ "}\n"
+ "ORDER BY DESC(?URI)";
// String sparqlQuery = "PREFIX agrold:<http://purl.agrold.org/vocabulary/> \n"
// + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n"
// + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
// + "SELECT distinct ?taxonId ?taxonName (group_concat(distinct ?d;separator=\"; \") as ?Description) (?taxon AS ?URI)\n"
// + "WHERE {\n"
// + " OPTIONAL {?taxon rdfs:label ?taxonName .}\n"
// + " OPTIONAL { ?taxon agrold:has_trait ?d} \n"
// + " ?taxon rdf:type|rdfs:subClassOf ?type.\n"
// + " FILTER(?type IN (<"+TAXON_TYPE_URI+">,<"+TAXON_TYPE_URI2+">))\n"
// + " BIND(REPLACE(str(?taxon), '^.*(#|/)', \"\") AS ?taxonId) .\n"
// + "}\n"
// + "ORDER BY DESC(?URI)";
String sparqlQuery = "BASE <http://purl.agrold.org/>\n"
+ "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n"
+ "PREFIX fn:<https://www.w3.org/TR/xpath-functions-31/#>\n"
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n"
+ "PREFIX graph: <ensembl.plants>\n"
+ "SELECT distinct ?species\n"
+ "WHERE { \n"
+ "values (?q){(<http://purl.obolibrary.org/obo/RO_0002162>)}\n"
+ "graph graph:{ \n"
+ " ?gene ?q ?species . \n"
+ "} \n"
+ "} \n";
sparqlQuery = Utils.addLimitAndOffset(sparqlQuery, pageSize, page);

return Utils.executeSparqlQuery(sparqlQuery, Utils.sparqlEndpointURL, resultFormat);
Expand Down Expand Up @@ -62,7 +75,7 @@ public static String getTaxonIdAssociatedWithOntoId(String ontoId, int page, int
// + " BIND(REPLACE(str(?taxon), '^.*(#|/)', \"\") AS ?taxonId) .\n"
// + " }\n"
// + "}";
String sparqlQuery = "BASE <http://www.southgreen.fr/agrold/>\n"
String sparqlQuery = "BASE <http://purl.agrold.org/>\n"
+ "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n"
+ "SELECT DISTINCT ?taxonId (?taxon AS ?URI) ?taxonLabel (REPLACE(str(?predicate), '^.*(#|/)', \"\") AS ?Association) "
Expand All @@ -72,7 +85,7 @@ public static String getTaxonIdAssociatedWithOntoId(String ontoId, int page, int
+ " {\n"
+ " ?taxon ?predicate ?ontoElt .\n"
+ " ?ontoElt rdfs:subClassOf ?ontoEltClass.\n"
+ " {?taxon rdf:type <http://www.southgreen.fr/agrold/resource/Taxon>.}\n"
+ " {?taxon rdf:type <http://purl.agrold.org/vocabulary/Taxon>.}\n"
+ " UNION\n"
+ " {?taxon rdfs:subClassOf <http://purl.obolibrary.org/obo/SO_0000771>.}\n"
+ " optional {?ontoElt rdfs:label ?ontoLabel}\n"
Expand All @@ -88,7 +101,7 @@ public static String getTaxonIdAssociatedWithOntoId(String ontoId, int page, int
}

public static String getTaxonsAssociatedWithProteinId(String proteinId, int page, int pageSize, String resultFormat) throws IOException {
String sparqlQuery = "BASE <http://www.southgreen.fr/agrold/>\n"
String sparqlQuery = "BASE <http://purl.agrold.org/>\n"
+ "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n"
+ "PREFIX vocab:<vocabulary/>\n"
+ "PREFIX graph1:<protein.annotations>\n"
Expand Down

0 comments on commit edf34a0

Please sign in to comment.