Skip to content

Commit 8ff9b5c

Browse files
committed
Now outputs instance classes in instance-level .ttl.
1 parent 4e9a1d9 commit 8ff9b5c

4 files changed

Lines changed: 27 additions & 21 deletions

File tree

src/controller/Controller.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,7 @@ private void addElementSubaction(MouseEvent mouseEvent) {
644644
if (isOntology && isClass) {
645645
String rdfslabel = classInfo.get(2);
646646
String rdfscomment = classInfo.get(3);
647-
boolean isPlaceholder = Boolean.valueOf(classInfo.get(4));
648-
classes.add(new Vertex(compiledElement, rdfslabel, rdfscomment, isPlaceholder));
647+
classes.add(new Vertex(compiledElement, rdfslabel, rdfscomment));
649648
} else if (isOntology){
650649
String dataType = classInfo.get(1);
651650
classes.add(new Vertex(compiledElement, dataType));

src/model/conceptual/Vertex.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import javafx.geometry.Bounds;
66
import javafx.scene.layout.StackPane;
77
import javafx.scene.shape.Ellipse;
8+
import javafx.scene.shape.Shape;
89
import javafx.scene.text.Text;
910
import javafx.util.Pair;
1011

@@ -52,7 +53,6 @@ public class UndefinedElementTypeException extends Exception {
5253
private ArrayList<Edge> incomingEdges, outgoingEdges;
5354
private boolean isBlankNode;
5455
private boolean isIri;
55-
private boolean isPlaceholder = false;
5656
private String typeDefinition;
5757

5858
private String rdfsLabel, rdfsComment;
@@ -65,14 +65,11 @@ public class UndefinedElementTypeException extends Exception {
6565
* @throws OutsideElementException if the container is not castable to a stackpane (aka it is outside the canvas.
6666
* @throws UndefinedElementTypeException if the name of the Vertex does not correspond to any of the GraphElemTypes.
6767
*/
68-
public Vertex(EventTarget element, String rdfsLabel, String rdfsComment, boolean isPlaceholder)
68+
public Vertex(EventTarget element, String rdfsLabel, String rdfsComment)
6969
throws OutsideElementException, UndefinedElementTypeException {
7070
this(element);
7171
this.rdfsLabel = rdfsLabel;
7272
this.rdfsComment = rdfsComment;
73-
this.isPlaceholder = isPlaceholder;
74-
75-
if (this.isPlaceholder) this.elementType = GraphElemType.INSTANCE_CLASS;
7673
}
7774

7875
/**
@@ -98,7 +95,9 @@ public Vertex(EventTarget element) throws OutsideElementException, UndefinedElem
9895
throw new OutsideElementException();
9996
}
10097

101-
this.name = ((Text) container.getChildren().get(1)).getText();
98+
Shape shape = (Shape) container.getChildren().get(0);
99+
Text name = (Text) container.getChildren().get(1);
100+
this.name = name.getText();
102101

103102
// determine if the Vertex is a Blank Node or fully qualified IRI.
104103
if (this.name.charAt(0) == '_') {
@@ -114,7 +113,9 @@ public Vertex(EventTarget element) throws OutsideElementException, UndefinedElem
114113
}
115114

116115
// determine whether the Vertex is a class, global literal or instance literal.
117-
if (container.getChildren().get(0) instanceof Ellipse) this.elementType = GraphElemType.GLOBAL_CLASS;
116+
if (shape instanceof Ellipse && shape.getStrokeDashArray().size() == 0)
117+
this.elementType = GraphElemType.GLOBAL_CLASS;
118+
else if (shape instanceof Ellipse) this.elementType = GraphElemType.INSTANCE_CLASS;
118119
else if (this.name.matches(globalLiteralRegex)) this.elementType = GraphElemType.GLOBAL_LITERAL;
119120
else if (this.name.matches(instanceLiteralRegex)) this.elementType = GraphElemType.INSTANCE_LITERAL;
120121
else throw new UndefinedElementTypeException();
@@ -323,8 +324,6 @@ public void addOutgoingEdge(Edge e){
323324

324325
public boolean isIri() { return isIri; }
325326

326-
public boolean isPlaceholder() { return isPlaceholder; }
327-
328327
public static char getNextBlankNodeName() {
329328
nextBlankNodeName += 1;
330329
blankNodeNames.add(nextBlankNodeName);

src/model/conversion/gat/FromGatConverter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private void bindLiteral(String lit) throws OutsideElementException, UndefinedEl
103103
double w = Double.valueOf(litElements[2]);
104104
double h = Double.valueOf(litElements[3]);
105105
Color c = Color.web(litElements[4]);
106-
String etype = litElements[5];
106+
boolean isInstance = litElements[5].equals("i");
107107
Text name = new Text(litElements[6]);
108108
String dtype = litElements[7];
109109

@@ -117,7 +117,7 @@ private void bindLiteral(String lit) throws OutsideElementException, UndefinedEl
117117
rect.setStroke(Color.BLACK);
118118

119119
// if the literal is an instance literal, give it a dashed rectangle.
120-
if (etype.equals("i")) rect.getStrokeDashArray().addAll(10d, 10d);
120+
if (isInstance) rect.getStrokeDashArray().addAll(10d, 10d);
121121

122122
compiledLit.getChildren().addAll(rect, name);
123123
compiledElements.add(compiledLit);
@@ -139,7 +139,7 @@ private void bindClass(String cls) throws OutsideElementException, UndefinedElem
139139
double rx = Double.valueOf(clsElements[2]);
140140
double ry = Double.valueOf(clsElements[3]);
141141
Color c = Color.web(clsElements[4]);
142-
String etype = clsElements[5];
142+
boolean isInstance = clsElements[5].equals("i");
143143
Text name = new Text(clsElements[6]);
144144
String label = clsElements[7];
145145
String comment = clsElements[8];
@@ -155,13 +155,13 @@ private void bindClass(String cls) throws OutsideElementException, UndefinedElem
155155
ellipse.setStroke(Color.BLACK);
156156

157157
// if the class is an instance class, give it a dashed ellipse.
158-
if (etype.equals("i")) ellipse.getStrokeDashArray().addAll(10d, 10d);
158+
if (isInstance) ellipse.getStrokeDashArray().addAll(10d, 10d);
159159

160160
compiledCls.getChildren().addAll(ellipse, name);
161161
compiledElements.add(compiledCls);
162162

163163
if (!label.equals("") || !comment.equals(""))
164-
classes.add(new Vertex(compiledCls, label, comment, etype.equals("i")));
164+
classes.add(new Vertex(compiledCls, label, comment));
165165
else classes.add(new Vertex(compiledCls));
166166
}
167167

src/model/dataintegration/DataIntegrator.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ public DataIntegrator(
6767
*/
6868
public String generate() throws PrefixMissingException {
6969
StringBuilder instanceData = new StringBuilder();
70-
ttlClasses = classes.stream().filter(c -> c.getElementType() == GLOBAL_CLASS).collect(Collectors.toList());
70+
ttlClasses = classes
71+
.stream()
72+
.filter(c -> c.getElementType() == GLOBAL_CLASS || c.getElementType() == INSTANCE_CLASS)
73+
.collect(Collectors.toList());
7174

7275
for (CSVRecord record : csv)
7376
instanceData.append(generateInstanceDataOf(record));
@@ -143,7 +146,7 @@ else if (klass.isIri())
143146
return "<" + klass.getName() + ">";
144147
else if (klass.isBlank())
145148
return klass.getName() + blankNodePermutation;
146-
else if (klass.getElementType() == GLOBAL_CLASS) {
149+
else if (klass.getElementType() == GLOBAL_CLASS || klass.getElementType() == INSTANCE_CLASS) {
147150
String name = klass.getName();
148151
String[] nameParts = name.split(":");
149152
String prefixAcronym = nameParts[0];
@@ -248,17 +251,22 @@ private String generateLongformPrefix(String acronym) throws PrefixMissingExcept
248251
* Find either classes or csv headers that do not directly correlate (are not noticably similar).
249252
*/
250253
public void attemptCorrelationOfHeaders(){
251-
ArrayList<Vertex> uncorrelatedClasses = new ArrayList<>(classes);
254+
ArrayList<Vertex> instances = classes
255+
.stream()
256+
.filter(p -> p.getElementType() == INSTANCE_CLASS || p.getElementType() == INSTANCE_LITERAL)
257+
.collect(Collectors.toCollection(ArrayList::new));
258+
259+
ArrayList<Vertex> uncorrelatedClasses = new ArrayList<>(instances);
252260
Map<String, Integer> uncorrelatedHeaders = new HashMap<>(headers);
253261

254262
for (Entry<String, Integer> header : headers.entrySet()){
255-
for (Vertex klass : classes){
263+
for (Vertex klass : instances){
256264
String headerComparable =
257265
header.getKey().charAt(0) == '\uFEFF' ? header.getKey().substring(1) : header.getKey();
258266

259267
boolean isExactMatch = headerComparable.equals(klass.getName());
260268
boolean isCloseMatch = !klass.isIri()
261-
&& klass.getElementType() == GLOBAL_CLASS
269+
&& klass.getElementType() == INSTANCE_CLASS
262270
&& headerComparable.equalsIgnoreCase(klass.getName().split(":", 2)[1]);
263271

264272
if (isExactMatch || isCloseMatch){

0 commit comments

Comments
 (0)