这两个 RDF/XML 片段在语义上等价吗?

huangapple go评论57阅读模式
英文:

Are those 2 RDF/XML snippets semantically equivalent?

问题

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>
英文:

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>

答案1

得分: 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.
英文:

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.

huangapple
  • 本文由 发表于 2023年5月11日 15:17:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76225002.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定