phamcong / rdfquery

Automatically exported from code.google.com/p/rdfquery
0 stars 0 forks source link

Expose RDFa Parser In API #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Describe the feature that you're after and why it's important.

RDFa is richer then RDF - RDFa has context within the markup. This is
valuable and should be accessible from an RDFa library.

Illustrate how you'd like to see it work, with code samples.

$("body").rdfa(function(counter, node, triple) {
  dump("The " + counter + " triple found is " + triple
    + " It was found on a " + node.tagName + " tag.")
})

The second argument in the callback is the last node that contained the
object or predicate of the triple in an attribute.

Original issue reported on code.google.com by james-no...@leighnet.ca on 21 Sep 2009 at 7:45

GoogleCodeExporter commented 9 years ago
The attached file is an adequate solution.

Original comment by james-no...@leighnet.ca on 21 Sep 2009 at 11:23

Attachments:

GoogleCodeExporter commented 9 years ago
The HTML element from which a triple was generated is captured within the 
.source property, so you can 
currently do:

$('body').rdf()
  .databank
  .triples()
  .each(function (counter) {
    var triple = this,
      node = this.source;
    dump("The " + counter + " triple found is " + triple + " It was found on a " + node[0].tagName + " tag.");
  })

although it won't necessarily give you the triples in the original order (not 
that that RDFa parsing is 
necessarily deterministic anyway). Is that sufficient for your requirement, or 
do you think having a callback 
has particular advantages?

(When you submit patches, it would be really helpful if you did so on the 
individual files that you get from 
trunk rather than the packaged Javascript. It would make them easier to 
integrate.)

Original comment by jeni.ten...@gmail.com on 22 Sep 2009 at 8:19

GoogleCodeExporter commented 9 years ago
In my case the order is important. I am building a SPARQL CONSTRUCT query based 
on an
RDFa template. Because of nested OPTIONAL clauses I need the structure of the 
WHERE
clause to match the structure of the HTML nodes. Therefore the nodes must be 
sorted
based on parent/child relationships (as they are in HTML).

I can rewrite the patch for the source file if you are planning on applying it 
to
trunk (it's fairly simple).

Original comment by james-no...@leighnet.ca on 22 Sep 2009 at 11:57

GoogleCodeExporter commented 9 years ago
OK. I'm happy to add a callback, but we need to thrash out a bit what it should 
look like. I think that $.rdf() 
should still return an rdfQuery object, whether you have a callback or not, so 
I'm not going to do it in 
precisely the same way as you suggest; you'll get the callbacks but also get 
something you can query.

You ask for the callback to get a counter, but the patch that you gave doesn't 
seem to provide that facility. Is 
that because it's something you thought of later but don't actually need? I 
think that the only counter it would 
be able to provide would be from a depth-first search of the information. Is 
that going to be helpful to you 
(as opposed to a breadth-first traversal)?

Also, with the way the gleaners work, you would also get a bunch of callbacks 
from each gleaner's traversal of 
the document, one after the other. Either each gleaner could restart the 
counter, or it could continue counting 
from the previous gleaner. But it does mean that just because one counter is 
greater than another, it doesn't 
mean that the one triple comes from later in the document than the other.

BTW, are you using http://spinrdf.org/sp.html or something similar to express 
the SPARQL query using RDFa? 
Can't you query over the RDFa to construct the query based on the explicit, 
RDFa-encoded, relationships of 
the resources to each other? Maybe I'm misunderstanding what you're doing.

Original comment by jeni.ten...@gmail.com on 22 Sep 2009 at 1:51

GoogleCodeExporter commented 9 years ago
I don't need a counter myself, I added in the description to follow the
jQuery.rdf.each callback parameters.

In the patch, I didn't return anything from $.rdf(callback) to avoid unnecessary
processing.

I am not using spinrdf. The query building could be described as a way to 
answer the
question "what resources are like this.." The resulting query will find 
resources
that have similar relationships as what is in the RDFa. The challenge is that 
each
nested node is optional. I can't just recreated the structure using RDF because 
the
rev vs rel direction is lost once it is converted to RDF.

Original comment by james-no...@leighnet.ca on 22 Sep 2009 at 2:15

GoogleCodeExporter commented 9 years ago
In r175, I added a callback on $.fn.rdf() that is called on each gleaned triple 
and takes two arguments: the triple 
and the node on which the triple is found. Within the callback function 'this' 
is set to the triple itself. The value 
returned by the function should usually be the triple itself, but you can use 
the callback to filter out the triple 
(by not returning anything from the function), modifying it, or adding to it 
(by having the function return an array 
of triples).

I think this is a really nice improvement to the flexibility of rdfQuery; thank 
you for suggesting it James.

Original comment by jeni.ten...@gmail.com on 26 Sep 2009 at 7:24