1

I am experimenting with converting RDF to another format (JSON-LD in this case, via RDFLib) and back to RDF. The resulting RDF is a tad different from the original, and although as a human both kinda make sense, I do wonder if they are actually semantically exactly the same.

Are the 2 following snippets interchangeable in RDF?

Original:

<cim:Substation rdf:ID="_1234">
    <cim:IdentifiedObject.name>A substation</cim:IdentifiedObject.name>
</cim:Substation>

The back and forth converted snippet:

<rdf:Description rdf:about="_1234">
    <rdf:type rdf:resource="cim:Substation"/>
    <cim:IdentifiedObject.name>A substation</cim:IdentifiedObject.name>
</rdf:Description>

Guillaume
  • 2,325
  • 2
  • 22
  • 40

1 Answers1

2

No, these two snippets are definitely not equivalent. This can be verified by using a converter (such as this one), and choosing a more basic RDF serialization format, such as N-Triples.

Input:

<?xml version="1.0"?>
<rdf:RDF xml:base="example:base/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cim="example:cim#">
    <cim:Substation rdf:ID="_1234">
        <cim:IdentifiedObject.name>A substation</cim:IdentifiedObject.name>
    </cim:Substation>
</rdf:RDF>

Output:

<example:base/#_1234> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <example:cim#Substation> .
<example:base/#_1234> <example:cim#IdentifiedObject.name> "A substation" .

Input:

<?xml version="1.0"?>
<rdf:RDF xml:base="example:base/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cim="example:cim#">
    <rdf:Description rdf:about="_1234">
        <rdf:type rdf:resource="cim:Substation"/>
        <cim:IdentifiedObject.name>A substation</cim:IdentifiedObject.name>
    </rdf:Description>
</rdf:RDF>

Output:

<example:base/_1234> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <cim:Substation> .
<example:base/_1234> <example:cim#IdentifiedObject.name> "A substation" .

There are two differences in these two snippets:

  • rdf:ID="name" is (more or less) an abbreviation of rdf:about="#name" (notice the #). If you care about the document using stable URIs for its resources, using rdf:about="name" will produce different URIs, as you can see from the N-Triples output ‒ one has example:base/#_1234 and the other has example:base/_1234. The only situation where this might be equivalent is if the parser/formatter chose a different XML base for the second snippet (e.g. example:base# as opposed to example:base), and interpreted the absolute URI formation of example:base#+_1234 as example:base#_1234, which is nevertheless incorrect, as example:base#+_1234 is example:_1234.
  • The usage of cim:Substation as an XML element name is not resolved in the same way as the value of rdf:resource. In the former case, the XML namespace is used and concatenated with the element's local name (resulting in example:cim#Substation), while in the latter case, it is simply treated as a plain URI. This would be equivalent only if the prefix cim: is supposed to denote the namespace cim: (i.e. having xmlns:cim="cim:" in the original snippet) which it might not.
IS4
  • 11,945
  • 2
  • 47
  • 86