# -*- coding: utf-8 -*- """ Implementation of the C{@property} value handling. RDFa 1.0 and RDFa 1.1 are fairly different. RDFa 1.0 generates only literals, see U{RDFa Task Force's wiki page} for the details. On the other hand, RDFa 1.1, beyond literals, can also generate URI references. Hence the duplicate method in the L{ProcessProperty} class, one for RDFa 1.0 and the other for RDFa 1.1. @summary: RDFa Literal generation @requires: U{RDFLib package} @organization: U{World Wide Web Consortium} @author: U{Ivan Herman} @license: This software is available for use under the U{W3C® SOFTWARE NOTICE AND LICENSE} """ """ $Id: property.py,v 1.11 2012/06/12 11:47:11 ivan Exp $ $Date: 2012/06/12 11:47:11 $ """ import re, sys import rdflib from rdflib import BNode from rdflib import Literal, URIRef, Namespace if rdflib.__version__ >= "3.0.0" : from rdflib import RDF as ns_rdf from rdflib.term import XSDToPython else : from rdflib.RDF import RDFNS as ns_rdf from rdflib.Literal import XSDToPython from . import IncorrectBlankNodeUsage, IncorrectLiteral, err_no_blank_node, ns_xsd from .utils import has_one_of_attributes, return_XML from .host.html5 import handled_time_types XMLLiteral = ns_rdf["XMLLiteral"] HTMLLiteral = URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML") class ProcessProperty : """Generate the value for C{@property} taking into account datatype, etc. Note: this class is created only if the C{@property} is indeed present, no need to check. @ivar node: DOM element node @ivar graph: the (RDF) graph to add the properies to @ivar subject: the RDFLib URIRef serving as a subject for the generated triples @ivar state: the current state to be used for the CURIE-s @type state: L{state.ExecutionContext} @ivar typed_resource: Typically the bnode generated by a @typeof """ def __init__(self, node, graph, subject, state, typed_resource = None) : """ @param node: DOM element node @param graph: the (RDF) graph to add the properies to @param subject: the RDFLib URIRef serving as a subject for the generated triples @param state: the current state to be used for the CURIE-s @param state: L{state.ExecutionContext} @param typed_resource: Typically the bnode generated by a @typeof; in RDFa 1.1, that becomes the object for C{@property} """ self.node = node self.graph = graph self.subject = subject self.state = state self.typed_resource = typed_resource def generate(self) : """ Common entry point for the RDFa 1.0 and RDFa 1.1 versions; bifurcates based on the RDFa version, as retrieved from the state object. """ if self.state.rdfa_version >= "1.1" : self.generate_1_1() else : self.generate_1_0() def generate_1_1(self) : """Generate the property object, 1.1 version""" ######################################################################### # See if the target is _not_ a literal irirefs = ("resource", "href", "src") noiri = ("content", "datatype", "rel", "rev") notypediri = ("content", "datatype", "rel", "rev", "about", "about_pruned") if has_one_of_attributes(self.node, irirefs) and not has_one_of_attributes(self.node, noiri) : # @href/@resource/@src takes the lead here... object = self.state.getResource(irirefs) elif self.node.hasAttribute("typeof") and not has_one_of_attributes(self.node, notypediri) and self.typed_resource != None : # a @typeof creates a special branch in case the typed resource was set during parsing object = self.typed_resource else : # We have to generate a literal # Get, if exists, the value of @datatype datatype = '' dtset = False if self.node.hasAttribute("datatype") : dtset = True dt = self.node.getAttribute("datatype") if dt != "" : datatype = self.state.getURI("datatype") # Supress lange is set in case some elements explicitly want to supress the effect of language # There were discussions, for example, that the