Package pyRdfa :: Package transform :: Module ContainersCollections
[hide private]
[frames] | no frames]

Module ContainersCollections

source code

Transfomer: handles the RDF collections and containers. This means that structures of the form:

 <ul typeof="rdf:Seq">
   <li>....</li>
   ....
 </ul>

are turned into intermediate DOM nodes that yield, via the RDFa processing, RDF containers, whereas structures of the form:

 <ul typeof="rdf:List">
   <li>....</li>
   ....
 </ul>

are turned into intermediate DOM nodes that yield, via the RDFa processing, RDF collections.

The details are as follows:

The Container case

In its simplest form the transformation adds @property attributes to the <li> elements with the values of rdf:_1, rdf:_2,... Ie, the transformed DOM tree is equivalent to:

<ul typeof="rdf:Seq">
   <li property="rdf:1">....</li>
   <li property="rdf:2">....</li>
   ....
 </ul>

which will yield the right RDF collection triples. This simple case occurs if the li element does not include any of the RDFa attributes href, resource, typeof, rel, rev, or property. Otherwise, the li will be surrounded by a new element with a rel attribute of value rdf:_1, rdf:_2,... Ie, the following XHTML code:

 <ul typeof="rdf:Seq">
   <li typeof="a:b">....</li>
   <li about="#b">...</li>
   ....
 </ul>

will be transformed into:

 <ul typeof="rdf:Seq">
   <div rel="rdf:_1"><li typeof="a:b">....</li></div>
   <div rel="rdf:_2"><li about="#b">...</li></div>
   ....
 </ul>

Although this is meaningless (and invalid!) in terms of XHTML, this modified DOM tree is used by the RDFa parser only and will generate the right RDF triplets.

The Collection case

The simple case is again when the individual <li> elements do not include and of RDFa attributes href, resource, typeof, rel, rev, or property. The code:

 <ul typeof="rdf:List">
   <li>text 1</li>
   <li>text 2</li>
 </ul>

is transformed into:

 <ul about="_:a1" typeof="rdf:List">
   <li about="_:a1" property="rdf:first">text 1</li>
   <li about="_:a1" rel="rdf:rest" resource="[_:a2]"/>
   <li about="_:a2" property="rdf:first">text 2</li>
   <li about="_:a2" typeof="rdf:List" rel="rdf:rest" resource="[rdf:nil]"/>
 </ul>

(Where the _:a1, _:a2, etc are just for illustration; for each <ul>/<li> structure unique identifiers are used.) Just as in the case of containers, the transformation is more complicated insofar as the original <li> is surrounded by a new element. Ie:

 <ul typeof="rdf:List">
   <li typeof="a:b" property="q:r">text 1</li>
   <li about="#b">text 2</li>
   ....
 </ul>

is transformed into:

 <ul about="_:a1" typeof="rdf:List">
   <div about="_:a1" rel="rdf:first"><li typeof="a:b" property="q:r">text 1</li></div>
   <li about="_:a1" rel="rdf:rest" resource="[_:a2]"/>
   <div about="_:a2" rel="rdf:first"><li about="#b">text 2</li></div>
   <li about="_:a2" typeof="rdf:List" rel="rdf:rest" resource="[rdf:nil]"/>
 </ul>

In both cases, the RDFa processing rules generate the right set of triples for RDF collections.


Requires: RDFLib package

Organization: World Wide Web Consortium

Author: Ivan Herman

License: This software is available for use under the W3C® SOFTWARE NOTICE AND LICENSE

Functions [hide private]
 
decorate_li_s(html, options)
The main transformer entry point.
source code
Variables [hide private]
  _NONE = 0
  _CONTAINER = 1
  _COLLECTION = 2
  __package__ = 'pyRdfa.transform'

Imports: random, _has_one_of_attributes, rdf_prefix, traverse_tree, dump


Function Details [hide private]

decorate_li_s(html, options)

source code 

The main transformer entry point. See the module description for details.

Parameters:
  • html - a DOM node for the top level html element
  • options (Options) - invocation options