1
0
mirror of https://github.com/gsi-upm/sitc synced 2024-11-22 06:22:29 +00:00
sitc/lod/sparql.py
2017-02-27 12:53:23 +01:00

24 lines
523 B
Python

# !/bin/env python #
# Ejemplo de consultas SPARQL sobre turtle #
# python consultas.py #
import rdflib
import sys
dataset = sys.argv[1] if len(sys.argv) > 1 else 'reviews.ttl'
g = rdflib.Graph()
schema = rdflib.Namespace("http://schema.org/")
# Read Turtle file #
g.parse(dataset, format='turtle')
results = g.query(
"""SELECT DISTINCT ?review ?p ?o
WHERE {
?review a schema:Review.
?review ?p ?o.
}""", initNs={'schema': schema})
for row in results:
print("%s %s %s" % row)