Skip to content

Commit 9cef63f

Browse files
committed
This commit includes:
- bug fixes related to RDF comparison - enhancing RDFS to SHACL by including base profiles of different CIM versions - bug fixes related to xml generation from xls template - code clean up
1 parent f4541ce commit 9cef63f

File tree

15 files changed

+729
-1064
lines changed

15 files changed

+729
-1064
lines changed

dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>eu.griddigit</groupId>
55
<artifactId>CimPal</artifactId>
6-
<version>2023.2</version>
6+
<version>2023.3</version>
77
<build>
88
<finalName>CimPal</finalName>
99
<plugins>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>eu.griddigit</groupId>
1414
<artifactId>CimPal</artifactId>
15-
<version>2023.2</version>
15+
<version>2023.3</version>
1616

1717

1818
<build>

src/main/java/application/MainController.java

Lines changed: 304 additions & 253 deletions
Large diffs are not rendered by default.

src/main/java/core/ComparisonSHACLshapes.java

Lines changed: 11 additions & 564 deletions
Large diffs are not rendered by default.

src/main/java/core/DataTypeMaping.java

Lines changed: 96 additions & 118 deletions
Large diffs are not rendered by default.

src/main/java/core/ModelManipulationFactory.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,22 @@ public static void generateDataFromXls(String xmlBase, Boolean profileModelUnion
167167

168168

169169
switch (propertyType) {
170-
case "Attribute": //add literal
170+
case "Attribute" -> { //add literal
171171
if (rdfid.startsWith("urn:uuid:")) {
172-
model.add(ResourceFactory.createStatement(ResourceFactory.createResource(rdfid), ResourceFactory.createProperty(propertyURI), ResourceFactory.createPlainLiteral(object)));
172+
if (object.contains("LangXMLTag:")) {
173+
model.add(ResourceFactory.createStatement(ResourceFactory.createResource(rdfid), ResourceFactory.createProperty(propertyURI), ResourceFactory.createLangLiteral(object.split("LangXMLTag:", 2)[0], object.split("LangXMLTag:", 2)[1])));
174+
} else {
175+
model.add(ResourceFactory.createStatement(ResourceFactory.createResource(rdfid), ResourceFactory.createProperty(propertyURI), ResourceFactory.createPlainLiteral(object)));
176+
}
173177
} else {
174178
if (rdfid.startsWith("http://")) {
175179
model.add(ResourceFactory.createStatement(ResourceFactory.createResource(rdfid), ResourceFactory.createProperty(propertyURI), ResourceFactory.createPlainLiteral(object)));
176180
} else {
177181
model.add(ResourceFactory.createStatement(ResourceFactory.createResource(classNS + rdfid), ResourceFactory.createProperty(propertyURI), ResourceFactory.createPlainLiteral(object)));
178182
}
179183
}
180-
break;
181-
case "Association": //add resource
184+
}
185+
case "Association" -> { //add resource
182186
if (rdfid.startsWith("urn:uuid:")) {
183187
model.add(ResourceFactory.createStatement(ResourceFactory.createResource(rdfid), ResourceFactory.createProperty(propertyURI), ResourceFactory.createProperty(object)));
184188
} else {
@@ -188,10 +192,9 @@ public static void generateDataFromXls(String xmlBase, Boolean profileModelUnion
188192
model.add(ResourceFactory.createStatement(ResourceFactory.createResource(classNS + rdfid), ResourceFactory.createProperty(propertyURI), ResourceFactory.createProperty(object)));
189193
}
190194
}
191-
break;
192-
case "Enumeration": //add enum
193-
model.add(ResourceFactory.createStatement(ResourceFactory.createResource(classNS + rdfid), ResourceFactory.createProperty(propertyURI), ResourceFactory.createResource(object)));
194-
break;
195+
}
196+
case "Enumeration" -> //add enum
197+
model.add(ResourceFactory.createStatement(ResourceFactory.createResource(classNS + rdfid), ResourceFactory.createProperty(propertyURI), ResourceFactory.createResource(object)));
195198
}
196199

197200
}

src/main/java/core/RdfConvert.java

Lines changed: 96 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package core;
77

88
import application.MainController;
9+
import customWriter.CustomRDFFormat;
910
import javafx.stage.FileChooser;
1011
import org.apache.commons.io.FileUtils;
1112
import org.apache.jena.datatypes.RDFDatatype;
@@ -19,6 +20,7 @@
1920

