Skip to content

Instantly share code, notes, and snippets.

@daniel-dona
Created May 13, 2020 09:05
Show Gist options
  • Save daniel-dona/d2fda3669aecdf859454e072f4a36e43 to your computer and use it in GitHub Desktop.
Save daniel-dona/d2fda3669aecdf859454e072f4a36e43 to your computer and use it in GitHub Desktop.
from rdflib import Graph, URIRef, Namespace, Literal
from pprint import pprint
data = '''
@prefix rr: <http://www.w3.org/ns/r2rml#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix : <http://mapping.example.com/>.
:map_stoptimes_0 a rr:TriplesMap;
rdfs:label "stoptimes".
:s_0 a rr:SubjectMap.
:map_stoptimes_0 rr:subjectMap :s_0.
:s_0 rr:template "http://transport.linkeddata.es/madrid/metro/stoptimes/{trip_id}-{stop_id}-{arrival_time}".
:pom_0 a rr:PredicateObjectMap.
:map_stoptimes_0 rr:predicateObjectMap :pom_0.
:pm_0 a rr:PredicateMap.
:pom_0 rr:predicateMap :pm_0.
:pm_0 rr:constant rdf:type.
'''
graph = Graph()
graph.parse(data=data, format="ttl")
print("ORIGINAL: ")
print(data)
print("PROCESSED: ")
print(graph.serialize(format="ttl").decode())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment