| 1 |
|
| 2 |
""" |
| 3 |
Encoding of the RDFa prototype vocabulary behavior. This means processing the graph by adding and removing triples |
| 4 |
based on triples using the rdfa:Prototype and rdfa:ref class and property, respectively. For details, see the HTML5+RDFa document. |
| 5 |
|
| 6 |
|
| 7 |
@author: U{Ivan Herman<a href="http://www.w3.org/People/Ivan/">} |
| 8 |
@license: This software is available for use under the |
| 9 |
U{W3C® SOFTWARE NOTICE AND LICENSE<href="http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231">} |
| 10 |
@contact: Ivan Herman, [email protected] |
| 11 |
@version: $Id: prototype.py,v 1.1 2013-01-18 09:41:49 ivan Exp $ |
| 12 |
$Date: 2013-01-18 09:41:49 $ |
| 13 |
""" |
| 14 |
|
| 15 |
from rdflib import RDF as ns_rdf |
| 16 |
|
| 17 |
from .. import ns_rdfa |
| 18 |
|
| 19 |
Prototype = ns_rdfa["Pattern"] |
| 20 |
pref = ns_rdfa["copy"] |
| 21 |
|
| 22 |
def handle_prototypes(graph): |
| 23 |
to_remove = set() |
| 24 |
for x, ref, PR in graph.triples((None, pref, None)): |
| 25 |
if (PR, ns_rdf["type"], Prototype) in graph: |
| 26 |
to_remove.add((PR, ns_rdf["type"], Prototype)) |
| 27 |
to_remove.add((x, ref, PR)) |
| 28 |
|
| 29 |
for (PR, p, y) in graph.triples((PR, None, None)): |
| 30 |
if not (p == ns_rdf["type"] and y == Prototype): |
| 31 |
graph.add((x, p, y)) |
| 32 |
to_remove.add((PR, p, y)) |
| 33 |
for t in to_remove: graph.remove(t) |
| 34 |
|