Functional RDFa
From RDFaWiki
Functional RDFa
One style of programming useful in many situations is Functional Programming.
This style is native to XSLT and many sources of inspiration for XSLT, including DSSSL and Lisp. The following is based on material originally posted by Micah Dubinko at http://lists.w3.org/Archives/Public/public-rdf-in-xhtml-tf/2008Apr/0126.html
Please comment on and enhance this description.
Specification
Given an XHTML document as input, define a mapping to a list of triples as output.
Terminology:
For the attributes rel, rev, typeof, and property, these may contain a whitespace separated list. So the terminology "rel-value", "rev-value", "typeof-value", and "property-value" refers to a single token in the overall attribute value. When an attribute has multiple values, each should be processed in turn.
Certain attributes must always be processed in certain ways, which for brevity are not repeated throughout this page.
@rel CURIEs unprefixed values from the list of XHTML rels are acceptable @rev CURIEs unprefixed values form the list of XHTML rels are acceptable @href URI @src URI @about URIorSafeCURIE @property CURIEs @resource URIorSafeCURIE @datatupe CURIE @typeof CURIEs
The aforementioned list of HTML rel values
chapter contents copyright first glossary help icon index last license meta next p3pv1 prev role section stylesheet subsection start top up
"nearest ancestor subject" computation:
from the starting node, choose the first that applies:
if @about is present, it forms the subject
if @src is present, it forms the subject
if the current node is "head" or "body", the base URI forms the subject
if @typeof is present, a blank node created by the @typeof forms the subject
if the starting node has an ancestor, make the ancestor the current node and proceed below
otherwise, the base URI forms the subject
from a current node, choose the first that applies:
if @resource is present, it forms the subject
if @href is present, it forms the subject
if @about is present, it forms the subject
if @src is present, it forms the subject
if rel-value or typeof-value are present, a newly-created blank-node forms the subject
if the current node has an ancestor, make the ancestor the current node and recur
otherwise the base URI forms the subject.
"completion node list" computation:
In plain english, this means that from a starting node, grab all the descendant nodes with any of 5 key attributes, but exclude stuff already seen (ancestors of the starting node) and stuff yet to be seen (more than one level of completion deep). So for example
<x rel="my:prop">
<x id="d1" resource="find-me">
<x id="d2" about="but-not-me"/>
</x>
</x>
So starting from the outermost element, we want to select d1 but not d2.
Note: key attribute means any of @src or @about or @typeof or @href or @resource
from the starting node, select all descendant nodes where the following applies:
a key attribute is present on the descendant node
decendant nodes' ancestors back to the starting node do not contain any nodes with a key attribute
For each property-value on a node:
if the property-value is a valid CURIE:
generate a triple:
xml:lang = language code from the node, or nearest ancestor
subject = formed from nearest ancestor subject of the node
predicate = formed from property-value CURIE
Note: XMLLiteral processing occurs if (and only if) any of the following holds:
@datatype is present and has a CURIE value that resolves to "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"
@datatype is not present, and the node has children, at least one of which is not a text node
if XMLLiteral processing occurs:
parseType = "Literal"
object = deep copy of the contents of the node
else
if @datatype is present and a valid, nonblank CURIE:
datatype = value from @datatype
if @content is present:
object = value from @content
else
object = text value of node
For each rel-value on a node:
if @resource or @rel are present, process the node IMMEDIATE rel-value otherwise process the node as a HANGING rel-value and also process the node as a HANGING-BNODE rel-value
For each IMMEDIATE rel-value on a node:
if the rel-value is a valid CURIE or value from the XHTML relation list:
generate a triple:
subject = nearest ancestor subject of the node
predicate = URL from rel-value CURIE
object = choose the first that applies:
if @resource is present, then it forms the object
if @href is present, then it forms the object
For each HANGING rel-value on a node: (note that multiple triples may be completed from a single rel-value)
if the rel-value is a valid CURIE or value from the XHTML relation list:
for each completion node (determined using the algorithm above):
generate a triple:
subject = nearest ancestor subject of the node
predicate = URL from the rel-value CURIE
object = choose the first that applies:
if @about is present on the completion node, then it forms the object
if @src is present on the completion node, then it forms the object
if @typeof is present on the completion node, then a blank node formed by the typeof forms the object
if @rel or @rev are present on the completion, STOP, do not generate a triple and do not
if @resource is present, then it forms the object
if @href is present, then it forms the object
otherwise, a blank node generated from the completion node forms the object
For each HANGING-BNODE rel-value on a node: (note that @rel/@rev/@property completers share a bnode, which is generated here)
if the node has a descendant with @rel, @rev, or @property present:
generate a triple:
subject = nearest ancestor subject of node
predicate = URL from the rel-value CURIE
object = blank node created by this node
For each rev-value on a node:
exactly per the "rel" rules above, except subject and object are exchanged when generating the triple
For each typeof-value on a node:
if the typeof-value is a valid CURIE:
generate a triple:
subject = choose the first that applies:
if @about is present, then it forms the subject
if @src is present, then it forms the subject
if the name of the node is "head" or "body", then the base URI forms the subject
if @resource is present and neither @rel nor @rev are present, then @resource forms the subject
if @href is present and neither @rel nor @rev are present, then @href forms the subject
otherwise a blank node created by this node forms the subject
predicate = rdf:type
object = formed by typeof-value CURIE

