arne-bdt commented on issue #2473:
URL: https://github.com/apache/jena/issues/2473#issuecomment-2118306695

   I think it is fair to say: All occurrences of the bare 
`parseType="Statements"` are due to sloppy implementations or copy-and-paste 
errors. The namespace should always be `rdf:parseType="Statements"`.
   
   Google discovered an old draft of the IEC standard  [Part 5xx: CIM XML Model 
Exchange 
Format](https://cimug.ucaiug.org/WG13/Part%20552%20CIM%20XML%20Model%20Exchange%20Format%20[Martin%20Miller]/Edition%201/57_1262e_CDV.pdf)
 . For example, on page 21, the RDF example lacks the namespace, but the text 
explicitly mentions the correct namespace.
   
   > Just for clarification with the namespace “dm” new statements are 
introduced that are valid
   extensions to the standard RDF syntax through the new property 
rdf:parseType, which is called
   Statements. 
   <property parseType=”Statements”>
      <!-- Content: (definition|description)* -->
   </property>
   The content model of an element with rdf:parseType=”Statements” is the same 
as the content
   model of the rdf:RDF element.
   
   Today I also discovered the [RDF Syntax User 
Guide](https://eepublicdownloads.entsoe.eu/clean-documents/CIM_documents/Grid_Model_CIM/RDF-SyntaxUserGuide_v1-0.pdf)
 listed on https://www.entsoe.eu/data/cim/cim-for-grid-models-exchange/, which 
contains a chapter "General differences between CIM XML (552) and RDF XML 
(W3C)". This chapter explains a lot right at the beginning:
   
   > The CIM XML is defined in the IEC 61970-552:2016. This version of the 
standard is based on
   a much earlier edition in which some serialization assumptions were made. 
Important: When 
   the initial version of IEC 61970-552 was developed, the W3C recommendations 
on RDF XML
   were not released. Therefore, there was a growing gap during the last two 
decades. The latest
   RDF XML was standardized by W3C in 2014 (RDF 1.1 XML Syntax (w3.org)) and 
IEC 61970-552 
   did not align with this due to existing implementations objecting changes in 
CIM XML.
   
   It lists many of the issues I've stumbled upon over the last few years. 
Unfortunately, the rdf:parseType="Statements" issue is missing from this 
chapter.
   
   There, I also found the latest [Metadata and Document Header Data Exchange 
Specification](https://www.entsoe.eu/Documents/CIM_documents/Grid_Model_CIM/MetadataAndHeaderDataExchangeSpecification_v2.3.0.pdf),
 which includes parts of the Difference Model Specification:
   
   > The content [of the DifferenceModel] is described by the Model class, the
   association role forwardDifferences and association role reverseDifferences. 
Both association
   roles may have one set of Statements.
   [chapter "7.3 (dm) DifferenceModel", page 33]
   
   Description for "forwardDifferences":
   > A property of the difference model whose value is a collection of 
statements (i.e., resources of type rdf:Statement) representing the forward 
difference statements.
   
   
   With Jena, I would want to be able to parse the forwardDifferences and 
backwardDifferences into separate graphs, so that I can apply them as additions 
and deletions, or use them in a `org.apache.jena.graph.compose.Delta`.
   
   Here is sample code to illustrate a way to read the forwardDifferences as a 
graph:
   
   ```
   String xml = "<rdf:RDF \n" +
           "    xml:base=\"http://iec.ch/TC57/2014/CIM-schema-cim16#\"\n"; +
           "    xmlns:dm=\"http://iec.ch/2002/schema/CIM_difference_model#\"; 
\n" +
           "    
xmlns:md=\"http://iec.ch/TC57/61970-552/ModelDescription/1#\"\n"; +
           "    xmlns:cim=\"http://iec.ch/TC57/2014/CIM-schema-cim16#\"\n"; +
           "    xmlns:meta=\"http://iec.ch/TC57/2014/CIM-schema-cim16#\"\n"; +
           "    xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\";>\n" +
           "<dm:DifferenceModel 
rdf:about=\"#_248c809d-1d7b-397c-830f-6928007ae6d9\">                \n" +
           "<md:Model.version>1715589426</md:Model.version>\n" +
           "<md:Model.created>2024-05-13T08:37:06.830Z</md:Model.created>\n" +
           
"<md:Model.scenarioTime>2024-05-13T08:37:06.830Z</md:Model.scenarioTime>\n" +
           "<md:Model.profile>http://profile/</md:Model.profile>\n" +
           
"<md:Model.modelingAuthoritySet>unknown</md:Model.modelingAuthoritySet>\n" +
           
"<meta:Model.modelVersionIri>http://ontology.adms.ru/UIP/md/2021-1</meta:Model.modelVersionIri>\n"
 +
           
"<meta:Model.differenceFrom>2024-04-01T07:55:06.779475Z</meta:Model.differenceFrom>\n"
 +
           
"<meta:Model.differenceTo>2027-10-01T08:37:06.779475Z</meta:Model.differenceTo>\n"
 +
           "<dm:forwardDifferences rdf:parseType=\"Statements\">\n" +
           "<cim:A rdf:about=\"#_individual-A-1\">\n" +
           "<cim:A-2-B rdf:resource=\"#_individual-B-1\"/>\n" +
           "</cim:A>\n" +
           "<cim:B rdf:about=\"#_individual-B-1\"/>\n" +
           "<cim:D rdf:about=\"#_individual-D-1\"/>\n" +
           "</dm:forwardDifferences>\n" +
           "<dm:reverseDifferences parseType=\"Statements\">\n" +
           "</dm:reverseDifferences>\n" +
           "</dm:DifferenceModel>\n" +
           "</rdf:RDF> ";
   
   
   Model res = ModelFactory.createDefaultModel();
   RDFParserBuilder
           .create()
           .fromString(xml)
           .forceLang(Lang.RDFXML)
           .build()
           .parse(res);
   
   RDFDataMgr.write(System.out, res, RDFFormat.JSONLD11_PRETTY);
   
   var subjDiffModel = 
NodeFactory.createURI("http://iec.ch/TC57/2014/CIM-schema-cim16#_248c809d-1d7b-397c-830f-6928007ae6d9";);
   var predForwardDifferences = 
NodeFactory.createURI("http://iec.ch/2002/schema/CIM_difference_model#forwardDifferences";);
   //get the forward differences
   var objForwardDifferences = res.getGraph().find(subjDiffModel, 
predForwardDifferences, Node.ANY).next().getObject();
   
   //create a new RDF/XML graph
   var forwardRDF = "<rdf:RDF \n" +
           "    xml:base=\"http://iec.ch/TC57/2014/CIM-schema-cim16#\"\n"; +
           "    xmlns:dm=\"http://iec.ch/2002/schema/CIM_difference_model#\"; 
\n" +
           "    
xmlns:md=\"http://iec.ch/TC57/61970-552/ModelDescription/1#\"\n"; +
           "    xmlns:cim=\"http://iec.ch/TC57/2014/CIM-schema-cim16#\"\n"; +
           "    xmlns:meta=\"http://iec.ch/TC57/2014/CIM-schema-cim16#\"\n"; +
           "    xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\";>\n" +
           objForwardDifferences.getLiteralLexicalForm() +
           "</rdf:RDF>";
   
   var forwardGraph = GraphFactory.createGraphMem();
   forwardGraph.getPrefixMapping().setNsPrefixes(res.getNsPrefixMap());
   RDFParserBuilder
           .create()
           .fromString(forwardRDF)
           .forceLang(Lang.RDFXML)
           .build()
           .parse(forwardGraph);
   
   
   RDFDataMgr.write(System.out, forwardGraph, RDFFormat.JSONLD11_PRETTY);
   ```
   This process is not pretty, and writing DifferenceModels might even be 
uglier.
   
   Accepting `rdf:parseType="Statements"` seems to be a good compromise to 
ensure that Jena is regarded as a stable component in any CIM/XML tool chain. 
   
   ### Next Steps ?
   I would like to approach ENTSO-E so that they may extend their chapter 
"General differences between CIM XML (552) and RDF XML (W3C)." Proposing the 
use of rdf:parseType="Literal" to improve general compatibility with RDF/XML 
could be one suggestion. However, does anyone have a good idea on how to 
express DifferenceModels with nested graphs for forwardDifferences and 
backwardDifferences in RDF/XML? (My knowledge of the standards and parsers is 
not sufficient to devise a practical solution.)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to