diff --git a/bin/ar2dtool.jar b/bin/ar2dtool.jar index 4875325..6411294 100644 Binary files a/bin/ar2dtool.jar and b/bin/ar2dtool.jar differ diff --git a/es/upm/oeg/ar2dtool/RDF2Diagram.java b/es/upm/oeg/ar2dtool/RDF2Diagram.java index 65ee2d9..12fa612 100644 --- a/es/upm/oeg/ar2dtool/RDF2Diagram.java +++ b/es/upm/oeg/ar2dtool/RDF2Diagram.java @@ -13,6 +13,7 @@ import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; +import com.hp.hpl.jena.ontology.Restriction; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; @@ -55,6 +56,10 @@ public class RDF2Diagram { //Prefix map for later format Map prefixMap; + + //Restriction List + private ArrayList restrictionList; + //LOGGING private static final Logger log = Logger.getLogger("AR2DTOOL"); @@ -103,9 +108,10 @@ public void loadRdf(String pathToRdfFile) throws RDFNotFound, RDFInputNotValid } log("RDF model loaded from " + pathToRdfFile); - - + detectPrefixMap(); + + detectRestrictions(); detectClasses(); @@ -376,12 +382,12 @@ private void SEVERE(String msg) public DOTGenerator getDOTGenerator() { - return new DOTGenerator(model,conf, classesSC, prefixMap); + return new DOTGenerator(model,conf, classesSC, prefixMap,restrictionList); } public GraphMLGenerator getGraphMLGenerator() { - return new GraphMLGenerator(model,conf, classesSC, prefixMap); + return new GraphMLGenerator(model,conf, classesSC, prefixMap,restrictionList); } public String printModel() { @@ -408,6 +414,22 @@ private void detectClasses() } } + + private void detectRestrictions() + { + + restrictionList = new ArrayList(); + + ExtendedIterator itr = model.listRestrictions(); + while(itr.hasNext()) + { + Restriction res = itr.next(); + restrictionList.add(res.toString()); + log(">>>>>>RESTRICTION:" + res); + } + + } + //load the nsmap and swap keys and values //for easier access later private void detectPrefixMap() diff --git a/es/upm/oeg/ar2dtool/utils/dot/DOTGenerator.java b/es/upm/oeg/ar2dtool/utils/dot/DOTGenerator.java index e1384ae..7223401 100644 --- a/es/upm/oeg/ar2dtool/utils/dot/DOTGenerator.java +++ b/es/upm/oeg/ar2dtool/utils/dot/DOTGenerator.java @@ -5,16 +5,19 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import com.hp.hpl.jena.graph.Node; import com.hp.hpl.jena.ontology.DatatypeProperty; import com.hp.hpl.jena.ontology.Individual; import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntProperty; +import com.hp.hpl.jena.ontology.Restriction; import com.hp.hpl.jena.rdf.model.NsIterator; import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.RDFNode; @@ -47,6 +50,9 @@ public class DOTGenerator //WHEN RANGE OR DOMAINS ARE EMPTY private static final String DEFAULT_OBJ_PROP_VALUE = "http://www.w3.org/2002/07/owl#Thing"; + //AVOID RESTRICTIONS + private static final boolean AVOID_RESTRICTION_NODES = true; + //CONF VALUES private ConfigValues conf; @@ -57,13 +63,20 @@ public class DOTGenerator //DOT Triples private ArrayList dottriples; + //ALL NODENAMES to be depicted + private HashSet allDepictedNodeNames; + //SHAPES&COLORS LISTS private ArrayList classesSC, individualsSC, literalsSC, ontPropertiesSC, dtPropertiesSC; private Map prefixMap; + + + //RESTRICTION LIST + private ArrayList restrictionList; - public DOTGenerator(OntModel m, ConfigValues c, ArrayList clsc, Map pm) + public DOTGenerator(OntModel m, ConfigValues c, ArrayList clsc, Map pm, ArrayList reslist) { model = m; conf = c; @@ -74,6 +87,8 @@ public DOTGenerator(OntModel m, ConfigValues c, ArrayList clsc, Map(); dtPropertiesSC = new ArrayList(); objPropsMap = new HashMap>(); + allDepictedNodeNames = new HashSet(); + restrictionList = reslist; prefixMap = pm; } @@ -90,7 +105,7 @@ public DOTGenerator(OntModel m, ConfigValues c, ArrayList clsc, Map \"" + dt.getTarget() + "\" [ label = \""+ dt.getEdge() + "\" ];\n"; dotsource += spoviz; + + //store all node names for later filtering ISSUE #25 + allDepictedNodeNames.add(dt.getSource()); + allDepictedNodeNames.add(dt.getEdge()); + allDepictedNodeNames.add(dt.getTarget()); } String classStyle = "node [shape = "+ conf.getKeys().get("classShape") +", color=\""+ conf.getKeys().get("classColor") +"\"]; "; @@ -188,7 +218,10 @@ public String generateDOTSource() throws NullTripleMember String classesStyle = ""; for (String c : classesSC) { - classesStyle += "\"" + c + "\" "; + if(allDepictedNodeNames.contains(c)) + { + classesStyle += "\"" + c + "\" "; + } } if(!classesStyle.equals("")) { @@ -198,7 +231,10 @@ public String generateDOTSource() throws NullTripleMember String individualsStyle = ""; for (String i : individualsSC) { - individualsStyle += "\"" + i + "\" "; + if(allDepictedNodeNames.contains(i)) + { + individualsStyle += "\"" + i + "\" "; + } } if(!individualsStyle.equals("")) { @@ -209,7 +245,10 @@ public String generateDOTSource() throws NullTripleMember String literalsStyle = ""; for (String l : literalsSC) { - literalsStyle += "\"" + l + "\" "; + if(allDepictedNodeNames.contains(l)) + { + literalsStyle += "\"" + l + "\" "; + } } if(!literalsStyle.equals("")) { @@ -219,7 +258,10 @@ public String generateDOTSource() throws NullTripleMember String objPropsStyle = ""; for (String op : ontPropertiesSC) { - objPropsStyle += "\"" + op + "\" "; + if(allDepictedNodeNames.contains(op)) + { + objPropsStyle += "\"" + op + "\" "; + } } if(!objPropsStyle.equals("")) { @@ -229,7 +271,10 @@ public String generateDOTSource() throws NullTripleMember String dtPropsStyle = ""; for (String dt : dtPropertiesSC) { - dtPropsStyle += "\"" + dt + "\" "; + if(allDepictedNodeNames.contains(dt)) + { + dtPropsStyle += "\"" + dt + "\" "; + } } if(!dtPropsStyle.equals("")) { diff --git a/es/upm/oeg/ar2dtool/utils/graphml/GraphMLGenerator.java b/es/upm/oeg/ar2dtool/utils/graphml/GraphMLGenerator.java index 126c3a0..8b152af 100644 --- a/es/upm/oeg/ar2dtool/utils/graphml/GraphMLGenerator.java +++ b/es/upm/oeg/ar2dtool/utils/graphml/GraphMLGenerator.java @@ -65,6 +65,14 @@ public class GraphMLGenerator //DOT Triples private ArrayList gmltriples; + //RESTRICTION LIST + private ArrayList restrictionList; + + //AVOID RESTRICTIONS + private static final boolean AVOID_RESTRICTION_NODES = true; + + + //SHAPES&COLORS LISTS private ArrayList classesSC, individualsSC, literalsSC, ontPropertiesSC, dtPropertiesSC; @@ -72,7 +80,7 @@ public class GraphMLGenerator private Map prefixMap; - public GraphMLGenerator(OntModel m, ConfigValues c, ArrayList clsc, Map pm) + public GraphMLGenerator(OntModel m, ConfigValues c, ArrayList clsc, Map pm, ArrayList reslist) { model = m; conf = c; @@ -83,6 +91,7 @@ public GraphMLGenerator(OntModel m, ConfigValues c, ArrayList clsc, Map< ontPropertiesSC = new ArrayList(); dtPropertiesSC = new ArrayList(); objPropsMap = new HashMap>(); + restrictionList = reslist; prefixMap = pm; } @@ -122,11 +131,19 @@ public void applyTransformations() throws NullTripleMember Property p = st.getPredicate(); RDFNode o = st.getObject(); + if((AVOID_RESTRICTION_NODES)&&(restrictionList.contains(s.toString()))) + continue; + //detecting literals if(o.isLiteral()) { literalsSC.add(st.getObject().toString()); } + else + { + if((AVOID_RESTRICTION_NODES)&&(restrictionList.contains(o.toString()))) + continue; + } //check syntetize ob props diff --git a/lib/ar2dtool-0.1.jar b/lib/ar2dtool-0.1.jar index 75593ec..56eed32 100644 Binary files a/lib/ar2dtool-0.1.jar and b/lib/ar2dtool-0.1.jar differ