def uso_suelo(query, municipio) -> str: query = query.replace( "WHERE", " FROM " + Constants.grafo_uso_suelo() + " WHERE") query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " + Constants.etiqueta() + " . ") query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") answerpart = ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/dimension#corine-land-cover-2000-nivel-5-descripcion> " + Constants.aux1() + " . ") query += answerpart query += ("BIND(SUBSTR(STRDT(" + Constants.aux1() + ", xsd:string),80) as" + Constants.answer0() + ") . ") query += TemplatesAragon.selecting_max_year( Constants.grafo_uso_suelo(), answerpart) return query
def antiguedad_edificios(query, municipio) -> str: query = query.replace( "WHERE", Constants.fecha() + " " + Constants.etiqueta2() + " FROM " + Constants.grafo_edificios_construccion() + " WHERE", ) query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " + Constants.etiqueta() + " . ") query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") answerpart = ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/medida#numero-hogares> " + Constants.answer0() + " . ") query += answerpart query += TemplatesAragon.selecting_max_year( Constants.grafo_edificios_construccion(), answerpart) return query
def selecting_max_year(grafo: str, answerpart: str) -> str: query = " { SELECT DISTINCT MAX(xsd:integer(?max)) as " + Constants.year_max( ) query += " FROM " + grafo query += " WHERE { " query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " + Constants.etiqueta() + " . ") query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refPeriod> " + Constants.fecha() + " . ") query += ("BIND(SUBSTR(STRDT(" + Constants.fecha() + ", xsd:string),38,4) as ?max) . ") query += answerpart query += " }}" return query
def tipo_area_extranjeros(query, tipo_area) -> str: tipo_area = tipo_area.lower() if tipo_area == "continente": query = query.replace( "WHERE", " FROM " + Constants.grafo_extranjeros_continente() + " WHERE") query += ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/medida#personas> " + Constants.answer0() + " . ") elif tipo_area == "pais": query = query.replace( "WHERE", " FROM " + Constants.grafo_extranjeros_pais() + " WHERE") query += ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/medida#extranjeros> " + Constants.answer0() + " . ") query += ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/dimension#nacionalidad-" + tipo_area + "-nombre> " + Constants.etiqueta2() + " . ") return query
def empresas_por_actividad(query, municipio) -> str: query = query.replace("SELECT DISTINCT ?answer0", "SELECT DISTINCT SUM(?answer0) as ?answer0") query = query.replace( "WHERE", " FROM " + Constants.grafo_actividad_empresa() + " WHERE") query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " + Constants.etiqueta() + " . ") query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") answerpart = ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/medida#numero-de-actividades> " + Constants.answer0() + " . ") query += answerpart query += TemplatesAragon.selecting_max_year( Constants.grafo_sector_empresa(), answerpart) return query
def superficie_municipio(query, municipio) -> str: query += (Constants.municipio() + " aragopedia:areaTotal " + Constants.answer0() + " . ") query += Constants.municipio() + " rdfs:label " + Constants.etiqueta() query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") return query
def superficie_secano(query, municipio) -> str: query += (Constants.municipio() + " aragopedia:hasObservation " + Constants.observacion() + " . ") query += Constants.municipio() + " rdfs:label " + Constants.etiqueta() query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") query += (Constants.observacion() + " aragopedia:hectareasCultivosSecano " + Constants.answer0() + " . ") return query
def comarca_del_municipio(query, municipio) -> str: query += (Constants.municipio() + " aragopedia:enComarca " + Constants.comarca() + " . ") query += Constants.municipio() + " rdfs:label " + Constants.etiqueta() query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") query += Constants.comarca() + " rdfs:label " + Constants.answer0( ) + " . " return query
def cargo_municipio(query, municipio) -> str: # municipio = municipio.upper() # En el campo esta en mayusculas el municipio query += (Constants.id_membresia() + " org:organization " + Constants.municipio() + " . ") query += (Constants.municipio() + " ei2a:organizationName " + Constants.etiqueta()) query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") return query
def poblacion(query, municipio) -> str: query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " + Constants.etiqueta() + " . ") query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") query += (Constants.municipio() + " <http://opendata.aragon.es/def/iaest/medida#poblacion> " + Constants.answer0() + " . ") return query
def habitantes_municipio(query, municipio) -> str: query = query.replace(Constants.answer0(), Constants.answer0() + " " + Constants.answer1()) query += (Constants.municipio() + " aragopedia:menPopulation " + Constants.answer0() + " . ") query += (Constants.municipio() + " aragopedia:womenPopulation " + Constants.answer1() + " . ") query += Constants.municipio() + " rdfs:label " + Constants.etiqueta() query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") return query
def email_ayuntamiento(query, municipio) -> str: # municipio = municipio.upper() # En el campo esta en mayusculas el municipio query += (Constants.municipio() + " " + Constants.aux0() + " ei2a:Ayuntamiento . ") query += (Constants.municipio() + " ei2a:organizationName " + Constants.etiqueta()) query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") query += Constants.municipio() + " foaf:mbox " + Constants.answer0( ) + " . " return query
def year_dataset(query, year) -> str: Log.log_debug("QUERIES_: Entrando a year_dataset()") Log.log_debug("QUERIES_: Year entrante: {0} ".format(year)) if year == "": query = TemplatesAragon.year_max_one_paramater(query) else: Log.log_debug( "QUERIES_: query before replacing: {0} ".format(query)) pos_init = query.find("{ SELECT") Log.log_debug("QUERIES_: posicion init: {0} ".format(pos_init)) pos_end = query.find(" }}") Log.log_debug("QUERIES_: posicion end: {0} ".format(pos_end)) subquery = query[pos_init:pos_end + 3] Log.log_debug("QUERIES_: subquery: {0} ".format(subquery)) query = query.replace(subquery, "") Log.log_debug("QUERIES_: query post replace: {0} ".format(query)) query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refPeriod> " + Constants.fecha() + " . ") query += ( TemplatesAragon.create_bif_contains(year, Constants.fecha()) + " . ") return query
def year_dataset_max(query, cadena) -> str: Log.log_debug("QUERIES_: Entrando a year_dataset_max()") Log.log_debug("QUERIES_: query: {0} ".format(query)) query = query.replace( Constants.etiqueta() + " FROM", Constants.etiqueta() + " " + Constants.fecha() + " FROM", ) query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refPeriod> " + Constants.fecha() + " . ") try: if int(cadena) > 1900: query += (TemplatesAragon.create_filter_regex_var( "STRDT(" + str(cadena) + ", xsd:string)", Constants.fecha()) + " . ") except: query += (TemplatesAragon.create_filter_regex_var( "STRDT(" + Constants.year_max() + ", xsd:string)", Constants.fecha()) + " . ") return query
def num_parados(query, municipio) -> str: query = query.replace("WHERE", " FROM " + Constants.grafo_parados() + " WHERE") query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " + Constants.etiqueta() + " . ") query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") query += (Constants.municipio() + " <http://opendata.aragon.es/def/iaest/medida#n-parados> " + Constants.answer0() + " . ") return query
def num_trabajadores(query: str, trabajadores: str) -> str: query += (Constants.municipio() + " <http://opendata.aragon.es/def/iaest/dimension#estrato> " + Constants.etiqueta2() + " . ") query += TemplatesAragon.create_bif_contains(trabajadores, Constants.etiqueta2()) return query
def hectareas_quemadas(query, municipio) -> str: query = query.replace( "WHERE", " FROM " + Constants.grafo_incendios() + " WHERE") query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " + Constants.etiqueta() + " . ") query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") query += ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/medida#superficie-forestal-afectada> " + Constants.answer0() + " . ") return query
def renta_per_capita(query, municipio) -> str: query = query.replace("WHERE", " FROM " + Constants.grafo_renta() + " WHERE") query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " + Constants.etiqueta() + " . ") query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") query += ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/medida#renta-disponible-bruta-per-capita> " + Constants.answer0() + " . ") return query
def antiguedad(query: str, antiguedad: str) -> str: query += ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/dimension#ano-de-construccion> " + Constants.etiqueta2() + " . ") query += (TemplatesAragon.create_bif_contains( antiguedad, Constants.etiqueta2()) + " . ") return query
def actividad(query: str, actividad: str) -> str: query += ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/dimension#rama-de-actividad> " + Constants.etiqueta2() + " . ") query += (TemplatesAragon.create_bif_contains( actividad, Constants.etiqueta2()) + " . ") return query
def sector(query: str, sector: str) -> str: query += ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/dimension#sector-descripcion> " + Constants.etiqueta2() + " . ") query += TemplatesAragon.create_bif_contains(sector, Constants.etiqueta2()) return query
def tipo_superficie(query: str, tipo_superficie: str) -> str: query += ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/dimension#corine-land-cover-2000-nivel-1-descripcion> " + Constants.aux1() + " . ") query += TemplatesAragon.create_bif_contains(tipo_superficie, Constants.aux1()) return query
def poblacion_extranjeros(query, municipio) -> str: query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " + Constants.etiqueta() + " . ") query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") return query
def fax_municipio(query, municipio) -> str: # municipio = municipio.upper() # En el campo esta en mayusculas el municipio query += (Constants.municipio() + " " + Constants.aux0() + " ei2a:Ayuntamiento . ") query += (Constants.municipio() + " ei2a:organizationName " + Constants.etiqueta()) query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") query += Constants.municipio() + " org:hasSite " + Constants.sede( ) + " . " query += Constants.sede() + " org:siteAddress " + Constants.aux1( ) + " . " query += Constants.aux1() + " vcard:Fax " + Constants.answer0() + " . " return query
def empresas_por_trabajadores(query, municipio) -> str: query = query.replace("SELECT DISTINCT ?answer0", "SELECT DISTINCT SUM(?answer0) as ?answer0") query = query.replace( "WHERE", " FROM " + Constants.grafo_trabajadores_empresa() + " WHERE") query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " + Constants.etiqueta() + " . ") query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") query += ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/medida#numero-empresas> " + Constants.answer0() + " . ") return query
def sexo(query, sexo) -> str: sexo = sexo.lower() query = query.replace("SELECT DISTINCT ?answer0", "SELECT DISTINCT SUM(?answer0) as ?answer0") query += (Constants.municipio() + " <http://opendata.aragon.es/def/iaest/dimension#sexo> " + Constants.aux1() + " . ") if sexo == "mujeres" or sexo == "hombres": query += TemplatesAragon.create_bif_contains( sexo, Constants.aux1()) + " . " return query
def hectareas_zona(query, municipio) -> str: query = query.replace( "WHERE", " FROM " + Constants.grafo_hectareas_zona() + " WHERE") query += ( Constants.municipio() + " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " + Constants.etiqueta() + " . ") query += (TemplatesAragon.create_bif_contains( municipio, Constants.etiqueta()) + " . ") answerpart = ( Constants.municipio() + " <http://opendata.aragon.es/def/iaest/medida#superficie-has> " + Constants.answer0() + " . ") query += answerpart query += TemplatesAragon.selecting_max_year( Constants.grafo_contenedores_vidrio(), answerpart) return query