package fr.insee.rmes.api.geo;

import fr.insee.rmes.config.Configuration;

public class GeoQueries {
	
	public static String getCommune(String code) {
		return "SELECT ?uri ?intitule WHERE { \n"
				+ "?uri igeo:codeINSEE '" + code + "'^^xsd:token . \n"
				+ "?uri igeo:nom ?intitule \n"
				// Ensure that is not the IGN URI and include COM towns
				+ "FILTER (REGEX(STR(?uri), '" + Configuration.BASE_HOST + "/geo/commune/')) \n"
				+ "FILTER (lang(?intitule) = 'fr') \n"
				+ "}";
	}
	
	public static String getCountry(String code) {
		return "SELECT ?uri ?intitule ?intituleEntier WHERE { \n"
				+ "?uri rdf:type igeo:Etat . \n"
				+ "?uri igeo:codeINSEE '" + code + "'^^xsd:token . \n"
				+ "?uri igeo:nom ?intitule . \n"
				+ "?uri igeo:nomEntier ?intituleEntier . \n"
				// Ensure that is not the dbpedia URI
				+ "FILTER (REGEX(STR(?uri), '" + Configuration.BASE_HOST + "')) \n"
				+ "FILTER (lang(?intitule) = 'fr') \n"
				+ "FILTER (lang(?intituleEntier) = 'fr') \n"
				+ "}";
	}
	
	public static String getRegion(String code) {
		return "SELECT ?uri ?intitule WHERE { \n"
				+ "?uri rdf:type igeo:Region . \n"
				+ "?uri igeo:codeINSEE '" + code + "'^^xsd:token . \n"
				+ "?uri igeo:nom ?intitule \n"
				// Ensure that is not the IGN URI
				+ "FILTER (REGEX(STR(?uri), '" + Configuration.BASE_HOST + "')) \n"
				+ "FILTER (lang(?intitule) = 'fr') \n"
				+ "}";
	}

}

@@ -169,32 +169,97 @@
  ?uri ?intitule 
+%5Cn%22%0A%09%09%09%09+ %22FROM %3Chttp://rdf.insee.fr/graphes/geo/cog%3E %5Cn%22%0A%09%09%09%09+ %22
 WHERE %7B %5Cn%22%0A%09%09%09%09
@@ -246,32 +246,32 @@
 %09+ %22WHERE %7B %5Cn%22%0A
-
 %09%09%09%09+ %22?uri igeo
@@ -648,16 +648,81 @@
 eEntier 
+%5Cn%22%0A%09%09%09%09+ %22FROM %3Chttp://rdf.insee.fr/graphes/geo/cog%3E %5Cn%22%0A%09%09%09%09+ %22
 WHERE %7B 
@@ -1168,32 +1168,32 @@
 (String code) %7B%0A
-
 %09%09return %22SELECT
@@ -1208,16 +1208,81 @@
 ntitule 
+%5Cn%22%0A%09%09%09%09+ %22FROM %3Chttp://rdf.insee.fr/graphes/geo/cog%3E %5Cn%22%0A%09%09%09%09+ %22
 WHERE %7B 

Optimise COG queries