Skip to content

Commit

Permalink
Merge pull request #1 from ahmad88me/master
Browse files Browse the repository at this point in the history
Fix max triples error and add option flag to specify temp file directory
  • Loading branch information
ahmad88me authored Oct 8, 2020
2 parents 96dfa25 + 3d77a0d commit b0c97be
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ java -jar ar2dtool.jar -i PathToInputRdfFile -o FileToOutputFile -t OutputFileTy

- [-d] optional flag for debugging.

- [-tmp]: option flag to specify the temp folder.


AR2DTool Java API
===============
Expand Down Expand Up @@ -87,6 +89,12 @@ These are the list parameters that can be defined:
Two sample configuration files are available in the /samples folder. One creates and ER diagram of the ontology. The other one depicts the taxonomy of the classes.


## Contribution
### To compile and generate the JAR (LINUX)
1. `cd mavenProject`
2. `mvn compile; mvn install`
3. The jar will generated in `mavenProject/target`

Acknowledgements
===============

Expand Down
2 changes: 1 addition & 1 deletion mavenProject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>es.upm.oeg</groupId>
<artifactId>ar2dtool</artifactId>
<version>0.2.0</version>
<version>1.3.0</version>
<packaging>jar</packaging>

<name>ar2dtool</name>
Expand Down
44 changes: 35 additions & 9 deletions mavenProject/src/main/java/es/upm/oeg/ar2dtool/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.util.logging.Level;

import es.upm.oeg.ar2dtool.exceptions.ConfigKeyNotFound;
import es.upm.oeg.ar2dtool.exceptions.ConfigFileNotFoundException;
import es.upm.oeg.ar2dtool.exceptions.NullTripleMember;
import es.upm.oeg.ar2dtool.exceptions.RDFInputNotValid;
Expand Down Expand Up @@ -44,6 +45,7 @@ public class Main {
private static boolean GENERATE_GV = false;
private static boolean GENERATE_GML = false;
private static boolean COMPILE_GV = false;
private static String temp_dir = "";

public static void main(String[] args) {
parseArgs(args);
Expand All @@ -58,19 +60,24 @@ public static void main(String[] args) {
if(DEBUG)
{
logLevelToSee =Level.INFO;
//logLevelToSee =Level.ALL;
dbg("now in debug \n\n\n",Level.INFO);
}
else
{
logLevelToSee =Level.FINE;
}

log.getWriter().setVisibleLogLevel(logLevelToSee);

log("pathToInputFile:" + pathToInputFile);
log("pathToOuputFile:" + pathToOuputFile);
log("outputFileType:" + outputFileType);
log("pathToConfFile:" + pathToConfFile);








Expand All @@ -80,6 +87,16 @@ public static void main(String[] args) {

//load config info
r2d.loadConfigValues(pathToConfFile);
if(temp_dir!=""){
log("Setting the temp dir to: "+temp_dir);
try{
r2d.getConf().setKeys("pathToTempDir",temp_dir);
}
catch(ConfigKeyNotFound e){
log("Exception in setting the temp dir");
e.printStackTrace();
}
}

//print config values
log(r2d.getConf().toString());
Expand All @@ -104,19 +121,20 @@ public static void main(String[] args) {

//get the DOTGenerator with the resultant info
DOTGenerator dg = r2d.getDOTGenerator();

log("Got Dot Generator");
//apply transformations
dg.applyTransformations();

log("Applied Transformations");
//save the DOT source to file
dg.saveSourceToFile(pathToOuputFile+".dot");

log("Saved the .dot file");

log("Generated! Path="+pathToOuputFile+".dot");


if(COMPILE_GV)
{
log("Getting the DOT Source");
//get source DOT code
String src = dg.generateDOTSource();

Expand All @@ -139,14 +157,15 @@ public static void main(String[] args) {
{
//get the GraphMLGenerator with the resultant info
GraphMLGenerator gg = r2d.getGraphMLGenerator();

log("Getting GML");
//apply transformations
gg.applyTransformations();

log("GraphML source " + gg.generateGraphMLSource());

//save the GraphML source to file
gg.saveSourceToFile(pathToOuputFile+".graphml");
log("the Graphml is generated");
}


Expand Down Expand Up @@ -224,10 +243,16 @@ private static void parseArgs(String[] args) {
i++;
maxNumberOfTriples = Integer.valueOf(args[i]);
}
else
{
dbg(syntaxErrorMsg,Level.WARNING);
return;
else{
if(args[i].equals("-tmp")){
i++;
temp_dir = args[i];
}
else
{
dbg(syntaxErrorMsg,Level.WARNING);
return;
}
}
}
}
Expand All @@ -242,6 +267,7 @@ private static void parseArgs(String[] args) {

private static void log(String msg) {
log.getWriter().log(msg);
log.getWriter().log(msg,Level.INFO);
}

private static void dbg(String msg, Level logLevel){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private boolean includeStatement(Statement st)
*/
public boolean exceedsNumberOfTriples(int mnt)
{
return model.listStatements().toList().size() > mnt;
return model.listStatements().toList().size() > mnt && mnt!=-1;
}

public ConfigValues getConf() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,15 @@ public int generateDOTDiagram(String dotSource, String outPath, String type)
// String repesentationType= "sfdp";
// String repesentationType= "twopi";
// String repesentationType= "circo";

log("Will try writing to file: "+outPath);
File out = new File(outPath); // Linux
return gv.writeGraphToFile( gv.getGraph(gv.getDotSource(), type, repesentationType), out );
log("ask for Dot Source");
String dotSource1 = gv.getDotSource();
log("Ask for Graph from String");
//return gv.writeGraphToFile( gv.getGraph(gv.getDotSource(), type, repesentationType), out );
byte[] gvGraph = gv.getGraph(dotSource1, type, repesentationType);
log("Got the graph");
return gv.writeGraphToFile(gvGraph, out);
}

private void generateSyntObjPropertiesTriples() throws NullTripleMember
Expand Down Expand Up @@ -548,6 +554,7 @@ public void setModel(OntModel model) {
private void log(String msg)
{
log.getWriter().log(msg);
log.getWriter().log(msg, Level.INFO);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public byte[] getGraph(String dot_source, String type, String representationType
byte[] img_stream = null;

try {
logger.getWriter().log("write dot source to file: "+dot_source, Level.INFO);
dot = writeDotSourceToFile(dot_source);
if (dot != null)
{
Expand Down Expand Up @@ -326,6 +327,7 @@ private File writeDotSourceToFile(String str) throws java.io.IOException
{
File temp;
try {
logger.getWriter().log("TEMP DIR: "+GraphViz.TEMP_DIR, Level.INFO);
temp = File.createTempFile("graph_", ".dot.tmp", new File(GraphViz.TEMP_DIR));
FileWriter fout = new FileWriter(temp);
fout.write(str);
Expand Down

0 comments on commit b0c97be

Please sign in to comment.