def tipo_localizacion_cultivos(query, tipo_localizacion) -> str:
        tipo_localizacion = tipo_localizacion.lower()

        if tipo_localizacion == "aragon":
            query = query.replace(
                "WHERE",
                " FROM " + Constants.grafo_agricultura_cultivos_aragon() +
                " WHERE",
            )
        elif tipo_localizacion == "municipio":
            query = query.replace(
                "WHERE",
                " FROM " + Constants.grafo_agricultura_cultivos_municipio() +
                " WHERE",
            )
        elif tipo_localizacion == "provincia":
            query = query.replace(
                "WHERE",
                " FROM " + Constants.grafo_agricultura_cultivos_provincia() +
                " WHERE",
            )
        elif tipo_localizacion == "comarca":
            query = query.replace(
                "WHERE",
                " FROM " + Constants.grafo_agricultura_cultivos_comarca() +
                " WHERE",
            )
        return query
Esempio n. 2
0
 def base_query() -> str:
     base = (Config.prefix() + "SELECT DISTINCT " + Constants.answer0() +
             " " + Constants.etiqueta())
     if Config.graph() != "":
         base += " FROM <" + Config.graph() + ">"
     base += " WHERE { "
     return base
Esempio n. 3
0
    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
Esempio n. 4
0
    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
Esempio n. 5
0
    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
Esempio n. 6
0
    def year(query, year) -> str:

        query += Constants.observacion(
        ) + " aragopedia:year " + Constants.fecha()

        query += TemplatesAragon.create_bif_contains(year,
                                                     Constants.fecha()) + " . "

        return query
    def year(query, year) -> str:

        query += (
            Constants.aux0() +
            " <http://purl.org/linked-data/sdmx/2009/dimension#refPeriod> " +
            Constants.etiqueta())

        query += (TemplatesAgriculture.create_bif_contains(
            year, Constants.etiqueta()) + " . ")
        return query
Esempio n. 8
0
    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
Esempio n. 9
0
    def area_filter_extranjeros(query, nombre_area) -> str:
        nombre_area = nombre_area.lower()

        query = query.replace(
            Constants.etiqueta2() + " . ",
            Constants.etiqueta2() + " . " +
            TemplatesAragon.create_bif_contains(nombre_area,
                                                Constants.etiqueta2()) + " . ",
        )
        return query
Esempio n. 10
0
    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
Esempio n. 11
0
    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
Esempio n. 12
0
    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
Esempio n. 13
0
    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
Esempio n. 14
0
    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
Esempio n. 15
0
    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
Esempio n. 16
0
    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
Esempio n. 17
0
    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
Esempio n. 18
0
    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
Esempio n. 19
0
    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
Esempio n. 20
0
    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 secano(query, municipio) -> str:

        query += (
            Constants.aux0() +
            " <http://opendata.aragon.es/def/iaest/medida#hectareas-en-tierras-labradas-de-secano> "
            + Constants.answer0() + " . ")

        query += (
            Constants.aux0() +
            " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " +
            Constants.etiqueta2() + " . ")

        query += (TemplatesAgriculture.create_bif_contains(
            municipio, Constants.etiqueta2()) + " . ")
        return query
    def ecologica(query, municipio) -> str:

        query += (
            Constants.aux0() +
            " <http://opendata.aragon.es/def/iaest/medida#superficie-total-agricultura-ecologica> "
            + Constants.answer0() + " . ")

        query += (
            Constants.aux0() +
            " <http://purl.org/linked-data/sdmx/2009/dimension#refArea> " +
            Constants.etiqueta2() + " . ")

        query += (TemplatesAgriculture.create_bif_contains(
            municipio, Constants.etiqueta2()) + " . ")
        return query
Esempio n. 23
0
    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
Esempio n. 24
0
    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
Esempio n. 25
0
    def empresasActivas(query: str, location: str) -> str:

        query += (
            '''
            ?emp rdf:type org:Organization .

            ?emp ei2a:organizationName ''' + Constants.answer0() + ' . ' +
            '''?emp dc:type ?tipo .
    
            FILTER regex(?tipo, "empresa_turismo_activo") .
    
            ?emp geo:location ?loc .
    
            ?loc ?b ''' + Constants.etiqueta() + ''' FILTER regex(''' +
            Constants.etiqueta() + ''', "''' +
            TemplatesAragon.create_bif_contains_only_change_cadena(location) +
            '") .')

        return query
Esempio n. 26
0
    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
Esempio n. 27
0
    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
Esempio n. 28
0
    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
Esempio n. 29
0
    def cargo(query, cargo) -> str:

        query += Constants.id_membresia() + " org:role " + Constants.id_rol(
        ) + " . "

        query += Constants.id_rol() + ' ei2a:roleName "' + cargo.upper(
        ) + '" . '

        query += (Constants.id_membresia() + " org:member " +
                  Constants.id_persona() + " . ")

        query += (Constants.id_persona() + " ei2a:fullName " +
                  Constants.answer0() + " . ")
        return query
Esempio n. 30
0
    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