Skip to content

Commit ca0b3a0

Browse files
author
Chavdar Ivanov
committed
Version 2021-1.0.2-beta: Main improvement - the RDFS comparison when using the draft 61970-501:Ed2.
1 parent 38c53ca commit ca0b3a0

File tree

10 files changed

+573
-191
lines changed

10 files changed

+573
-191
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>2021-1.0.0</version>
6+
<version>2021-1.0.2</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>2021-1.0.0</version>
15+
<version>2021-1.0.2</version>
1616

1717

1818
<build>

src/main/java/application/MainController.java

Lines changed: 136 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package application;
77

8+
import com.fasterxml.jackson.databind.annotation.JsonAppend;
89
import core.*;
910
import gui.ComboBoxCell;
1011
import gui.GUIhelper;
@@ -37,14 +38,13 @@
3738
import org.apache.jena.riot.Lang;
3839
import org.apache.jena.riot.RDFDataMgr;
3940
import org.apache.jena.riot.RDFFormat;
41+
import org.apache.jena.util.ResourceUtils;
4042
import org.apache.jena.util.iterator.ExtendedIterator;
41-
import org.apache.jena.vocabulary.OWL;
42-
import org.apache.jena.vocabulary.RDF;
43-
import org.apache.jena.vocabulary.RDFS;
44-
import org.apache.jena.vocabulary.XSD;
43+
import org.apache.jena.vocabulary.*;
4544
import org.topbraid.jenax.util.JenaUtil;
4645
import org.topbraid.shacl.vocabulary.DASH;
4746
import org.topbraid.shacl.vocabulary.SH;
47+
import util.CompareFactory;
4848
import util.ExcelTools;
4949