2021
import java.io.*;
2122
import java.util.*;
23+
import java.util.zip.ZipOutputStream;
2224

2325

2426
public class RdfConvert {
@@ -63,7 +65,7 @@ public static void rdfConversion(File file, List<File> files, String sourceForma
6365
// filechooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Main RDF file", "*.rdf","*.xml", "*.ttl"));
6466
// filechooser.setInitialDirectory(new File(MainController.prefs.get("LastWorkingFolder","")));
6567
// File fileDet1=null;
66-
List<File> fileDet1 = util.ModelFactory.filechoosercustom(true,"Main RDF file", List.of("*.rdf","*.xml", "*.ttl"));
68+
List<File> fileDet1 = util.ModelFactory.filechoosercustom(true,"Main RDF file", List.of("*.rdf","*.xml", "*.ttl"),"");
6769
// try {
6870
// fileDet1 = filechooser.showOpenDialog(null);
6971
// }catch (Exception e){
@@ -81,7 +83,7 @@ public static void rdfConversion(File file, List<File> files, String sourceForma
8183
// filechooser1.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Deviation RDF file", "*.rdf","*.xml", "*.ttl"));
8284
// filechooser1.setInitialDirectory(new File(MainController.prefs.get("LastWorkingFolder","")));
8385
// File fileDet2=null;
84-
List<File> fileDet2 = util.ModelFactory.filechoosercustom(true,"Deviation RDF file", List.of("*.rdf","*.xml", "*.ttl"));
86+
List<File> fileDet2 = util.ModelFactory.filechoosercustom(true,"Deviation RDF file", List.of("*.rdf","*.xml", "*.ttl"),"");
8587
// try {
8688
// fileDet2 = filechooser1.showOpenDialog(null);
8789
// }catch (Exception e){
@@ -99,7 +101,7 @@ public static void rdfConversion(File file, List<File> files, String sourceForma
99101
// filechooser2.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Extended RDF file", "*.rdf","*.xml", "*.ttl"));
100102
// filechooser2.setInitialDirectory(new File(MainController.prefs.get("LastWorkingFolder","")));
101103
// File fileDet3=null;
102-
List<File> fileDet3 = util.ModelFactory.filechoosercustom(true,"Extended RDF file", List.of("*.rdf","*.xml", "*.ttl"));
104+
List<File> fileDet3 = util.ModelFactory.filechoosercustom(true,"Extended RDF file", List.of("*.rdf","*.xml", "*.ttl"),"");
103105
// try {
104106
// fileDet3 = filechooser2.showOpenDialog(null);
105107
// }catch (Exception e){
@@ -197,7 +199,7 @@ public static void rdfConversion(File file, List<File> files, String sourceForma
197199

198200
}else{
199201
// load all models
200-
model = util.ModelFactory.modelLoad(modelFiles,xmlBase,rdfSourceFormat);
202+
model = util.ModelFactory.modelLoad(modelFiles,xmlBase,rdfSourceFormat,false);
201203
}
202204

203205

@@ -250,36 +252,103 @@ public static void rdfConversion(File file, List<File> files, String sourceForma
250252

251253
switch (targetFormat) {
252254
case "RDF XML (.rdf or .xml)":
255+
256+
//register custom format
257+
CustomRDFFormat.RegisterCustomFormatWriters();
258+
String showXmlEncoding = "true"; //saveProperties.get("showXmlEncoding").toString();
259+
boolean putHeaderOnTop = true; //(boolean) saveProperties.get("putHeaderOnTop");
260+
String headerClassResource="http://iec.ch/TC57/61970-552/ModelDescription/1#FullModel"; //saveProperties.get("headerClassResource").toString();
261+
boolean useAboutRules = false;//(boolean) saveProperties.get("useAboutRules"); //switch to trigger file chooser and adding the property
262+
boolean useEnumRules = false;//(boolean) saveProperties.get("useEnumRules"); //switch to trigger special treatment when Enum is reference
263+
264+
Set<Resource> rdfAboutList = null; //(Set<Resource>) saveProperties.get("rdfAboutList");
265+
Set<Resource> rdfEnumList = null;//(Set<Resource>) saveProperties.get("rdfEnumList");
266+
253267
OutputStream outXML = fileSaveDialog("Save RDF XML for: "+filename, "RDF XML", "*.rdf");
254-
if (outXML!=null) {
268+
269+
if (outXML != null) {
255270
try {
256-
Map<String, Object> properties = new HashMap<>();
257-
properties.put("showXmlDeclaration", showXmlDeclaration);
258-
properties.put("showDoctypeDeclaration", showDoctypeDeclaration);
259-
//properties.put("blockRules", RDFSyntax.propertyAttr.toString()); //???? not sure
260-
properties.put("xmlbase", xmlBase);
261-
properties.put("tab", tab);
262-
//properties.put("prettyTypes",new Resource[] {ResourceFactory.createResource("http://iec.ch/TC57/61970-552/ModelDescription/1#FullModel")});
263-
properties.put("relativeURIs", relativeURIs);
264-
265-
266-
// Put a properties object into the Context.
267-
Context cxt = new Context();
268-
cxt.set(SysRIOT.sysRdfWriterProperties, properties);
269-
270-
org.apache.jena.riot.RDFWriter.create()
271-
.base(xmlBase)
272-
.format(rdfFormat)
273-
.context(cxt)
274-
.source(model)
275-
.output(outXML);
276-
if (inheritanceList) {
277-
fileSaveDialogInheritance(filename+"Inheritance",xmlBase);
271+
if (rdfFormat == CustomRDFFormat.RDFXML_CUSTOM_PLAIN_PRETTY || rdfFormat == CustomRDFFormat.RDFXML_CUSTOM_PLAIN) {
272+
Map<String, Object> properties = new HashMap<>();
273+
properties.put("showXmlDeclaration", showXmlDeclaration);
274+
properties.put("showDoctypeDeclaration", showDoctypeDeclaration);
275+
properties.put("showXmlEncoding", showXmlEncoding); // works only with the custom format
276+
//properties.put("blockRules", "daml:collection,parseTypeLiteralPropertyElt,"
277+
// +"parseTypeResourcePropertyElt,parseTypeCollectionPropertyElt"
278+
// +"sectionReification,sectionListExpand,idAttr,propertyAttr"); //???? not sure
279+
if (putHeaderOnTop) {
280+
properties.put("prettyTypes", new Resource[]{ResourceFactory.createResource(headerClassResource)});
281+
}
282+
properties.put("xmlbase", xmlBase);
283+
properties.put("tab", tab);
284+
properties.put("relativeURIs", relativeURIs);
285+
286+
if (useAboutRules) {
287+
properties.put("aboutRules", rdfAboutList);
288+
}
289+
290+
if (useEnumRules) {
291+
properties.put("enumRules", rdfEnumList);
292+
}
293+
294+
// Put a properties object into the Context.
295+
Context cxt = new Context();
296+
cxt.set(SysRIOT.sysRdfWriterProperties, properties);
297+
298+
org.apache.jena.riot.RDFWriter.create()
299+
.base(xmlBase)
300+
.format(rdfFormat)
301+
.context(cxt)
302+
.source(model)
303+
.output(outXML);
304+
305+
} else {
306+
try {
307+
Map<String, Object> properties = new HashMap<>();
308+
properties.put("showXmlDeclaration", showXmlDeclaration);
309+
properties.put("showDoctypeDeclaration", showDoctypeDeclaration);
310+
//properties.put("blockRules", RDFSyntax.propertyAttr.toString()); //???? not sure
311+
properties.put("xmlbase", xmlBase);
312+
properties.put("tab", tab);
313+
//properties.put("prettyTypes",new Resource[] {ResourceFactory.createResource("http://iec.ch/TC57/61970-552/ModelDescription/1#FullModel")});
314+
properties.put("relativeURIs", relativeURIs);
315+
316+
317+
// Put a properties object into the Context.
318+
Context cxt = new Context();
319+
cxt.set(SysRIOT.sysRdfWriterProperties, properties);
320+
321+
org.apache.jena.riot.RDFWriter.create()
322+
.base(xmlBase)
323+
.format(rdfFormat)
324+
.context(cxt)
325+
.source(model)
326+
.output(outXML);
327+
if (inheritanceList) {
328+
fileSaveDialogInheritance(filename + "Inheritance", xmlBase);
329+
}
330+
} finally {
331+
outXML.close();
332+
}
278333
}
279334
} finally {
335+
outXML.flush();
280336
outXML.close();
337+
338+
281339
}
282340
}
341+
342+
343+
344+
345+
346+
347+
348+
349+
350+
351+
283352
break;
284353

285354
case "RDF Turtle (.ttl)":

0 commit comments

Comments
 (0)