/usr/share/doc/python-rdflib-doc/examples/slice.py is in python-rdflib-doc 4.1.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | """
RDFLib Graphs (and Resources) can be "sliced" with [] syntax
This is a short-hand for iterating over triples
Combined with SPARQL paths (see ``foafpaths.py``) - quite complex queries
can be realised.
See :meth:`rdflib.graph.Graph.__getitem__` for details
"""
from rdflib import Graph, RDF
from rdflib.namespace import FOAF
if __name__=='__main__':
graph = Graph()
graph.load("foaf.rdf")
for person in graph[: RDF.type : FOAF.Person]:
friends = list(graph[person:FOAF.knows * '+'/FOAF.name])
if friends:
print "%s's circle of friends:"%graph.value(person, FOAF.name)
for name in friends:
print name
|