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 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 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 year(query, year) -> str: query += Constants.observacion( ) + " aragopedia:year " + Constants.fecha() query += TemplatesAragon.create_bif_contains(year, Constants.fecha()) + " . " 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