W3C home > Mailing lists > Public > public-rdfa-wg@w3.org > February 2010

Re: RDFa DOM API: Adding RDF triples to the DOM

From: Ivan Herman <ivan@w3.org>
Date: Wed, 24 Feb 2010 19:04:57 +0100
Message-ID: <4B856A49.4040901@w3.org>
To: benjamin.adrian@dfki.de
CC: RDFa WG <public-rdfa-wg@w3.org>
My first reaction was: hm:-)

This 'hm' has two distinct reasons

- Regardless of the options you have below: I have the impression that
the majority of usage for the RDFa API is on _reading_ (a.k.a.
accessing) the triples extracted from an RDFa file, rather than adding
triples to it. If this is true (and I may be wrong!) than I would first
like to have a clear idea on how that is done, optimize the interface
for that usage and look at writing the triples after that. The reading
part may dictate a 'style' of interface that might affect the writing
part. I know I am vague but maybe you understand what I mean...

- I am trying to be simple. I really believe that version 3 below is too
complicated both of the implementer (thought that may be secondary) as
well as for the user. Your version 1 is of course deadly simple and the
application may have to modify the DOM tree explicitly to add the
information (your 'summary' in the example) but I am not sure that is
bad. And that may also be a good example where the writing part and the
reading part mutually influence one another: will, for example, the
subject chaining appear in the read part? Or will the interface simply
return a triple for each node and that is it (ie, all the complication
on the chaining is hidden to the user)? Because if the latter, than we
should stick to your alternative a.

Now it is your turn to be unhappy with me:-)

Cheers

Ivan

On 2010-2-23 17:10 , Benjamin Adrian wrote:
> 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/
> 
> 

-- 

Ivan Herman, W3C Semantic Web Activity Lead
Home: http://www.w3.org/People/Ivan/
mobile: +31-641044153
PGP Key: http://www.ivan-herman.net/pgpkey.html
FOAF   : http://www.ivan-herman.net/foaf.rdf
vCard  : http://www.ivan-herman.net/HermanIvan.vcf


Received on Wednesday, 24 February 2010 18:05:16 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:05:16 UTC