5050
import java.io.*;
@@ -202,6 +202,12 @@ public class MainController implements Initializable {
202202
private CheckBox fcbIDcompSolutionOverview;
203203
@FXML
204204
private CheckBox fcbIDcompShowDetails;
205+
@FXML
206+
private CheckBox fcbRDFcompareCimVersion;
207+
@FXML
208+
private CheckBox fcbRDFcompareProfileNS;
209+
@FXML
210+
private TextField fPrefixRDFCompare;
205211

206212

207213

@@ -310,6 +316,7 @@ public void write(int b) {
310316

311317
fcbRDFSformat.getItems().addAll(
312318
"RDFS (augmented) by CimSyntaxGen",
319+
"RDFS IEC 61970-501:Ed2 (CD) by CimSyntaxGen",
313320
"SHACL Shapes"
314321

315322
);
@@ -386,6 +393,9 @@ public void write(int b) {
386393
//Adding action to the choice box
387394
fcbIDmap.getSelectionModel().selectedItemProperty().addListener((obs, oldV, newV) -> actionCBIDmap());
388395

396+
//Adding action to the choice box
397+
fcbRDFSformat.getSelectionModel().selectedItemProperty().addListener((obs, oldV, newV) -> actionCBfcbRDFSformat());
398+
389399
//TODO: see how to have this default on the screen
390400
defaultShapesURI="/Constraints";
391401
}
@@ -490,7 +500,8 @@ private void actionBtnResetExcelShape(ActionEvent actionEvent) {
490500
private void actionBrowseRDFfile1(ActionEvent actionEvent) {
491501
progressBar.setProgress(0);
492502
File file=null;
493-
if (fcbRDFSformat.getSelectionModel().getSelectedItem().equals("RDFS (augmented) by CimSyntaxGen")) {
503+
if (fcbRDFSformat.getSelectionModel().getSelectedItem().equals("RDFS (augmented) by CimSyntaxGen") ||
504+
fcbRDFSformat.getSelectionModel().getSelectedItem().equals("RDFS IEC 61970-501:Ed2 (CD) by CimSyntaxGen")) {
494505
//select file 1
495506
FileChooser filechooser = new FileChooser();
496507
filechooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("RDF files", "*.rdf"));
@@ -524,7 +535,8 @@ private void actionBrowseRDFfile1(ActionEvent actionEvent) {
524535
private void actionBrowseRDFfile2(ActionEvent actionEvent) {
525536
progressBar.setProgress(0);
526537
File file=null;
527-
if (fcbRDFSformat.getSelectionModel().getSelectedItem().equals("RDFS (augmented) by CimSyntaxGen")) {
538+
if (fcbRDFSformat.getSelectionModel().getSelectedItem().equals("RDFS (augmented) by CimSyntaxGen") ||
539+
fcbRDFSformat.getSelectionModel().getSelectedItem().equals("RDFS IEC 61970-501:Ed2 (CD) by CimSyntaxGen")) {
528540
//select file 2
529541
FileChooser filechooser = new FileChooser();
530542
filechooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("RDF files", "*.rdf"));
@@ -787,7 +799,7 @@ private void actionBtnRunIDcompare(ActionEvent actionEvent) throws IOException {
787799
}
788800
if (fcbIDcompCount.isSelected()) {
789801
options.set(3,1);
790-
compareResults = ComparisonInstanceData.compareCountClasses(compareResults,model1,model2);
802+
compareResults = CompareFactory.compareCountClasses(compareResults,model1,model2);
791803
}
792804
if (fcbIDcompIgnoreTP.isSelected()) {
793805
options.set(4,1);
@@ -815,8 +827,8 @@ private void actionBtnRunIDcompare(ActionEvent actionEvent) throws IOException {
815827
try {
816828
Stage guiRdfDiffResultsStage = new Stage();
817829
//Scene for the menu RDF differences
818-
FXMLLoader fxmlLoader = new FXMLLoader();
819-
Parent rootRDFdiff = fxmlLoader.load(getClass().getResource("/fxml/rdfDiffResult.fxml"));
830+
//FXMLLoader fxmlLoader = new FXMLLoader();
831+
Parent rootRDFdiff = FXMLLoader.load(getClass().getResource("/fxml/rdfDiffResult.fxml"));
820832
Scene rdfDiffscene = new Scene(rootRDFdiff);
821833
guiRdfDiffResultsStage.setScene(rdfDiffscene);
822834
guiRdfDiffResultsStage.setTitle("Comparison Instance data");
@@ -852,6 +864,7 @@ private void actionBtnRunRDFcompare(ActionEvent actionEvent) throws FileNotFound
852864
Lang rdfSourceFormat2=Lang.RDFXML;
853865
switch (fcbRDFSformat.getSelectionModel().getSelectedItem().toString()) {
854866
case "RDFS (augmented) by CimSyntaxGen":
867+
case "RDFS IEC 61970-501:Ed2 (CD) by CimSyntaxGen":
855868
rdfSourceFormat1=Lang.RDFXML;
856869
rdfSourceFormat2=Lang.RDFXML;
857870
break;
@@ -878,8 +891,54 @@ private void actionBtnRunRDFcompare(ActionEvent actionEvent) throws FileNotFound
878891
modelFiles2.add(MainController.rdfModel2);
879892

880893
Model model1 = util.ModelFactory.modelLoad(modelFiles1,null,rdfSourceFormat1);
881-
Model model2 = util.ModelFactory.modelLoad(modelFiles2,null,rdfSourceFormat2);
894+
Model model2Temp = util.ModelFactory.modelLoad(modelFiles2, null, rdfSourceFormat2);
895+
896+
Model model2 = null;
897+
boolean error=false;
898+
if (fcbRDFcompareCimVersion.isSelected() && !fcbRDFcompareProfileNS.isSelected()) {//rename cim namespace in the second model
899+
model2 = CompareFactory.renameNamespaceURIresources(model2Temp, "cim", model1.getNsPrefixURI("cim"));
900+
}else if (!fcbRDFcompareCimVersion.isSelected() && fcbRDFcompareProfileNS.isSelected()) {//rename only profile namespace in the second model
901+
String prefixProfile = fPrefixRDFCompare.getText();
902+
String profileURI = model1.getNsPrefixURI(prefixProfile);
903+
if (profileURI!=null){
904+
model2 = CompareFactory.renameNamespaceURIresources(model2Temp, prefixProfile, profileURI);
905+
}else{
906+
String profilePrefixURI = CompareFactory.getProfileURI(model2Temp);
907+
if (profilePrefixURI!=null){
908+
model2 = CompareFactory.renameNamespaceURIresources(model2Temp, profilePrefixURI,model1.getNsPrefixURI(profilePrefixURI));
909+
}else{
910+
error=true;
911+
}
912+
}
913+
914+
}else if (fcbRDFcompareCimVersion.isSelected() && fcbRDFcompareProfileNS.isSelected()){//rename both cim namespace and profile namespace in the second model
915+
model2 = CompareFactory.renameNamespaceURIresources(model2Temp, "cim", model1.getNsPrefixURI("cim"));
916+
String prefixProfile = fPrefixRDFCompare.getText();
917+
String profileURI = model1.getNsPrefixURI(prefixProfile);
918+
if (profileURI!=null){
919+
model2 = CompareFactory.renameNamespaceURIresources(model2, prefixProfile, profileURI);
920+
}else{
921+
String profilePrefixURI = CompareFactory.getProfileURI(model2);
922+
if (profilePrefixURI!=null){
923+
model2 = CompareFactory.renameNamespaceURIresources(model2, profilePrefixURI,model1.getNsPrefixURI(profilePrefixURI));
924+
}else{
925+
error=true;
926+
}
927+
}
928+
929+
}else{// no rename
930+
model2=model2Temp;
931+
}
932+
882933

934+
if (error){
935+
Alert alert = new Alert(Alert.AlertType.ERROR);
936+
alert.setContentText("No header in the file and the profile namespace prefix is not declared.");
937+
alert.setHeaderText(null);
938+
alert.setTitle("Error");
939+
alert.showAndWait();
940+
return;
941+
}
883942

884943

885944
//Model model1 = ModelFactory.createDefaultModel(); // model for rdf file1
@@ -897,43 +956,53 @@ private void actionBtnRunRDFcompare(ActionEvent actionEvent) throws FileNotFound
897956
rdfsCompareFiles.add(MainController.rdfModel1.getName());
898957
rdfsCompareFiles.add(MainController.rdfModel2.getName());
899958

900-
if (fcbRDFSformat.getSelectionModel().getSelectedItem().toString().equals("RDFS (augmented) by CimSyntaxGen")) {
901-
compareResults = ComparisonRDFSprofile.compareRDFSprofile(model1, model2);
902-
903-
if (compareResults.size() != 0) {
959+
switch (fcbRDFSformat.getSelectionModel().getSelectedItem().toString()) {
960+
case "RDFS (augmented) by CimSyntaxGen":
961+
compareResults = ComparisonRDFSprofile.compareRDFSprofile(model1, model2);
962+
break;
963+
case "RDFS IEC 61970-501:Ed2 (CD) by CimSyntaxGen":
964+
compareResults = ComparissonRDFS501Ed2.compareRDFS501Ed2(model1, model2);
965+
break;
966+
case "SHACL Shapes":
967+
compareResults = ComparisonSHACLshapes.compareSHACLshapes(model1, model2);
968+
break;
969+
}
904970

905-
try {
906-
Stage guiRdfDiffResultsStage = new Stage();
907-
//Scene for the menu RDF differences
908-
FXMLLoader fxmlLoader = new FXMLLoader();
909-
Parent rootRDFdiff = fxmlLoader.load(getClass().getResource("/fxml/rdfDiffResult.fxml"));
910-
Scene rdfDiffscene = new Scene(rootRDFdiff);
911-
guiRdfDiffResultsStage.setScene(rdfDiffscene);
912-
guiRdfDiffResultsStage.setTitle("Comparison RDFS profiles");
913-
guiRdfDiffResultsStage.initModality(Modality.APPLICATION_MODAL);
914-
rdfDiffResultController.initData(guiRdfDiffResultsStage);
915-
progressBar.setProgress(1);
916-
guiRdfDiffResultsStage.showAndWait();
917971

972+
if (compareResults.size() != 0) {
918973

919-
} catch (IOException e) {
920-
e.printStackTrace();
921-
}
922-
} else {
923-
Alert alert = new Alert(Alert.AlertType.INFORMATION);
924-
alert.setContentText("The two models are identical if the CIM namespace would be the same.");
925-
alert.setHeaderText(null);
926-
alert.setTitle("Information");
974+
try {
975+
Stage guiRdfDiffResultsStage = new Stage();
976+
//Scene for the menu RDF differences
977+
//FXMLLoader fxmlLoader = new FXMLLoader();
978+
Parent rootRDFdiff = FXMLLoader.load(getClass().getResource("/fxml/rdfDiffResult.fxml"));
979+
Scene rdfDiffscene = new Scene(rootRDFdiff);
980+
guiRdfDiffResultsStage.setScene(rdfDiffscene);
981+
guiRdfDiffResultsStage.setTitle("Comparison RDFS profiles");
982+
guiRdfDiffResultsStage.initModality(Modality.APPLICATION_MODAL);
983+
rdfDiffResultController.initData(guiRdfDiffResultsStage);
927984
progressBar.setProgress(1);
928-
alert.showAndWait();
985+
guiRdfDiffResultsStage.showAndWait();
986+
987+
988+
} catch (IOException e) {
989+
e.printStackTrace();
929990
}
930-
} else if(fcbRDFSformat.getSelectionModel().getSelectedItem().toString().equals("SHACL Shapes")){
931-
compareResults = ComparisonSHACLshapes.compareSHACLshapes(model1, model2);
991+
} else {
992+
Alert alert = new Alert(Alert.AlertType.INFORMATION);
993+
alert.setContentText("The two models are identical if the CIM namespace would be the same.");
994+
alert.setHeaderText(null);
995+
alert.setTitle("Information");
996+
progressBar.setProgress(1);
997+
alert.showAndWait();
932998
}
933-
progressBar.setProgress(1);
999+
1000+
9341001

9351002
}
9361003

1004+
1005+
9371006
@FXML
9381007
//This is the menu item "Create datatypes map" - loads RDFfile(s) and creates the map
9391008
private void actionMenuDatatypeMap(ActionEvent actionEvent) throws IOException {
@@ -1293,6 +1362,35 @@ private void actionCBIDmap() {
12931362

12941363
}
12951364

1365+
//Action for choice box "RDF scope and format" related to RDF comparison
1366+
private void actionCBfcbRDFSformat() {
1367+
1368+
progressBar.setProgress(0);
1369+
if(!fcbRDFSformat.getSelectionModel().isSelected(-1)) {
1370+
if (fcbRDFSformat.getSelectionModel().getSelectedItem().toString().equals("RDFS IEC 61970-501:Ed2 (CD) by CimSyntaxGen") ||
1371+
fcbRDFSformat.getSelectionModel().getSelectedItem().toString().equals("SHACL Shapes")) {
1372+
fcbRDFcompareCimVersion.setDisable(false);
1373+
fcbRDFcompareProfileNS.setDisable(false);
1374+
fPrefixRDFCompare.setDisable(false);
1375+
} else {
1376+
fcbRDFcompareCimVersion.setDisable(true);
1377+
fcbRDFcompareCimVersion.setSelected(false);
1378+
fcbRDFcompareProfileNS.setDisable(true);
1379+
fcbRDFcompareProfileNS.setSelected(false);
1380+
fPrefixRDFCompare.setDisable(true);
1381+
fPrefixRDFCompare.clear();
1382+
}
1383+
} else {
1384+
fcbRDFcompareCimVersion.setDisable(true);
1385+
fcbRDFcompareCimVersion.setSelected(false);
1386+
fcbRDFcompareProfileNS.setDisable(true);
1387+
fcbRDFcompareProfileNS.setSelected(false);
1388+
fPrefixRDFCompare.setDisable(true);
1389+
fPrefixRDFCompare.clear();
1390+
}
1391+
1392+
}
1393+
12961394
//Loads model data
12971395
private void modelLoad(int m) {
12981396

0 commit comments

Comments
 (0)