Skip to content

Commit

Permalink
Fixes for ability to not draw arrows pointing to an empty box
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrancart committed Jul 21, 2021
1 parent e5bdab0 commit ca12066
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public static void main(String[] args) throws Exception {
}


ShaclPlantUmlWriter writer = new ShaclPlantUmlWriter(true, false);
String output = writer.writeInPlantUml(shaclGraph,owlGraph,outExpandDiagram);
ShaclPlantUmlWriter writer = new ShaclPlantUmlWriter(true, false, outExpandDiagram);
String output = writer.writeInPlantUml(shaclGraph,owlGraph);

String outputDirectory ="C:/Temp" ; //args[1];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ public String renderDefault(PlantUmlProperty property, String boxName) {
return output;
}

public String renderNodeShape(PlantUmlBox box, List<PlantUmlBox> GlobalBox, boolean outExpandDiagram) {
public String renderNodeShape(PlantUmlBox box, List<PlantUmlBox> GlobalBox, boolean avoidArrowsToEmptyBoxes) {
// String declaration = "Class"+"
// "+"\""+box.getNameshape()+"\""+((box.getNametargetclass() != null)?"
// "+"<"+box.getNametargetclass()+">":"");
String declaration = "";
// Array for control inverse

if (outExpandDiagram) {
if (avoidArrowsToEmptyBoxes) {
if (box.getProperties().size() > 0) {

declaration = "Class" + " " + "\"" + box.getLabel() + "\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,29 @@
import java.util.stream.Collectors;

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.OWL;
import org.apache.jena.vocabulary.RDF;
import org.topbraid.shacl.vocabulary.SH;

public class ShaclPlantUmlWriter {

protected boolean includeSubclassLinks = true;
protected boolean generateAnchorHyperlink = false;
protected boolean avoidArrowsToEmptyBoxes = true;

public ShaclPlantUmlWriter(boolean includeSubclassLinks, boolean generateAnchorHyperlink) {
public ShaclPlantUmlWriter(
boolean includeSubclassLinks,
boolean generateAnchorHyperlink,
boolean avoidArrowsToEmptyBoxes
) {
super();
this.includeSubclassLinks = includeSubclassLinks;
this.generateAnchorHyperlink = generateAnchorHyperlink;
this.avoidArrowsToEmptyBoxes = avoidArrowsToEmptyBoxes;
}

public String writeInPlantUml(Model shaclGraph, Model owlGraph, boolean outExpandDiagram) {
public String writeInPlantUml(Model shaclGraph, Model owlGraph) {

// read everything typed as NodeShape
List<Resource> nodeShapes = shaclGraph.listResourcesWithProperty(RDF.type, SH.NodeShape).toList();
Expand Down Expand Up @@ -95,7 +99,7 @@ public String writeInPlantUml(Model shaclGraph, Model owlGraph, boolean outExpan
}

for (PlantUmlBox plantUmlBox : plantUmlBoxes.stream().filter(b -> b.getPackageName().equals(aPackage)).collect(Collectors.toList())) {
sourceuml.append(renderer.renderNodeShape(plantUmlBox,plantUmlBoxes,outExpandDiagram));
sourceuml.append(renderer.renderNodeShape(plantUmlBox,plantUmlBoxes,this.avoidArrowsToEmptyBoxes));
}

if(!aPackage.equals("")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@

public class PlantUmlSourceGenerator {

public String generatePlantUmlDiagram(Model shapesModel, Model owlModel, boolean subclasssOf,boolean Classlink, boolean outExpandDiagram) throws IOException {
public String generatePlantUmlDiagram(
Model shapesModel,
Model owlModel,
boolean subclasssOf,
boolean Classlink,
boolean avoidArrowsToEmptyBoxes
) throws IOException {

// draw - without subclasses links
// set first parameter to true to draw subclassOf links
ShaclPlantUmlWriter writer = new ShaclPlantUmlWriter(subclasssOf, Classlink);
ShaclPlantUmlWriter writer = new ShaclPlantUmlWriter(subclasssOf, Classlink, avoidArrowsToEmptyBoxes);
Model finalModel = ModelFactory.createDefaultModel();
finalModel.add(shapesModel);
if(owlModel != null) {
finalModel.add(owlModel);
}
//String plantUmlString = writer.writeInPlantUml(finalModel,,outExpandDiagram);
String plantUmlString = writer.writeInPlantUml(shapesModel,owlModel,outExpandDiagram);
String plantUmlString = writer.writeInPlantUml(shapesModel,owlModel);
return plantUmlString;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

public class SVGGenerator {

public String generateSvgDiagram(Model shapesModel, Model owlModel,boolean outExpandDiagram) throws IOException {
public String generateSvgDiagram(Model shapesModel, Model owlModel,boolean avoidArrowsToEmptyBoxes) throws IOException {

// draw - without subclasses links
// set first parameter to true to draw subclassOf links
ShaclPlantUmlWriter writer = new ShaclPlantUmlWriter(true, true);
ShaclPlantUmlWriter writer = new ShaclPlantUmlWriter(true, true, avoidArrowsToEmptyBoxes);
Model finalModel = ModelFactory.createDefaultModel();
finalModel.add(shapesModel);
if(owlModel != null) {
finalModel.add(owlModel);
}
//String plantUmlString = writer.writeInPlantUml(finalModel);
String plantUmlString = writer.writeInPlantUml(shapesModel,owlModel,outExpandDiagram);
String plantUmlString = writer.writeInPlantUml(shapesModel,owlModel);

// System.out.println(plantUmlString);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public void execute(Object args) throws Exception {
InputModelReader.populateModel(shapesModel, a.getInput(), null);

// draw
ShaclPlantUmlWriter writer = new ShaclPlantUmlWriter(a.isIncludeSubclasses(), false);
ShaclPlantUmlWriter writer = new ShaclPlantUmlWriter(a.isIncludeSubclasses(), false, true);
// TODO : add parameter with OWL file
String plantUmlString = writer.writeInPlantUml(shapesModel, ModelFactory.createDefaultModel(), false);
String plantUmlString = writer.writeInPlantUml(shapesModel, ModelFactory.createDefaultModel());

for(File outputFile : a.getOutput()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ protected void doOutputDoc(
ShapesDocumentationReaderIfc reader = new ShapesDocumentationModelReader(true);
ShapesDocumentation doc = reader.readShapesDocumentation(
shapesModel,
null,
// OWL graph
ModelFactory.createDefaultModel(),
"en",
filename,
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,20 @@ protected void doOutputDiagram(
FORMAT format,
HttpServletResponse response
) throws IOException {
// includes the subClassOf links in the generated diagram
// don't generate hyperlinks
ShaclPlantUmlWriter writer = new ShaclPlantUmlWriter(true, false);


ShaclPlantUmlWriter writer = new ShaclPlantUmlWriter(
// includes the subClassOf links in the generated diagram
true,
// don't generate hyperlinks
false,
// avoid arrows to empty boxes
true);
String plantumlString = writer.writeInPlantUml(
shapesModel,
// OWL Model
ModelFactory.createDefaultModel(),
false);
ModelFactory.createDefaultModel()
);

response.setContentType(format.mimeType);
response.setHeader("Content-Disposition", "inline; filename=\""+filename+"."+format.extension+"\"");
Expand Down

0 comments on commit ca12066

Please sign in to comment.