RDFa DOM API: Adding RDF triples to the DOM

Hi

I was thinking about new methods for adding RDF triples in the new RDFa 
DOM API.
As code example I took the example from Use Case #2 at
http://www.w3.org/TR/xhtml-rdfa-scenarios/#use-case-2:

<div id="www2007_talk">
    <h2>My WWW2007 Talk</h2>
    a post by Paul.
    <p>
        I'm giving a talk at the WWW2007 Conference about structured 
blogging,
    on the second day of the conference at 10. This will be one of my
    <a href="technical">more technical talks</a>.
    </p>
</div>

desired RDF triples are:

@prefix cal: <http://www.w3.org/2002/12/cal/ical#>
@prefix dc: <http://purl.org/dc/elements/1.1/>
@prefix paul: <http://example.org/Paul/ns#>

<#www2007_talk> a cal:Vevent ;
                dc:title "My WWW2007 Talk" ;
                dc:creator "Paul" ;
                cal:summary "structured blogging" ;
                cal:dtstart "20070509T1000-0800" ;
                paul:audience <technical> .

Three API cases came to my mind:
1. Add single RDFa markup to single DOM elements.
2. Add chaining RDFa markup to a DOM subtree.
3. Add single RDFa markup to a literal phrase pattern.


Let's begin with the first one.

1. Add single RDFa markup to single DOM elements.

I tried to add the desired triples by just modifying single DOM elements at
once.

<div id="www2007_talk">
     <h2     about="www2007_talk"
        property="dc:title"
        typeof="cal:Vevent">
My WWW2007 Talk</h2>
    a post by Paul.
   <p about="www2007_talk" property="cal:dtstart" 
content="20070509T1000-0800">
        I'm giving a talk at the WWW2007 Conference about structured 
blogging,
    on the second day of the conference at 10. This will be one of my
    <a     href="technical" 
        about="www2007_talk"
        rel="paul:audience"
        resource="technical" >more technical talks</a>.
  </p>
</div>

This might be solved by extending the DOM API methods as follows:

interface Element {
Triple    addTriple(
        in DOMString? about,
        in DOMString? rel,
        in DOMString? resource)
 
Triple    addTriple(
        in DOMString? about,
        in DOMString? property,
        in DOMString? object,
        in DOMString? datatype)
}

You might have recognized that I could not markup neither the literals 
"Paul"
nor "structured blogging" with triples. There are no DOM elements to attach
these triples.

2. Add chaining RDFa markup to a DOM subtree.

Again I tried to attach all triples, but this time I used RDFa's 
chaining. This
will produce less data as I can add about="www2007_talk" to the root node of
this subtree.

<div id="www2007_talk" about="www2007_talk">
     <h2     property="dc:title"
        typeof="cal:Vevent">
My WWW2007 Talk</h2>
    a post by Paul.
   <p property="cal:dtstart" content="20070509T1000-0800">
        I'm giving a talk at the WWW2007 Conference about structured 
blogging,
    on the second day of the conference at 10. This will be one of my
    <a     href="technical" 
        rel="paul:audience"
        resource="technical" >more technical talks</a>.
  </p>
</div>

This might be solved by modifying the upper DOM API method extension with


interface Element {

/*
* If about, rel, and resource are null nothing happens.
*/
Triple    addTriple(
        in optional DOMString? about,
        in optional DOMString? rel,
        in optional DOMString? resource)

/*
* If about, rel, and resource are null nothing happens.
*/
Triple    addTriple(
        in optional DOMString? about,
        in optional DOMString? property,
        in optional DOMString? object,
        in optional DOMString? datatype)
 
Triple    addSubject(in DOMString? subject)
Triple    addRelation(in DOMString? predicate)
Triple    addProperty(in DOMString? predicate)
Triple    addResource(in DOMString? object)
Triple    addRDFLiteral(
        in DOMString? object,
        in optional DOMString? datatype)
}

The developer now has to call these method several times in order to 
annotate
each node correctly. This is really annoying. A good API should be 
simpler and
hide chaining to the programmer.

A better approach would be extending DocumentFragment as this intends to 
be a
DOM subtree.

interface DocumentFragment {

/**
* The about attribute will be added the DocumentFragment's root node.
* Whenever in descendants of DocumentFragment the resource value matches
* an existing about, href, or src attribute, the current node will be 
annotated
* with the rel attribute. If no matches occur, the DocumentFragment's 
root node
* is annotated.
**/
Triple    addTriple(
        in DOMString? about,
        in DOMString? rel,
        in DOMString? resource)

/**
* The about attribute will be added the DocumentFragment's root node.
* Whenever in descendants of DocumentFragment the literal value matches
* an existing text node, the current node will be annotated
* with the property attribute. If no matches occur, the 
DocumentFragment's root
* node is annotated.
**/
Triple    addTriple(
        in DOMString? about,
        in DOMString? property,
        in DOMString? literal,
        in optional DOMString? datatype)

}


Again I could not markup "Paul" and "structured blogging" for the same 
reason
as in case one.

3. Add single RDFa markup to a literal phrase pattern.

Now lets give the substrings "Paul" and "structured blogging" RDFa markup.

<div id="www2007_talk" about="www2007_talk">
     <h2     property="dc:title"
        typeof="cal:Vevent">
My WWW2007 Talk</h2>
    a post by <span rel="dc:creator" resource="Paul">Paul<span>.
   <p property="cal:dtstart" content="20070509T1000-0800">
        I'm giving a talk at the WWW2007 Conference about <span
property="cal:summary">structured blogging</span>,
    on the second day of the conference at 10. This will be one of my
    <a     href="technical" 
        rel="paul:audience"
        resource="technical">more technical talks</a>.
  </p>
</div>

interface DocumentFragment {

/**
* The about attribute will be added the DocumentFragment's root node.
* Whenever in text nodes of descendants of DocumentFragment the regexPattern
* value matches, the current node's C parent P will get a new text node as
* child that contains the original text value before the match. Then P will
* get a new node of type nodetype or SPAN as default. This new node 
element is
* annotated with attributes property and datatype. As text value it gets the
* string match. At last the string after the match will be attached as new
* child to P. C will be deleted. If no match happens, nothing happens.
**/
Triple    addTripleForPattern(
        in optional DOMString? about,
        in DOMString? property,
        in DOMString? regexPattern,
        in optional DOMString? nodetype,
        in optional DOMString? datatype)
}

I know this is difficult to implement. But it is a very powerful method
encouraging developers to automatically link keywords to e.g., Linked 
Data URIs.
In Epiphany[1], we make use of such a method do do exactly this.

So now I am ready for comments :).

[1]http://projects.dfki.uni-kl.de/epiphany/


-- 
__________________________________________
Benjamin Adrian
Email : benjamin.adrian@dfki.de
WWW : http://www.dfki.uni-kl.de/~adrian/
Tel.: +49631 20575 145
__________________________________________
Deutsches Forschungszentrum für Künstliche Intelligenz GmbH
Firmensitz: Trippstadter Straße 122, D-67663 Kaiserslautern
Geschäftsführung:
Prof. Dr. Dr. h.c. mult. Wolfgang Wahlster (Vorsitzender) Dr. Walter Olthoff
Vorsitzender des Aufsichtsrats:
Prof. Dr. h.c. Hans A. Aukes
Amtsgericht Kaiserslautern, HRB 2313
__________________________________________

Received on Tuesday, 23 February 2010 16:10:54 UTC