Re: Reproducing Gregg/Niklas' thoughts (@itemref issue) (ISSUE-144)

The Python implementation I posted takes care of this. This expands
the prototype on the referrers:

    for s, proto in graph.subject_objects(RDFA.ref):
        if (proto, RDF.type, RDFA.Prototype) in graph:
            for p, o in graph.predicate_objects(proto):
                if (p, o) != (RDF.type, RDFA.Prototype):
                    graph.add((s, p, o))

Then this (the optional part) removes the prototype itself:

    for s, proto in graph.subject_objects(RDFA.ref):
        graph.remove((s, RDFA.ref, proto))
        if (proto, RDF.type, RDFA.Prototype) in graph:
            graph.remove((proto, None, None))

I have run this code against examples, so it works.

Here is a SPARQL construct which achieves the same result by building
a new graph:

    prefix : <http://www.w3.org/ns/rdfa#>

    construct { ?s ?p ?o } where {
      {
        ?s ?p ?o
        filter(?p != :ref)
        filter not exists { ?s a :Prototype }
      } union {
        ?s :ref ?proto .
        ?proto a :Prototype; ?p ?o .
        filter(?p != rdf:type && ?o != :Prototype)
      }
    }

I have tested this with Sesame, and with the RDFLib SPARQL 1.1 Python
implementation (see [1] for how to run this locally).

Best regards,
Niklas

[1]: https://github.com/niklasl/rdf-sparql-lab#usage


On Sat, Dec 8, 2012 at 3:28 PM, Ivan Herman <ivan@w3.org> wrote:
>
> On Dec 7, 2012, at 18:59 , Gregg Kellogg wrote:
>
>> On Dec 7, 2012, at 3:46 PM, Ivan Herman <ivan@w3.org> wrote:
>>
>>>
>>> On 7 Dec 2012, at 17:12, Gregg Kellogg <gregg@greggkellogg.net> wrote:
>>>
>>>> I added experimental support to my parser (will deploy to distiller later) as part of vocabulary expansion.
>>>
>>> Kudos! But does it mean that I have to switch vocab expansion on to get this, or does this happen automatically?
>>
>> Turn on expansion, mostly because this is just experimental. It could be made the default action easily enough, but right now it's just coupled with the expansion rules.
>
> Right. The question is really how we would define it for processors. At this point we can only _require_ it for HTML5 processors of course.
>
>>
>>>> I pretty much implement Ivan's algorithm as part of RDFa vocabulary expansion, with the following difference:
>>>>
>>>> I modified the DELETE clause to remove the rdfa:Prototype on the subject resource as well:
>>>>
>>>> DELETE DATA {
>>>> ?x rdfa:ref ?PR .
>>>> ?x rdf:type rdfa:Prototype .
>>>> ?PR ?p ?y .
>>>> }
>>>>
>>>
>>> I am not sure understand. Shouldn't be ?PR rdf:type rdfa:Prototype ? And I am not sure it it is good to remove that, because the prototype triples are also present in the output graph, and it is good to keep this typing as an 'annotation'...
>>
>> No, without this rule, then ?x also gets type rdfa:Prototype, which doesn't make sense.
>
> Ah! Right. I think the equivalent, but, for communication purposes, clearer is to write down the rules as:
>
> INSERT DATA {
>   ?x ?p ?y .
> }
> DELETE DATA {
>   ?x rdfa:ref ?PR .
>   ?PR ?p ?y .
>   ?PR rdf:type rdfa:Prototype .
> }
> WHERE {
>   ?x rdfa:ref ?PR .
>   ?PR ?p ?y.
>   FILTER ( !(?p = rdf:type && ?y = rdfa:Prototype) )
>   ?PR a rdfa:Prototype .
> }
>
> Actually, this may not be fine. I am not aware of the details of SPARQL UPDATE, but, operationally, doing it this way would remove the rdfa:Prototype too early, so to say, ie, it would create problems if the same prototype is used twice. Ie, I would probably define this as two rules, to be executed one after the other (note that I made a syntactic error SPARQL -wise, in my previous format):
>
> INSERT {
>   ?x ?p ?y .
> }
> DELETE {
>   ?x rdfa:ref ?PR .
>   ?PR ?p ?y .
>   ?PR rdf:type rdfa:Prototype .
> }
> WHERE {
>   ?x rdfa:ref ?PR .
>   ?PR ?p ?y.
>   FILTER ( !(?p = rdf:type && ?y = rdfa:Prototype) )
>   ?PR a rdfa:Prototype .
> }
> ;
> DELETE WHERE {
>   ?x rdfa:type rdfa:Prototype .
> }
>
> I am actually not sure that your simple modification of the DELETE covers this case, I did not really checked...
>
>
>> The ?PR rdf:type rdfa:Prototype isn't necessary, as it's covered by ?PR ?p ?y.  Without this rule, the result of the first example would look like:
>>
>>        @prefix schema: <http://schema.org/> .
>>        [a schema:Person, rdfa:Prototype; schema:name "Amanda"] .
>>
>>>> Here are some example tests, based on those used by the Microdata RDF note:
>>>
>>> In all those examples, the prototype triples should also be present, shouldn't they?
>>
>> No, the DELETE DATA { ?PR ?p ?y } removes them.
>
> Ah, silly me. That is true. _Except_ the pathological case when one defines a prototype without really using it. In which case, hm, my second rule would probably be harmful, because it is better to keep the whole structure in its original form; ie, it should be applied only in case there was any change on the graph.
>
> Ivan
>

Received on Saturday, 8 December 2012 18:12:38 UTC