#!/usr/bin/env python # coding: utf-8 # ## Introducción # # Proyecto para la extracción y transformación de la colección digital Relaciones Geográficas a un modelo semántico basado en el vocabulario [European Data Model](https://pro.europeana.eu/page/edm-documentation). # # En este prototipo se han seleccionado [81 obras](input/manifests.txt) a través de sus manifests en formato JSON de la colección [Relaciones Geográficas of Mexico and Guatemala](https://collections.lib.utexas.edu/?f%5Bmods_relatedItem_titleInfo_title_source_t%5D%5B%5D=Relaciones+Geogr%C3%A1ficas+of+Mexico+and+Guatemala). # El [dataset](rdf/relaciones_uca.rdf) se ha transformado al formato RDF siguiendo el vocabulario EDM. # # El prototipo incluye las [modificaciones realizadas para la transformación a RDF con la herramienta Open Refine](openrefine/openrefine-steps.json). También se ha desarrollado un [Jupyter Notebook](https://nbviewer.org/github/hibernator11/UCA-relacionesgeograficas/blob/main/notebooks/EjemplosSPARQL.ipynb) que se puede ejecutar en la plataforma Binder. # ### Importamos la librería rdflib y cargamos el fichero RDF # In[27]: from rdflib import Graph # Create a Graph g = Graph().parse("rdf/relaciones_uca.rdf") # ### Consultar recursos de tipo edm:Agent # In[28]: print('##### edm:Agent') # Query the data in g using SPARQL # This query returns the 'name' of all ``edm:Agent`` instances q = """ PREFIX skos: PREFIX edm: SELECT ?name WHERE { ?p rdf:type edm:Agent . ?p skos:prefLabel ?name . } """ # Apply the query to the graph and iterate through results for r in g.query(q): print(r["name"]) # ### Consultar recursos de tipo edm:Place # In[29]: print('##### edm:Place') # Query the data in g using SPARQL # This query returns the 'name' of all ``edm:Place`` instances q = """ PREFIX skos: PREFIX edm: PREFIX wgs: SELECT distinct ?p ?lat ?long ?lbl WHERE { ?p rdf:type edm:Place . ?p skos:prefLabel ?lbl . ?p wgs:long ?long . ?p wgs:lat ?lat . } """ # Apply the query to the graph and iterate through results for r in g.query(q): print(r['p'] + ' ' + r["lbl"] + ' ' + r["lat"] + ' ' + r["long"]) # ### Consultar recursos de tipo edm:ProvidedCHO # In[7]: print('##### edm:ProvidedCHO') # Query the data in g using SPARQL # This query returns the 'name' of all ``edm:ProvidedCHO`` instances q = """ PREFIX skos: PREFIX edm: PREFIX dc: SELECT ?title WHERE { ?p rdf:type edm:ProvidedCHO . ?p dc:title ?title . } """ # Apply the query to the graph and iterate through results for r in g.query(q): print(r["title"]) # ### Propiedades utilizadas en los recursos de tipo ore:Aggregation # In[8]: print('##### ore:Aggregation') # Query the data in g using SPARQL # This query returns the 'name' of all ``edm:ProvidedCHO`` instances q = """ PREFIX ore: PREFIX edm: PREFIX dc: SELECT DISTINCT ?p WHERE { ?s rdf:type ore:Aggregation . ?s ?p ?o. } """ # Apply the query to the graph and iterate through results for r in g.query(q): print(r["p"]) # In[14]: print('##### void:Dataset') # Query the data in g using SPARQL # This query returns the 'name' of all ``edm:ProvidedCHO`` instances q = """ PREFIX ore: PREFIX edm: PREFIX void: PREFIX rdf: PREFIX rdfs: SELECT DISTINCT ?p ?o WHERE { ?s rdf:type void:Dataset . ?s ?p ?o. } """ # Apply the query to the graph and iterate through results for r in g.query(q): print(r["p"] + ' ' + r["o"]) # In[ ]: