w3c / rdf-star

RDF-star specification
https://w3c.github.io/rdf-star/
Other
119 stars 23 forks source link

RDF/XML interpretation as RDF-Star #160

Open JervenBolleman opened 3 years ago

JervenBolleman commented 3 years ago

I was wondering if we could have an rdf-star interpretation of reifying shorthand in RDF/XML.

Where the contents of the rdf:ID field can be disregarded and it's uses to be a "temporary name" for an asserted and embedded triple.

gkellogg commented 3 years ago

I looked into this, and it's a bit more complicate with RDF/XML. The rdf:ID attribute can be used on either Node Elements or Property Elements.

On Node elements, it creates a subject based on a fragment identifier in the main document, so that ID="foo" is pretty much the same as about="#foo".

On Property elements, it is the identifier of the reified statement composed of the established subject, the property identified by the element, and the object value.

Because a statement using the same identifier as a subject can be separate from the use of that identifier for the reified statement, to get the same affect as Turtle-star, you'd need to post-process the resulting graph in order to eliminate the use of the fragment identifier as a subject or object of some other statement. Easiest would be to replace the reification with an owl:sameAs to link the fragment to an embedded triple.

For example, consider the following:

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:ex="http://example.org/"
            xml:base="http://example.org/">
  <rdf:Description rdf:about='http://example.org/employee38'>
    <ex:familyName>Smith</ex:familyName>
    <ex:jobTitle rdf:ID="stmt">Assistant Designer</ex:jobTitle>
  </rdf:Description>
  <rdf:Description rdf:ID="stmt">
    <ex:accordingTo rdf:resource='http://example.org/employee22'/>
  </rdf:Description>
</rdf:RDF>

This might be represented by Turtle-star as in example 2:

@prefix :    <http://www.example.org/> .

:employee38
    :familyName "Smith" ;
    :jobTitle "Assistant Designer" {| :accordingTo :employee22 |} .

To get the same affect by parsing RDF/XML-star, you'd need to separately connect the use of "smnt" to identify the reified statement and to describe the accordingTo statement. Because they can be separated in space (and may not be used at all), it becomes a post-processing problem.

Instead, we could consider retaining "stmt" and creating an owl:sameAs equivalence:

@prefix :    <http://www.example.org/> .

:employee38
    :familyName "Smith" ;
    :jobTitle "Assistant Designer" .

:stmt owl:sameAs <<:employee38 :jobTitle "Assistant Designer">>;
  :accordingTo :employee22 .

This would reasonably preserve the semantics, but doesn't really create an equivalence with Turtle-star or the others.

ericprud commented 3 years ago
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:ex="http://example.org/"
            xml:base="http://example.org/">
  <rdf:Description rdf:about='http://example.org/employee38'>
    <ex:familyName>Smith</ex:familyName>
    <ex:jobTitle rdf:ID="stmt">Assistant Designer</ex:jobTitle>
  </rdf:Description>
  <rdf:Description rdf:ID="stmt">
    <ex:jobTitle>Assistant Designer</ex:jobTitle>
  </rdf:Description>
</rdf:RDF>

Did you intend the second rdf:Description to be:?

  <rdf:Description rdf:ID="stmt">
    <ex:accordingTo rdf:resource='http://example.org/employee22'/>
  </rdf:Description>
gkellogg commented 3 years ago

Did you intend the second rdf:Description to be:?

  <rdf:Description rdf:ID="stmt">
    <ex:accordingTo rdf:resource='http://example.org/employee22'/>
  </rdf:Description>

Yes, indeed. Transcription error.

pchampin commented 2 years ago

I do believe that this issue is actually not specific to RDF/XML. Regardless of the concrete syntax, one might be interested to "convert" an RDF graph using standard reification. @JervenBolleman would you agree?

Since reification is referentially transparent and allows multiple occurrences of the same statement, such a solution would rely on a standard vocabulary for occurrences (#169) and transparency-enabling properties (#209).

ericprud commented 2 years ago

None of the other syntaxes (Turtle, trig...) gave you a way to make a statement and gave you a way to annotate it (the rdf:ID="stmt" above). The orig RDF/XML syntax implies a connection between the triple and its reification. Was RDF/XML was decades ahead of its time?

Bub none of this utility survived the expression as triples 'cause triples aren't property graphs. Specifically, mere triples can't connect the reification back to the orig statement so the above example expresses a direct and a reified form of the statement.

ex:employee38   ex:familyName   "Smith" .
ex:employee38   ex:jobTitle "Assistant Designer" . # reified in <#stmt>
<#stmt>     a       rdf:Statement .
<#stmt>     rdf:object  "Assistant Designer" .
<#stmt>     rdf:predicate   ex:jobTitle .
<#stmt>     rdf:subject ex:employee38 .
<#stmt>     ex:accordingTo  <http://example.org/employee22> . # †

† for some reason, the precious annotation doesn't show up in the RDF Validator. Maybe that's what

Each (rdf:ID attribute value, base URI) pair has to be unique in an RDF/XML document, see constraint-id.

is trying to tell me.

The reified form is implied by the rdf:ID="stmt"; without it, you just get:

ex:employee38   ex:familyName   "Smith" .
ex:employee38   ex:jobTitle "Assistant Designer" . # reified in <#stmt>
<#stmt>     ex:accordingTo  <http://example.org/employee22> .

So I'm not saying that RDF/XML currently supports annotations; I'm saying that the syntax kind of implies it so it makes sense to leverage that syntax in the RDF-Star version of RDF/XML.

pchampin commented 2 years ago

FTR, a version of the RDF/XML example above that is accepted by the W3C RDF validator (replacing the 2nd rdf:ID with an equivalent rdf:about):

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:ex="http://example.org/"
            xml:base="http://example.org/">
  <rdf:Description rdf:about='http://example.org/employee38'>
    <ex:familyName>Smith</ex:familyName>
    <ex:jobTitle rdf:ID="stmt">Assistant Designer</ex:jobTitle>
  </rdf:Description>
  <rdf:Description rdf:about="#stmt">
    <ex:accordingTo rdf:resource='http://example.org/employee22'/>
  </rdf:Description>
</rdf:RDF>
pchampin commented 2 years ago

@ericprud

None of the other syntaxes (Turtle, trig...) gave you a way to make a statement and gave you a way to annotate it (the rdf:ID="stmt" above).

That's true, and that maybe why standard reification is more appealing to RDF/XML users than to Turtle users. But we don't want to change the semantics of RDF/XML, do we? And if we don't, then "an rdf-star interpretation of reifying shorthand in RDF/XML" (as suggested by @JervenBolleman) will be handled at the triple level, so independently of the concrete syntax... At least that's how I see it.

Granted, we could add a "flag" in RDF/XML, for example:

<rdf:RDF rdf:star="true">
...

that would indicate that the parser should do the post-processing of reification triples into RDF-star. But that post-processing could still be defined at the triple level and applied to any RDF graph, regardless of how it was serialized.

ericprud commented 2 years ago

I think a generic, triples-based translation would only leverage RDF/XML's syntactic (reification) constructs if it mapped:

ex:employee38   ex:familyName   "Smith" .
ex:employee38   ex:jobTitle "Assistant Designer" . # reified in <#stmt>
<#stmt>     a       rdf:Statement .
<#stmt>     rdf:object  "Assistant Designer" .
<#stmt>     rdf:predicate   ex:jobTitle .
<#stmt>     rdf:subject ex:employee38 .
<#stmt>     ex:accordingTo  <http://example.org/employee22> .

to:

ex:employee38   ex:familyName   "Smith" .
ex:employee38   ex:jobTitle "Assistant Designer" . # reified in <#stmt>
<#stmt>     ex:accordingTo  <http://example.org/employee22> .

. Having your RDF library do that automatically could alter the graph when it wasn't the user's intention; your rdf:star="true" could capture such an intention. (I'm not really fussed about that alteration but more conservative guardians of the semantics may be.)

afs commented 2 years ago

Like https://github.com/apache/jena/blob/main/jena-arq/src/main/java/org/apache/jena/system/RDFStar.java ?

ericprud commented 2 years ago

going by the javadoc, exactly!

btw, I PR'd to propose new names for this no-longer-hypothetical operation: RDFStar.encodeAsRDF and RDFStar.decodeFromRDF.