Skip to content

Commit

Permalink
issues #25 and #26 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
isantana committed Jun 2, 2015
1 parent 6e5fc14 commit 59a0373
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 12 deletions.
Binary file modified bin/ar2dtool.jar
Binary file not shown.
30 changes: 26 additions & 4 deletions es/upm/oeg/ar2dtool/RDF2Diagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +56,10 @@ public class RDF2Diagram {
//Prefix map for later format
Map<String, String> prefixMap;


//Restriction List
private ArrayList<String> restrictionList;


//LOGGING
private static final Logger log = Logger.getLogger("AR2DTOOL");
Expand Down Expand Up @@ -103,9 +108,10 @@ public void loadRdf(String pathToRdfFile) throws RDFNotFound, RDFInputNotValid
}
log("RDF model loaded from " + pathToRdfFile);




detectPrefixMap();

detectRestrictions();

detectClasses();

Expand Down Expand Up @@ -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() {
Expand All @@ -408,6 +414,22 @@ private void detectClasses()
}
}


private void detectRestrictions()
{

restrictionList = new ArrayList<String>();

ExtendedIterator<Restriction> 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()
Expand Down
59 changes: 52 additions & 7 deletions es/upm/oeg/ar2dtool/utils/dot/DOTGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -57,13 +63,20 @@ public class DOTGenerator
//DOT Triples
private ArrayList<AR2DTriple> dottriples;

//ALL NODENAMES to be depicted
private HashSet<String> allDepictedNodeNames;

//SHAPES&COLORS LISTS
private ArrayList<String> classesSC, individualsSC, literalsSC, ontPropertiesSC, dtPropertiesSC;

private Map<String, String> prefixMap;


//RESTRICTION LIST
private ArrayList<String> restrictionList;


public DOTGenerator(OntModel m, ConfigValues c, ArrayList<String> clsc, Map<String, String> pm)
public DOTGenerator(OntModel m, ConfigValues c, ArrayList<String> clsc, Map<String, String> pm, ArrayList<String> reslist)
{
model = m;
conf = c;
Expand All @@ -74,6 +87,8 @@ public DOTGenerator(OntModel m, ConfigValues c, ArrayList<String> clsc, Map<Stri
ontPropertiesSC = new ArrayList<String>();
dtPropertiesSC = new ArrayList<String>();
objPropsMap = new HashMap<String,ObjPropPair<String,String>>();
allDepictedNodeNames = new HashSet<String>();
restrictionList = reslist;
prefixMap = pm;
}

Expand All @@ -90,7 +105,7 @@ public DOTGenerator(OntModel m, ConfigValues c, ArrayList<String> clsc, Map<Stri
*/
public void applyTransformations() throws NullTripleMember
{

//detecting classes
detectClasses();

Expand All @@ -113,12 +128,21 @@ public void applyTransformations() throws NullTripleMember
Resource s = st.getSubject();
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
Expand Down Expand Up @@ -167,6 +191,7 @@ public String generateDOTSource() throws NullTripleMember
String dottail = "\n}";



String dotsource = "";
for(AR2DTriple dt : dottriples)
{
Expand All @@ -177,6 +202,11 @@ public String generateDOTSource() throws NullTripleMember

String spoviz = "\t\""+dt.getSource()+"\" -> \"" + 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") +"\"]; ";
Expand All @@ -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(""))
{
Expand All @@ -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(""))
{
Expand All @@ -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(""))
{
Expand All @@ -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(""))
{
Expand All @@ -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(""))
{
Expand Down
19 changes: 18 additions & 1 deletion es/upm/oeg/ar2dtool/utils/graphml/GraphMLGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,22 @@ public class GraphMLGenerator
//DOT Triples
private ArrayList<AR2DTriple> gmltriples;

//RESTRICTION LIST
private ArrayList<String> restrictionList;

//AVOID RESTRICTIONS
private static final boolean AVOID_RESTRICTION_NODES = true;



//SHAPES&COLORS LISTS

private ArrayList<String> classesSC, individualsSC, literalsSC, ontPropertiesSC, dtPropertiesSC;

private Map<String, String> prefixMap;


public GraphMLGenerator(OntModel m, ConfigValues c, ArrayList<String> clsc, Map<String, String> pm)
public GraphMLGenerator(OntModel m, ConfigValues c, ArrayList<String> clsc, Map<String, String> pm, ArrayList<String> reslist)
{
model = m;
conf = c;
Expand All @@ -83,6 +91,7 @@ public GraphMLGenerator(OntModel m, ConfigValues c, ArrayList<String> clsc, Map<
ontPropertiesSC = new ArrayList<String>();
dtPropertiesSC = new ArrayList<String>();
objPropsMap = new HashMap<String,ObjPropPair<String,String>>();
restrictionList = reslist;
prefixMap = pm;
}

Expand Down Expand Up @@ -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
Expand Down
Binary file modified lib/ar2dtool-0.1.jar
Binary file not shown.

0 comments on commit 59a0373

Please sign in to comment.