英文:
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 ofrdf:about="#name"(notice the#). If you care about the document using stable URIs for its resources, usingrdf:about="name"will produce different URIs, as you can see from the N-Triples output ‒ one hasexample:base/#_1234and the other hasexample: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 toexample:base), and interpreted the absolute URI formation ofexample:base#+_1234asexample:base#_1234, which is nevertheless incorrect, asexample:base#+_1234isexample:_1234.- The usage of
cim:Substationas an XML element name is not resolved in the same way as the value ofrdf:resource. In the former case, the XML namespace is used and concatenated with the element's local name (resulting inexample:cim#Substation), while in the latter case, it is simply treated as a plain URI. This would be equivalent only if the prefixcim:is supposed to denote the namespacecim:(i.e. havingxmlns: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 ofrdf:about="#name"(notice the#). If you care about the document using stable URIs for its resources, usingrdf:about="name"will produce different URIs, as you can see from the N-Triples output ‒ one hasexample:base/#_1234and the other hasexample: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 toexample:base), and interpreted the absolute URI formation ofexample:base#+_1234asexample:base#_1234, which is nevertheless incorrect, asexample:base#+_1234isexample:_1234. -
The usage of
cim:Substationas an XML element name is not resolved in the same way as the value ofrdf:resource. In the former case, the XML namespace is used and concatenated with the element's local name (resulting inexample:cim#Substation), while in the latter case, it is simply treated as a plain URI. This would be equivalent only if the prefixcim:is supposed to denote the namespacecim:(i.e. havingxmlns:cim="cim:"in the original snippet) which it might not.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论