From 5be5fd3daa0d50980fb3791e904e035cdbca254f Mon Sep 17 00:00:00 2001 From: RncLsn Date: Thu, 7 May 2015 19:26:24 +0100 Subject: Making the output machine-readable (JSON). --- .../Maven__com_google_code_gson_gson_2_3_1.xml | 13 ++ ...om_googlecode_json_simple_json_simple_1_1_1.xml | 13 ++ pom.xml | 10 ++ src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java | 41 +++-- src/uk/ac/ox/cs/pagoda/query/QueryRecord.java | 191 +++++++++++++++------ src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java | 67 ++++---- src/uk/ac/ox/cs/pagoda/util/Utility.java | 39 +---- .../ac/ox/cs/pagoda/test_units/CostEvaluation.java | 44 +++-- .../uk/ac/ox/cs/pagoda/test_units/JAIR_PAGOdA.java | 143 ++++++++------- .../ox/cs/pagoda/test_units/JAIR_Scalability.java | 33 ++-- .../ox/cs/pagoda/test_units/LightEvaluation.java | 45 ++--- .../ac/ox/cs/pagoda/test_units/PagodaDBPedia.java | 16 +- test/uk/ac/ox/cs/pagoda/test_units/PagodaELU.java | 10 +- test/uk/ac/ox/cs/pagoda/test_units/PagodaFLY.java | 7 +- test/uk/ac/ox/cs/pagoda/test_units/PagodaLUBM.java | 64 ++----- test/uk/ac/ox/cs/pagoda/test_units/PagodaNPD.java | 25 +-- .../ox/cs/pagoda/test_units/PagodaNPD_bench.java | 16 +- test/uk/ac/ox/cs/pagoda/test_units/PagodaRLU.java | 12 +- test/uk/ac/ox/cs/pagoda/test_units/PagodaUOBM.java | 75 ++------ .../pagoda/test_units/TestGlobalCorrectness.java | 55 ++++++ test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java | 16 +- test/uk/ac/ox/cs/pagoda/util/TestUtil.java | 64 +++++++ 22 files changed, 588 insertions(+), 411 deletions(-) create mode 100644 .idea/libraries/Maven__com_google_code_gson_gson_2_3_1.xml create mode 100644 .idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml create mode 100644 test/uk/ac/ox/cs/pagoda/test_units/TestGlobalCorrectness.java create mode 100644 test/uk/ac/ox/cs/pagoda/util/TestUtil.java diff --git a/.idea/libraries/Maven__com_google_code_gson_gson_2_3_1.xml b/.idea/libraries/Maven__com_google_code_gson_gson_2_3_1.xml new file mode 100644 index 0000000..d7b5038 --- /dev/null +++ b/.idea/libraries/Maven__com_google_code_gson_gson_2_3_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml b/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml new file mode 100644 index 0000000..f3f3738 --- /dev/null +++ b/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 096a14d..c6d3bb0 100644 --- a/pom.xml +++ b/pom.xml @@ -108,5 +108,15 @@ testng 6.7 + + com.googlecode.json-simple + json-simple + 1.1.1 + + + com.google.code.gson + gson + 2.3.1 + diff --git a/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java b/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java index 8d7e0b1..183cbe1 100644 --- a/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java +++ b/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java @@ -1,13 +1,10 @@ package uk.ac.ox.cs.pagoda.query; -import java.util.HashMap; -import java.util.Map; - +import com.google.gson.*; import org.semanticweb.HermiT.model.Constant; import org.semanticweb.HermiT.model.Individual; import org.semanticweb.HermiT.model.Term; import org.semanticweb.HermiT.model.Variable; - import uk.ac.ox.cs.JRDFox.JRDFStoreException; import uk.ac.ox.cs.JRDFox.model.Datatype; import uk.ac.ox.cs.JRDFox.model.GroundTerm; @@ -15,6 +12,10 @@ import uk.ac.ox.cs.JRDFox.model.Literal; import uk.ac.ox.cs.JRDFox.store.TupleIterator; import uk.ac.ox.cs.pagoda.util.Namespace; +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.Map; + public class AnswerTuple { public static final String SEPARATOR = "\t"; @@ -40,17 +41,21 @@ public class AnswerTuple { m_tuple = new GroundTerm[arity]; for (int i = 0; i < arity; ++i) m_tuple[i] = sup.m_tuple[i]; } + + private AnswerTuple(String m_str) { + this.m_str = m_str; + } public int getArity() { return m_tuple.length; } public int hashCode() { -// return toString().hashCode(); - int code = 0; - for (int i = 0; i < m_tuple.length; ++i) - code = code * 1997 + m_tuple[i].hashCode(); - return code; + return toString().hashCode(); +// int code = 0; +// for (int i = 0; i < m_tuple.length; ++i) +// code = code * 1997 + m_tuple[i].hashCode(); +// return code; } public boolean equals(Object obj) { @@ -131,5 +136,21 @@ public class AnswerTuple { if (length == extendedTuple.getArity()) return extendedTuple; else return new AnswerTuple(extendedTuple, length); } - + + + public static class AnswerTupleSerializer implements JsonSerializer { + + public JsonElement serialize(AnswerTuple src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toString()); + } + + } + + public class AnswerTupleDeserializer implements JsonDeserializer { + public AnswerTuple deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + return new AnswerTuple(json.getAsJsonPrimitive().getAsString()); + } + } + } diff --git a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java index ce92a67..4b55046 100644 --- a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java +++ b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java @@ -1,37 +1,9 @@ package uk.ac.ox.cs.pagoda.query; -import java.io.BufferedWriter; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; -import java.util.Set; - -import org.semanticweb.HermiT.model.Atom; -import org.semanticweb.HermiT.model.AtomicConcept; -import org.semanticweb.HermiT.model.AtomicRole; -import org.semanticweb.HermiT.model.DLClause; -import org.semanticweb.HermiT.model.DLPredicate; -import org.semanticweb.HermiT.model.Variable; -import org.semanticweb.owlapi.model.OWLAxiom; -import org.semanticweb.owlapi.model.OWLClass; -import org.semanticweb.owlapi.model.OWLClassAssertionAxiom; -import org.semanticweb.owlapi.model.OWLDataProperty; -import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom; -import org.semanticweb.owlapi.model.OWLIndividual; -import org.semanticweb.owlapi.model.OWLLiteral; -import org.semanticweb.owlapi.model.OWLObjectProperty; -import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom; -import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.model.OWLOntologyManager; -import org.semanticweb.owlapi.model.OWLOntologyStorageException; - +import com.google.gson.*; +import com.google.gson.reflect.TypeToken; +import org.semanticweb.HermiT.model.*; +import org.semanticweb.owlapi.model.*; import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxAnswerTuples; import uk.ac.ox.cs.pagoda.rules.GeneralProgram; @@ -39,6 +11,10 @@ import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper; import uk.ac.ox.cs.pagoda.util.Namespace; import uk.ac.ox.cs.pagoda.util.Utility; +import java.io.*; +import java.lang.reflect.Type; +import java.util.*; + public class QueryRecord { public static final String botQueryText = "SELECT ?X WHERE { ?X }"; @@ -47,11 +23,12 @@ public class QueryRecord { private String queryText; private int queryID = -1; - private String[][] answerVariables = null; - private Set soundAnswerTuples = new HashSet(); + + private String[][] answerVariables = null; + private Set soundAnswerTuples = new HashSet(); private Set gapAnswerTuples = null; - private QueryManager m_manager; + private QueryManager m_manager; public QueryRecord(QueryManager manager, String text, int id, int subID) { m_manager =manager; @@ -178,7 +155,7 @@ public class QueryRecord { // str.contains("internal:def"); // } - boolean processed = false; + boolean processed = false; public void markAsProcessed() { processed = true; @@ -205,7 +182,7 @@ public class QueryRecord { return queryText; } - String stringQueryID = null; + String stringQueryID = null; public String getQueryID() { return stringQueryID; @@ -233,27 +210,27 @@ public class QueryRecord { writer.newLine(); writer.write(queryText); writer.newLine(); - StringBuilder space = new StringBuilder(); - int arity = getArity(), varSpace = 0; + StringBuilder space = new StringBuilder(); + int arity = getArity(), varSpace = 0; for (int i = 0; i < arity; ++i) - varSpace += answerVariables[0][i].length(); + varSpace += answerVariables[0][i].length(); for (int i = 0; i < (SEPARATOR.length() - varSpace) / (arity + 1); ++i) - space.append(" "); + space.append(" "); for (int i = 0; i < getArity(); ++i) { writer.write(space.toString()); writer.write(answerVariables[0][i]); } writer.newLine(); writer.write(SEPARATOR); - writer.newLine(); + writer.newLine(); for (AnswerTuple tuple: soundAnswerTuples) { - writer.write(tuple.toString()); + writer.write(tuple.toString()); writer.newLine(); } if (!processed()) for (AnswerTuple tuple: gapAnswerTuples) { writer.write("*"); - writer.write(tuple.toString()); + writer.write(tuple.toString()); writer.newLine(); } // writer.write(SEPARATOR); @@ -261,6 +238,38 @@ public class QueryRecord { } } + + public void outputAnswerStatistics() { + + int answerCounter = soundAnswerTuples.size(); + if (!processed()) answerCounter += gapAnswerTuples.size(); + + Utility.logInfo("The number of answer tuples: " + answerCounter); +// if (jsonAnswers != null) { +// JSONObject jsonAnswer = new JSONObject(); +// +// jsonAnswer.put("queryID", queryID); +// jsonAnswer.put("queryText", queryText); +// +// JSONArray answerVars = new JSONArray(); +// int arity = getArity(), varSpace = 0; +// for (int i = 0; i < getArity(); i++) +// answerVars.add(answerVariables[0][i]); +// jsonAnswer.put("answerVars", answerVars); +// +// JSONArray answerTuples = new JSONArray(); +// soundAnswerTuples.stream().forEach(t -> answerTuples.add(t)); +// jsonAnswer.put("answerTuples", answerTuples); +// +// if (!processed) { +// JSONArray gapAnswerTuples = new JSONArray(); +// gapAnswerTuples.stream().forEach(t -> gapAnswerTuples.add(t)); +// } +// jsonAnswer.put("gapAnswerTuples", gapAnswerTuples); +// +// jsonAnswers.put(Integer.toString(queryID), jsonAnswer); +// } + } public void outputTimes() { for (Step step: Step.values()) { @@ -290,8 +299,8 @@ public class QueryRecord { return diffculty; } - OWLOntology relevantOntology = null; - Set relevantClauses = new HashSet(); + OWLOntology relevantOntology = null; + Set relevantClauses = new HashSet(); public void setRelevantOntology(OWLOntology knowledgebase) { relevantOntology = knowledgebase; @@ -355,7 +364,7 @@ public class QueryRecord { public enum Step {LowerBound, UpperBound, ELLowerBound, Fragment, FragmentRefinement, Summarisation, Dependency, FullReasoning}; - double[] timer; + double[] timer; public void addProcessingTime(Step step, double time) { timer[step.ordinal()] += time; @@ -431,14 +440,14 @@ public class QueryRecord { } } - int subID; + int subID; public void updateSubID() { ++subID; stringQueryID = String.valueOf(queryID) + "_" + subID; } - DLClause queryClause = null; + DLClause queryClause = null; public DLClause getClause() { if (queryClause != null) @@ -557,6 +566,88 @@ public class QueryRecord { public boolean hasNonAnsDistinguishedVariables() { return answerVariables[1].length > answerVariables[0].length; } - + public static class QueryRecordSerializer implements JsonSerializer { + + public JsonElement serialize(QueryRecord src, Type typeOfSrc, JsonSerializationContext context) { + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + JsonObject object = new JsonObject(); + object.addProperty("queryID", src.queryID); + object.addProperty("queryText", src.queryText); + object.addProperty("difficulty", src.diffculty.toString()); + + object.add("answerVariables", context.serialize(src.getAnswerVariables())); + object.add("answers", context.serialize(src.soundAnswerTuples)); + object.add("gapAnswers", context.serialize(src.gapAnswerTuples)); + + return object; + } + } + + private QueryRecord() { } + + public class QueryRecordDeserializer implements JsonDeserializer { + + public QueryRecord deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + + QueryRecord record = new QueryRecord(); + JsonObject object = json.getAsJsonObject(); + record.queryID = object.getAsJsonPrimitive("queryID").getAsInt(); + record.queryText = object.getAsJsonPrimitive("queryText").getAsString(); + + JsonArray answerVariablesJson = object.getAsJsonArray("answerVariables"); + record.answerVariables = new String[2][]; + record.answerVariables[0] = new String[answerVariablesJson.size()]; + for(int i = 0; i < answerVariablesJson.size(); i++) + record.answerVariables[0][i] = answerVariablesJson.get(i).getAsString(); + + record.soundAnswerTuples = context.deserialize(object.getAsJsonObject("answers"), + new TypeToken>() {}.getType()); + + record.gapAnswerTuples = context.deserialize(object.getAsJsonObject("gapAnswers"), + new TypeToken>() {}.getType()); + return null; + } + } + + /* + * Two QueryRecords are equal iff + * they have the same queryText and + * their AnswerTuples have the same string representation + * */ + @Override + public boolean equals(Object o) { + if(!o.getClass().equals(getClass())) return false; + QueryRecord that = (QueryRecord) o; + + if(!this.queryText.equals(that.queryText)) return false; + + if(soundAnswerTuples.size() != that.soundAnswerTuples.size()) return false; + if(gapAnswerTuples.size() != that.gapAnswerTuples.size()) return false; + + ArrayList thisSoundAnswers = new ArrayList<>(soundAnswerTuples); + Collections.sort(thisSoundAnswers, (AnswerTuple t1, AnswerTuple t2) -> t1.m_str.compareTo(t2.m_str)); + + ArrayList thatSoundAnswers = new ArrayList<>(that.soundAnswerTuples); + Collections.sort(thatSoundAnswers, (AnswerTuple t1, AnswerTuple t2) -> t1.m_str.compareTo(t2.m_str)); + + Iterator soundIt1 = this.soundAnswerTuples.iterator(); + Iterator soundIt2 = that.soundAnswerTuples.iterator(); + while(soundIt1.hasNext() && soundIt2.hasNext()) + if(!soundIt1.next().m_str.equals(soundIt2.next().m_str)) return false; + + ArrayList thisGapAnswers = new ArrayList<>(gapAnswerTuples); + Collections.sort(thisGapAnswers, (AnswerTuple t1, AnswerTuple t2) -> t1.m_str.compareTo(t2.m_str)); + + ArrayList thatGapAnswers = new ArrayList<>(that.gapAnswerTuples); + Collections.sort(thatGapAnswers, (AnswerTuple t1, AnswerTuple t2) -> t1.m_str.compareTo(t2.m_str)); + + Iterator gapIt1 = this.gapAnswerTuples.iterator(); + Iterator gapIt2 = that.gapAnswerTuples.iterator(); + while(gapIt1.hasNext() && gapIt2.hasNext()) + if(!gapIt1.next().m_str.equals(gapIt2.next().m_str)) return false; + + return true; + } } diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java index f2b7251..1f08fdf 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java @@ -1,16 +1,10 @@ package uk.ac.ox.cs.pagoda.reasoner; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.util.Collection; - +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import org.semanticweb.owlapi.model.OWLOntology; - import uk.ac.ox.cs.pagoda.owl.OWLHelper; +import uk.ac.ox.cs.pagoda.query.AnswerTuple; import uk.ac.ox.cs.pagoda.query.AnswerTuples; import uk.ac.ox.cs.pagoda.query.QueryManager; import uk.ac.ox.cs.pagoda.query.QueryRecord; @@ -18,6 +12,13 @@ import uk.ac.ox.cs.pagoda.util.Properties; import uk.ac.ox.cs.pagoda.util.Timer; import uk.ac.ox.cs.pagoda.util.Utility; +import java.io.BufferedWriter; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collection; + public abstract class QueryReasoner { // protected boolean forSemFacet = false; @@ -179,28 +180,33 @@ public abstract class QueryReasoner { } +// public void evaluate(Collection queryRecords) { +// evaluate(queryRecords); +// } + + BufferedWriter answerWriter = null; + public void evaluate(Collection queryRecords) { - evaluate(queryRecords, null); - } - - BufferedWriter answerWriter = null; - - public void evaluate(Collection queryRecords, String answerFile) { if (!isConsistent()) { Utility.logDebug("The ontology and dataset is inconsistent."); return ; } - - if (answerWriter == null && answerFile != null) { + + if(properties.getAnswerPath() != null && answerWriter == null) { try { - answerWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(answerFile))); - } catch (FileNotFoundException e) { - Utility.logInfo("The answer file not found! " + answerFile); - return ; - } + answerWriter = Files.newBufferedWriter(Paths.get(properties.getAnswerPath())); + } catch (IOException e) { + Utility.logError("The answer path is not valid!"); + e.printStackTrace(); + } } - Timer t = new Timer(); + Timer t = new Timer(); + Gson gson = new GsonBuilder() + .registerTypeAdapter(AnswerTuple.class, new AnswerTuple.AnswerTupleSerializer()) + .registerTypeAdapter(QueryRecord.class, new QueryRecord.QueryRecordSerializer()) + .setPrettyPrinting() + .create(); for (QueryRecord record: queryRecords) { // if (Integer.parseInt(record.getQueryID()) != 218) continue; Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", @@ -215,24 +221,23 @@ public abstract class QueryReasoner { continue; } } - // FIXME: change the argument below - try { - record.outputAnswers(answerWriter); - } catch (IOException e) { - Utility.logInfo("Error in outputing answers " + answerFile); - } + record.outputAnswerStatistics(); record.outputTimes(); - record.dispose(); } + // TODO it can handle one call only + // if you call twice, you will end up with a json file with multiple roots + gson.toJson(queryRecords, answerWriter); + queryRecords.stream().forEach(record -> record.dispose()); } public void dispose() { - if (answerWriter != null) + if (answerWriter != null) { try { answerWriter.close(); } catch (IOException e) { e.printStackTrace(); } + } Utility.cleanup(); } diff --git a/src/uk/ac/ox/cs/pagoda/util/Utility.java b/src/uk/ac/ox/cs/pagoda/util/Utility.java index 7138ca9..6d50ee0 100644 --- a/src/uk/ac/ox/cs/pagoda/util/Utility.java +++ b/src/uk/ac/ox/cs/pagoda/util/Utility.java @@ -1,32 +1,13 @@ package uk.ac.ox.cs.pagoda.util; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintStream; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.text.SimpleDateFormat; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Collection; -import java.util.Date; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Scanner; -import java.util.Set; -import java.util.Stack; - import org.apache.log4j.Logger; import org.semanticweb.HermiT.model.Atom; -import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import java.io.*; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; public class Utility { @@ -259,14 +240,4 @@ public class Utility { return iri.replace(FILE_SEPARATOR, JAVA_FILE_SEPARATOR).replace(" ", "%20"); } - public static String combinePaths(String path1, String path2) { - File file1 = new File(path1); - File file2 = new File(file1, path2); - return file2.getPath(); - } - - public static void copyFile(String src, String dst) throws IOException { - Files.copy(Paths.get(src), Paths.get(dst), REPLACE_EXISTING); - } - } diff --git a/test/uk/ac/ox/cs/pagoda/test_units/CostEvaluation.java b/test/uk/ac/ox/cs/pagoda/test_units/CostEvaluation.java index 4e32297..968cf01 100644 --- a/test/uk/ac/ox/cs/pagoda/test_units/CostEvaluation.java +++ b/test/uk/ac/ox/cs/pagoda/test_units/CostEvaluation.java @@ -1,12 +1,12 @@ package uk.ac.ox.cs.pagoda.test_units; import org.semanticweb.owlapi.model.OWLOntology; - import org.testng.annotations.Test; import uk.ac.ox.cs.pagoda.owl.OWLHelper; import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner.Type; import uk.ac.ox.cs.pagoda.tester.PagodaTester; +import uk.ac.ox.cs.pagoda.util.TestUtil; import uk.ac.ox.cs.pagoda.util.Timer; import uk.ac.ox.cs.pagoda.util.Utility; @@ -15,20 +15,22 @@ public class CostEvaluation { @Test public void lubm100() { int number = 1; + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "lubm/univ-bench.owl", - PagodaTester.onto_dir + "lubm/data/lubm" + number + ".ttl", - PagodaTester.onto_dir + "lubm/queries/test_all_pagoda.sparql" + TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), + TestUtil.combinePaths(ontoDir, "lubm/data/lubm" + number + ".ttl"), + TestUtil.combinePaths(ontoDir, "lubm/queries/test_all_pagoda.sparql") ); // AllTests.copy("output/log4j.log", "results-backup/jair/lubm" + number + ".out"); } public void lubm1000() { int number = 1000; + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "lubm/univ-bench.owl", - PagodaTester.onto_dir + "lubm/data/lubm" + number + ".ttl", - PagodaTester.onto_dir + "lubm/queries/test_all_pagoda.sparql" + TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), + TestUtil.combinePaths(ontoDir, "lubm/data/lubm" + number + ".ttl"), + TestUtil.combinePaths(ontoDir, "lubm/queries/test_all_pagoda.sparql") }; OWLOntology ontology = OWLHelper.loadOntology(args[0]); QueryReasoner reasoner = QueryReasoner.getInstance(Type.ELHOU, ontology, true, true); @@ -46,10 +48,11 @@ public class CostEvaluation { @Test public void uobm5() { int number = 1; + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "uobm/univ-bench-dl.owl", - PagodaTester.onto_dir + "uobm/data/uobm" + number + ".ttl", - PagodaTester.onto_dir + "uobm/queries/standard_all_pagoda.sparql" + TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), + TestUtil.combinePaths(ontoDir, "uobm/data/uobm" + number + ".ttl"), + TestUtil.combinePaths(ontoDir, "uobm/queries/standard_all_pagoda.sparql") }; PagodaTester.main(args); // AllTests.copy("output/log4j.log", "results-backup/jair/uobm" + number + ".out"); @@ -57,10 +60,11 @@ public class CostEvaluation { public void uobm100() { int number = 200; + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "uobm/univ-bench-dl.owl", - PagodaTester.onto_dir + "uobm/data/uobm" + number + ".ttl", - PagodaTester.onto_dir + "uobm/queries/standard_group3_all.sparql" + TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), + TestUtil.combinePaths(ontoDir, "uobm/data/uobm" + number + ".ttl"), + TestUtil.combinePaths(ontoDir, "uobm/queries/standard_group3_all.sparql") }; PagodaTester.main(args); // AllTests.copy("output/log4j.log", "results-backup/jair/uobm" + number + ".out"); @@ -68,10 +72,11 @@ public class CostEvaluation { public void uobm500() { int number = 500; + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "uobm/univ-bench-dl.owl", - PagodaTester.onto_dir + "uobm/data/uobm" + number + ".ttl", - PagodaTester.onto_dir + "uobm/queries/standard_all_pagoda.sparql" + TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), + TestUtil.combinePaths(ontoDir, "uobm/data/uobm" + number + ".ttl"), + TestUtil.combinePaths(ontoDir, "uobm/queries/standard_all_pagoda.sparql") }; OWLOntology ontology = OWLHelper.loadOntology(args[0]); @@ -89,10 +94,11 @@ public class CostEvaluation { public static void main(String... args) { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); args = new String[] { - PagodaTester.onto_dir + "dbpedia/integratedOntology-all-in-one-minus-datatype.owl", - PagodaTester.onto_dir + "dbpedia/data/dbpedia-minus-datatype-new.ttl", - PagodaTester.onto_dir + "dbpedia/queries/atomic_ground.sparql" + TestUtil.combinePaths(ontoDir, "dbpedia/integratedOntology-all-in-one-minus-datatype.owl"), + TestUtil.combinePaths(ontoDir, "dbpedia/data/dbpedia-minus-datatype-new.ttl"), + TestUtil.combinePaths(ontoDir, "dbpedia/queries/atomic_ground.sparql") }; OWLOntology ontology = OWLHelper.loadOntology(args[0]); diff --git a/test/uk/ac/ox/cs/pagoda/test_units/JAIR_PAGOdA.java b/test/uk/ac/ox/cs/pagoda/test_units/JAIR_PAGOdA.java index ff616f7..10ac974 100644 --- a/test/uk/ac/ox/cs/pagoda/test_units/JAIR_PAGOdA.java +++ b/test/uk/ac/ox/cs/pagoda/test_units/JAIR_PAGOdA.java @@ -2,7 +2,7 @@ package uk.ac.ox.cs.pagoda.test_units; import org.testng.annotations.Test; import uk.ac.ox.cs.pagoda.tester.PagodaTester; -import uk.ac.ox.cs.pagoda.util.Utility; +import uk.ac.ox.cs.pagoda.util.TestUtil; import java.io.IOException; @@ -10,162 +10,175 @@ public class JAIR_PAGOdA { @Test public void lubm1() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "lubm/univ-bench.owl", - PagodaTester.onto_dir + "lubm/data/lubm1.ttl", - PagodaTester.onto_dir + "lubm/queries/test.sparql" + TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), + TestUtil.combinePaths(ontoDir, "lubm/data/lubm1.ttl"), + TestUtil.combinePaths(ontoDir, "lubm/queries/test.sparql") }; PagodaTester.main(args); - Utility.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/lubm1/pagoda"); + TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/lubm1/pagoda"); } @Test public void lubm1_conj() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "lubm/univ-bench.owl", - PagodaTester.onto_dir + "lubm/data/lubm1.ttl", - PagodaTester.onto_dir + "lubm/queries/test_pellet.sparql" + TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), + TestUtil.combinePaths(ontoDir, "lubm/data/lubm1.ttl"), + TestUtil.combinePaths(ontoDir, "lubm/queries/test_pellet.sparql") }; PagodaTester.main(args); - Utility.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/lubm1/pagoda_conj"); + TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/lubm1/pagoda_conj"); } @Test public void lubm1_rolledUp() throws IOException { - String[] args = new String[] { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); + PagodaTester.main( "/home/yzhou/backup/20141212/univ-bench-queries.owl", - PagodaTester.onto_dir + "lubm/data/lubm1.ttl", - PagodaTester.onto_dir + "lubm/queries/atomic_lubm.sparql" - }; - PagodaTester.main(args); - Utility.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/lubm1/pagoda_rolledUp"); + TestUtil.combinePaths(ontoDir, "lubm/data/lubm1.ttl"), + TestUtil.combinePaths(ontoDir, "lubm/queries/atomic_lubm.sparql") + ); + TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/lubm1/pagoda_rolledUp"); } @Test public void uobm1() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "uobm/univ-bench-dl.owl", - PagodaTester.onto_dir + "uobm/data/uobm1.ttl", - PagodaTester.onto_dir + "uobm/queries/standard.sparql" + TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), + TestUtil.combinePaths(ontoDir, "uobm/data/uobm1.ttl"), + TestUtil.combinePaths(ontoDir, "uobm/queries/standard.sparql") }; PagodaTester.main(args); - Utility.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uobm1/pagoda"); + TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uobm1/pagoda"); } @Test public void uobm1_conj() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "uobm/univ-bench-dl.owl", - PagodaTester.onto_dir + "uobm/data/uobm1.ttl", - PagodaTester.onto_dir + "uobm/queries/standard_pellet.sparql" + TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), + TestUtil.combinePaths(ontoDir, "uobm/data/uobm1.ttl"), + TestUtil.combinePaths(ontoDir, "uobm/queries/standard_pellet.sparql") }; PagodaTester.main(args); - Utility.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uobm1/pagoda_conj"); + TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uobm1/pagoda_conj"); } @Test public void uobm1_rolledUp() { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { "/home/yzhou/backup/20141212/univ-bench-dl-queries.owl", - PagodaTester.onto_dir + "uobm/data/uobm1.ttl", - PagodaTester.onto_dir + "uobm/queries/atomic_uobm.sparql" + TestUtil.combinePaths(ontoDir, "uobm/data/uobm1.ttl"), + TestUtil.combinePaths(ontoDir, "uobm/queries/atomic_uobm.sparql") }; PagodaTester.main(args); -// AllTests.copy("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uobm1/pagoda_rolledUp"); +// TestUtil.copyFile(("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uobm1/pagoda_rolledUp"); } @Test public void fly() { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", + TestUtil.combinePaths(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl"), null, - PagodaTester.onto_dir + "fly/queries/fly_pellet.sparql" + TestUtil.combinePaths(ontoDir, "fly/queries/fly_pellet.sparql") }; PagodaTester.main(args); -// AllTests.copy("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/fly/pagoda"); +// TestUtil.copyFile(("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/fly/pagoda"); } @Test public void fly_conj() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", + TestUtil.combinePaths(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl"), null, - PagodaTester.onto_dir + "fly/queries/fly_pellet.sparql" + TestUtil.combinePaths(ontoDir, "fly/queries/fly_pellet.sparql") }; PagodaTester.main(args); - Utility.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/fly/pagoda_conj"); + TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/fly/pagoda_conj"); } public void fly_rolledUp() { - PagodaTester.main(new String[] { -// PagodaTester.onto_dir + "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", - PagodaTester.onto_dir + "fly/fly-all-in-one_rolledUp.owl", + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); + PagodaTester.main( +// TestUtil.combinePaths(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", + TestUtil.combinePaths(ontoDir, "fly/fly-all-in-one_rolledUp.owl"), null, - PagodaTester.onto_dir + "fly/queries/fly_atomic.sparql" - }); -// Utility.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/fly/pagoda_rolledUp"); + TestUtil.combinePaths(ontoDir, "fly/queries/fly_atomic.sparql") + ); +// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/fly/pagoda_rolledUp"); } public void dbpedia() { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "dbpedia/integratedOntology-all-in-one-minus-datatype.owl", - PagodaTester.onto_dir + "dbpedia/data/dbpedia-minus-datatype-new.ttl", - PagodaTester.onto_dir + "dbpedia/queries/atomic_ground.sparql" - , "dbpedia.ans" + TestUtil.combinePaths(ontoDir, "dbpedia/integratedOntology-all-in-one-minus-datatype.owl"), + TestUtil.combinePaths(ontoDir, "dbpedia/data/dbpedia-minus-datatype-new.ttl"), + TestUtil.combinePaths(ontoDir, "dbpedia/queries/atomic_ground.sparql"), + "dbpedia.ans" ); -// Utility.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/dbpedia/pagoda"); +// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/dbpedia/pagoda"); } public void npd() { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "npd/npd-all-minus-datatype.owl", - PagodaTester.onto_dir + "npd/data/npd-data-dump-minus-datatype-new.ttl", - PagodaTester.onto_dir + "npd/queries/atomic_ground.sparql" + TestUtil.combinePaths(ontoDir, "npd/npd-all-minus-datatype.owl"), + TestUtil.combinePaths(ontoDir, "npd/data/npd-data-dump-minus-datatype-new.ttl"), + TestUtil.combinePaths(ontoDir, "npd/queries/atomic_ground.sparql") , "npd.ans" ); -// Utility.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/npd/pagoda"); +// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/npd/pagoda"); } public void reactome() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "bio2rdf/reactome/biopax-level3-processed.owl", - PagodaTester.onto_dir + "bio2rdf/reactome/graph sampling/reactome_sample_10.ttl", + TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/biopax-level3-processed.owl"), + TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/graph sampling/reactome_sample_10.ttl"), // null, -// PagodaTester.onto_dir + "bio2rdf/reactome/queries/atomic_ground.sparql" - PagodaTester.onto_dir + "bio2rdf/reactome/queries/example.sparql" +// TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/queries/atomic_ground.sparql") + TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/queries/example.sparql") , "pagoda_reactome.ans" ); - Utility.copyFile("log4j.log", "output/jair/pagoda_reactome.example"); + TestUtil.copyFile("log4j.log", "output/jair/pagoda_reactome.example"); -// AllTests.copy("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/reactome/pagoda_10p"); +// TestUtil.copyFile(("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/reactome/pagoda_10p"); } public void chembl() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "bio2rdf/chembl/cco-noDPR.ttl", - PagodaTester.onto_dir + "bio2rdf/chembl/graph sampling/sample_1.nt", -// PagodaTester.onto_dir + "bio2rdf/chembl/queries/atomic_ground.sparql" - PagodaTester.onto_dir + "bio2rdf/chembl/queries/example.sparql" + TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/cco-noDPR.ttl"), + TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/graph sampling/sample_1.nt"), +// TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/queries/atomic_ground.sparql") + TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/queries/example.sparql") , "pagoda_chembl.ans" ); - Utility.copyFile("log4j.log", "output/jair/pagoda_chembl.example"); -// Utility.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/chembl/pagoda_1p"); + TestUtil.copyFile("log4j.log", "output/jair/pagoda_chembl.example"); +// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/chembl/pagoda_1p"); } public void uniprot() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "bio2rdf/uniprot/core-sat-processed.owl", - PagodaTester.onto_dir + "bio2rdf/uniprot/graph sampling/sample_1.nt", + TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/core-sat-processed.owl"), + TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/graph sampling/sample_1.nt"), // null, -// PagodaTester.onto_dir + "bio2rdf/uniprot/queries/atomic_ground.sparql" - PagodaTester.onto_dir + "bio2rdf/uniprot/queries/example.sparql" +// TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/queries/atomic_ground.sparql") + TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/queries/example.sparql") , "pagoda_uniprot.ans" ); - Utility.copyFile("log4j.log", "output/jair/pagoda_uniprot.example"); -// AllTests.copy("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uniprot/pagoda_1p"); + TestUtil.copyFile("log4j.log", "output/jair/pagoda_uniprot.example"); +// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uniprot/pagoda_1p"); } diff --git a/test/uk/ac/ox/cs/pagoda/test_units/JAIR_Scalability.java b/test/uk/ac/ox/cs/pagoda/test_units/JAIR_Scalability.java index 43cb810..2cf8446 100644 --- a/test/uk/ac/ox/cs/pagoda/test_units/JAIR_Scalability.java +++ b/test/uk/ac/ox/cs/pagoda/test_units/JAIR_Scalability.java @@ -3,7 +3,7 @@ package uk.ac.ox.cs.pagoda.test_units; import org.testng.annotations.Test; import uk.ac.ox.cs.pagoda.tester.PagodaTester; import uk.ac.ox.cs.pagoda.util.Properties; -import uk.ac.ox.cs.pagoda.util.Utility; +import uk.ac.ox.cs.pagoda.util.TestUtil; import java.io.IOException; @@ -27,10 +27,11 @@ public class JAIR_Scalability { } public void testReactome(int percentage, boolean save) throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "bio2rdf/reactome/biopax-level3-processed.owl", - PagodaTester.onto_dir + "bio2rdf/reactome/graph sampling/simplifed_sample_" + percentage + ".ttl", - PagodaTester.onto_dir + "bio2rdf/reactome/queries/test.sparql" + TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/biopax-level3-processed.owl"), + TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/graph sampling/simplifed_sample_" + percentage + ".ttl"), + TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/queries/test.sparql") , "reactome.ans" }; if (percentage == 10) @@ -38,15 +39,16 @@ public class JAIR_Scalability { PagodaTester.main(args); if (save) - Utility.copyFile("log4j.log", "/home/yzhou/java-workspace/test-share/results_new/reactome/pagoda_" + percentage + "p" + date); + TestUtil.copyFile("log4j.log", "/home/yzhou/java-workspace/test-share/results_new/reactome/pagoda_" + percentage + "p" + date); } public void testChEMBL(int percentage, boolean save) throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "bio2rdf/chembl/cco-noDPR.ttl", - PagodaTester.onto_dir + "bio2rdf/chembl/sample_" + percentage + ".nt", -// PagodaTester.onto_dir + "bio2rdf/chembl/queries/atomic_ground.sparql" - PagodaTester.onto_dir + "bio2rdf/chembl/queries/test.sparql" + TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/cco-noDPR.ttl"), + TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/sample_" + percentage + ".nt"), +// TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/queries/atomic_ground.sparql") + TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/queries/test.sparql") , "chembl.ans" }; if (percentage == 1 || percentage == 10 || percentage == 50) @@ -57,15 +59,16 @@ public class JAIR_Scalability { PagodaTester.main(args); if (save) - Utility.copyFile("log4j.log", "/home/yzhou/java-workspace/test-share/results_new/chembl/pagoda_" + percentage + "p" + date); + TestUtil.copyFile("log4j.log", "/home/yzhou/java-workspace/test-share/results_new/chembl/pagoda_" + percentage + "p" + date); } public void testUniProt(int percentage, boolean save) throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { - PagodaTester.onto_dir + "bio2rdf/uniprot/core-sat-processed.owl", - PagodaTester.onto_dir + "bio2rdf/uniprot/sample_" + percentage + ".nt", -// PagodaTester.onto_dir + "bio2rdf/uniprot/queries/atomic_ground.sparql" - PagodaTester.onto_dir + "bio2rdf/uniprot/queries/test.sparql" + TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/core-sat-processed.owl"), + TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/sample_" + percentage + ".nt"), +// TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/queries/atomic_ground.sparql") + TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/queries/test.sparql") , "uniprot.ans" }; @@ -77,7 +80,7 @@ public class JAIR_Scalability { PagodaTester.main(args); if (save) - Utility.copyFile("log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uniprot/pagoda_" + percentage + "p" + date); + TestUtil.copyFile("log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uniprot/pagoda_" + percentage + "p" + date); } public static void main(String... args) throws IOException { diff --git a/test/uk/ac/ox/cs/pagoda/test_units/LightEvaluation.java b/test/uk/ac/ox/cs/pagoda/test_units/LightEvaluation.java index 29006de..932c178 100644 --- a/test/uk/ac/ox/cs/pagoda/test_units/LightEvaluation.java +++ b/test/uk/ac/ox/cs/pagoda/test_units/LightEvaluation.java @@ -2,7 +2,7 @@ package uk.ac.ox.cs.pagoda.test_units; import org.junit.Test; import uk.ac.ox.cs.pagoda.tester.PagodaTester; -import uk.ac.ox.cs.pagoda.util.Utility; +import uk.ac.ox.cs.pagoda.util.TestUtil; import java.io.IOException; @@ -11,52 +11,57 @@ public class LightEvaluation { @Test public void uobm1() throws IOException { int number = 1; + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "uobm/univ-bench-dl.owl", - PagodaTester.onto_dir + "uobm/data/uobm" + number + ".ttl", - PagodaTester.onto_dir + "uobm/queries/standard.sparql" + TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), + TestUtil.combinePaths(ontoDir, "uobm/data/uobm" + number + ".ttl"), + TestUtil.combinePaths(ontoDir, "uobm/queries/standard.sparql") ); - Utility.copyFile("log4j.log", "output/jair/uobm1.out"); + TestUtil.copyFile("log4j.log", "output/jair/uobm1.out"); } @Test public void lubm100() throws IOException { int number = 100; + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "lubm/univ-bench.owl", - PagodaTester.onto_dir + "lubm/data/lubm" + number + ".ttl", - PagodaTester.onto_dir + "lubm/queries/test.sparql" + TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), + TestUtil.combinePaths(ontoDir, "lubm/data/lubm" + number + ".ttl"), + TestUtil.combinePaths(ontoDir, "lubm/queries/test.sparql") ); - Utility.copyFile("log4j.log", "results-backup/current/lubm100.out"); + TestUtil.copyFile("log4j.log", "results-backup/current/lubm100.out"); } @Test public void fly() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", - PagodaTester.onto_dir + "fly/queries/fly.sparql" + TestUtil.combinePaths(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl"), + TestUtil.combinePaths(ontoDir, "fly/queries/fly.sparql") ); - Utility.copyFile("log4j.log", "results-backup/current/fly.out"); + TestUtil.copyFile("log4j.log", "results-backup/current/fly.out"); } @Test public void dbpedia() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "dbpedia/integratedOntology-all-in-one-minus-datatype.owl", - PagodaTester.onto_dir + "dbpedia/data/dbpedia-minus-datatype-new.ttl", - PagodaTester.onto_dir + "dbpedia/atomic.sparql" + TestUtil.combinePaths(ontoDir, "dbpedia/integratedOntology-all-in-one-minus-datatype.owl"), + TestUtil.combinePaths(ontoDir, "dbpedia/data/dbpedia-minus-datatype-new.ttl"), + TestUtil.combinePaths(ontoDir, "dbpedia/atomic.sparql") ); - Utility.copyFile("log4j.log", "results-backup/current/dbpedia.out"); + TestUtil.copyFile("log4j.log", "results-backup/current/dbpedia.out"); } @Test public void npdWithoutDataType() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "npd/npd-all-minus-datatype.owl", - PagodaTester.onto_dir + "npd/data/npd-data-dump-minus-datatype-new.ttl", - PagodaTester.onto_dir + "npd/queries/atomic.sparql" + TestUtil.combinePaths(ontoDir, "npd/npd-all-minus-datatype.owl"), + TestUtil.combinePaths(ontoDir, "npd/data/npd-data-dump-minus-datatype-new.ttl"), + TestUtil.combinePaths(ontoDir, "npd/queries/atomic.sparql") ); - Utility.copyFile("log4j.log", "results-backup/current/npd_minus.out"); + TestUtil.copyFile("log4j.log", "results-backup/current/npd_minus.out"); } } diff --git a/test/uk/ac/ox/cs/pagoda/test_units/PagodaDBPedia.java b/test/uk/ac/ox/cs/pagoda/test_units/PagodaDBPedia.java index aaf542e..1673179 100644 --- a/test/uk/ac/ox/cs/pagoda/test_units/PagodaDBPedia.java +++ b/test/uk/ac/ox/cs/pagoda/test_units/PagodaDBPedia.java @@ -1,28 +1,28 @@ package uk.ac.ox.cs.pagoda.test_units; -import static org.junit.Assert.fail; - import org.junit.Test; - import uk.ac.ox.cs.pagoda.tester.PagodaTester; import uk.ac.ox.cs.pagoda.tester.Statistics; -import uk.ac.ox.cs.pagoda.util.Utility; +import uk.ac.ox.cs.pagoda.util.TestUtil; import java.io.IOException; +import static org.junit.Assert.fail; + public class PagodaDBPedia { @Test public void test() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "dbpedia/integratedOntology-all-in-one-minus-datatype.owl", - PagodaTester.onto_dir + "dbpedia/data/dbpedia-minus-datatype-new.ttl", - PagodaTester.onto_dir + "dbpedia/atomic.sparql" + TestUtil.combinePaths(ontoDir, "dbpedia/integratedOntology-all-in-one-minus-datatype.owl"), + TestUtil.combinePaths(ontoDir, "dbpedia/data/dbpedia-minus-datatype-new.ttl"), + TestUtil.combinePaths(ontoDir, "dbpedia/atomic.sparql") ); Statistics stat = new Statistics("output/log4j.log"); String diff = stat.diff("results-backup/benchmark/dbpedia.out"); - Utility.copyFile("output/log4j.log", "results-backup/current/dbpedia.out"); + TestUtil.copyFile("output/log4j.log", "results-backup/current/dbpedia.out"); if (!diff.isEmpty()) fail(diff); } diff --git a/test/uk/ac/ox/cs/pagoda/test_units/PagodaELU.java b/test/uk/ac/ox/cs/pagoda/test_units/PagodaELU.java index c2fa838..70d531d 100644 --- a/test/uk/ac/ox/cs/pagoda/test_units/PagodaELU.java +++ b/test/uk/ac/ox/cs/pagoda/test_units/PagodaELU.java @@ -2,15 +2,17 @@ package uk.ac.ox.cs.pagoda.test_units; import org.junit.Test; import uk.ac.ox.cs.pagoda.tester.PagodaTester; +import uk.ac.ox.cs.pagoda.util.TestUtil; public class PagodaELU { @Test void test() { - int number = 1; + int number = 1; + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "uobm/univ-bench-dl.owl", - PagodaTester.onto_dir + "uobm/data/uobm" + number + ".ttl", - PagodaTester.onto_dir + "uobm/queries/standard.sparql" + TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), + TestUtil.combinePaths(ontoDir, "uobm/data/uobm" + number + ".ttl"), + TestUtil.combinePaths(ontoDir, "uobm/queries/standard.sparql") ); } diff --git a/test/uk/ac/ox/cs/pagoda/test_units/PagodaFLY.java b/test/uk/ac/ox/cs/pagoda/test_units/PagodaFLY.java index 2fe07f0..bad533f 100644 --- a/test/uk/ac/ox/cs/pagoda/test_units/PagodaFLY.java +++ b/test/uk/ac/ox/cs/pagoda/test_units/PagodaFLY.java @@ -1,16 +1,17 @@ package uk.ac.ox.cs.pagoda.test_units; import org.junit.Test; - import uk.ac.ox.cs.pagoda.tester.PagodaTester; +import uk.ac.ox.cs.pagoda.util.TestUtil; public class PagodaFLY { @Test public void test() { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", - PagodaTester.onto_dir + "fly/queries/fly_pellet.sparql" + TestUtil.combinePaths(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl"), + TestUtil.combinePaths(ontoDir, "fly/queries/fly_pellet.sparql") ); // Statistics stat = new Statistics("output/log4j.log"); diff --git a/test/uk/ac/ox/cs/pagoda/test_units/PagodaLUBM.java b/test/uk/ac/ox/cs/pagoda/test_units/PagodaLUBM.java index f40e41b..29abc87 100644 --- a/test/uk/ac/ox/cs/pagoda/test_units/PagodaLUBM.java +++ b/test/uk/ac/ox/cs/pagoda/test_units/PagodaLUBM.java @@ -1,68 +1,24 @@ package uk.ac.ox.cs.pagoda.test_units; -import org.testng.Assert; import org.testng.annotations.Test; -import uk.ac.ox.cs.pagoda.tester.PagodaTester; -import uk.ac.ox.cs.pagoda.tester.Statistics; -import uk.ac.ox.cs.pagoda.util.Utility; +import uk.ac.ox.cs.pagoda.util.TestUtil; -import java.io.FileInputStream; import java.io.IOException; -import java.util.Properties; +import java.nio.file.Paths; public class PagodaLUBM { - public static final String CONFIG_FILE = "config/test.properties"; - - private static boolean isInit = false; - private static String ontoDir; - - private static void init() { - if(isInit) return; - isInit = true; - - Properties config = new Properties(); - - try(FileInputStream in = new FileInputStream(CONFIG_FILE)) { - config.load(in); - in.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - ontoDir = config.getProperty("ontoDir"); - } - - private void test_all(int number) { - init(); - PagodaTester.main( - Utility.combinePaths(ontoDir, "lubm/univ-bench.owl"), - Utility.combinePaths(ontoDir, "lubm/data/lubm" + number + ".ttl"), - Utility.combinePaths(ontoDir, "lubm/queries/test.sparql") - ); - -// assertTrue(false); -// AllTests.copy("log4j.log", "output/jair/lubm" + number + ".out"); + private void testN(int number ) throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); + TestGlobalCorrectness.test(Paths.get(ontoDir, "lubm/univ-bench.owl"), + Paths.get(ontoDir, "lubm/data/lubm" + number + ".ttl"), + Paths.get(ontoDir, "lubm/queries/test.sparql"), + Paths.get(ontoDir, "lubm/lubm" + number + ".ans")); } @Test - public void test1() { - test_all(1); - } - -// @Test -// public void test() { -// int number = 100; -// test_all(number); -// } - - private void check(int number) throws IOException { - Statistics stat = new Statistics("output/log4j.log"); - // TODO insert proper file - String diff = stat.diff("results-backup/benchmark/lubm" + number + ".out"); - Utility.copyFile("output/log4j.log", "results-backup/current/lubm" + number + ".out"); - if (!diff.isEmpty()) - Assert.fail(diff); + public void test1() throws IOException { + testN(1); } } diff --git a/test/uk/ac/ox/cs/pagoda/test_units/PagodaNPD.java b/test/uk/ac/ox/cs/pagoda/test_units/PagodaNPD.java index 8fbe793..5f89162 100644 --- a/test/uk/ac/ox/cs/pagoda/test_units/PagodaNPD.java +++ b/test/uk/ac/ox/cs/pagoda/test_units/PagodaNPD.java @@ -1,43 +1,44 @@ package uk.ac.ox.cs.pagoda.test_units; -import static org.junit.Assert.fail; - import org.junit.Test; - import uk.ac.ox.cs.pagoda.tester.PagodaTester; import uk.ac.ox.cs.pagoda.tester.Statistics; -import uk.ac.ox.cs.pagoda.util.Utility; +import uk.ac.ox.cs.pagoda.util.TestUtil; import java.io.IOException; +import static org.junit.Assert.fail; + public class PagodaNPD { @Test public void testNPDwithoutDataType() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "npd/npd-all-minus-datatype.owl", - PagodaTester.onto_dir + "npd/data/npd-data-dump-minus-datatype-new.ttl", - PagodaTester.onto_dir + "npd/queries/atomic.sparql" + TestUtil.combinePaths(ontoDir, "npd/npd-all-minus-datatype.owl"), + TestUtil.combinePaths(ontoDir, "npd/data/npd-data-dump-minus-datatype-new.ttl"), + TestUtil.combinePaths(ontoDir, "npd/queries/atomic.sparql") ); Statistics stat = new Statistics("output/log4j.log"); String diff = stat.diff("results-backup/benchmark/npd_minus.out"); - Utility.copyFile("output/log4j.log", "results-backup/current/npd_minus.out"); + TestUtil.copyFile("output/log4j.log", "results-backup/current/npd_minus.out"); if (!diff.isEmpty()) fail(diff); } @Test public void testNPD() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "npd/npd-all.owl", - PagodaTester.onto_dir + "npd/data/npd-data-dump-processed.ttl", - PagodaTester.onto_dir + "npd/queries/atomic.sparql" + TestUtil.combinePaths(ontoDir, "npd/npd-all.owl"), + TestUtil.combinePaths(ontoDir, "npd/data/npd-data-dump-processed.ttl"), + TestUtil.combinePaths(ontoDir, "npd/queries/atomic.sparql") ); Statistics stat = new Statistics("output/log4j.log"); String diff = stat.diff("results-backup/benchmark/npd.out"); - Utility.copyFile("output/log4j.log", "results-backup/current/npd.out"); + TestUtil.copyFile("output/log4j.log", "results-backup/current/npd.out"); if (!diff.isEmpty()) fail(diff); } diff --git a/test/uk/ac/ox/cs/pagoda/test_units/PagodaNPD_bench.java b/test/uk/ac/ox/cs/pagoda/test_units/PagodaNPD_bench.java index 1243180..1aca36a 100644 --- a/test/uk/ac/ox/cs/pagoda/test_units/PagodaNPD_bench.java +++ b/test/uk/ac/ox/cs/pagoda/test_units/PagodaNPD_bench.java @@ -1,28 +1,28 @@ package uk.ac.ox.cs.pagoda.test_units; -import static org.junit.Assert.fail; - import org.junit.Test; - import uk.ac.ox.cs.pagoda.tester.PagodaTester; import uk.ac.ox.cs.pagoda.tester.Statistics; -import uk.ac.ox.cs.pagoda.util.Utility; +import uk.ac.ox.cs.pagoda.util.TestUtil; import java.io.IOException; +import static org.junit.Assert.fail; + public class PagodaNPD_bench { @Test public void test() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "npd-benchmark/npd-v2-ql_a.owl", - PagodaTester.onto_dir + "npd-benchmark/npd-v2-ql_a.ttl", - PagodaTester.onto_dir + "npd-benchmark/queries/all.sparql" + TestUtil.combinePaths(ontoDir, "npd-benchmark/npd-v2-ql_a.owl"), + TestUtil.combinePaths(ontoDir, "npd-benchmark/npd-v2-ql_a.ttl"), + TestUtil.combinePaths(ontoDir, "npd-benchmark/queries/all.sparql") ); Statistics stat = new Statistics("output/log4j.log"); String diff = stat.diff("results-backup/benchmark/npd-bench.out"); - Utility.copyFile("output/log4j.log", "results-backup/current/npd-bench.out"); + TestUtil.copyFile("output/log4j.log", "results-backup/current/npd-bench.out"); if (!diff.isEmpty()) fail(diff); } diff --git a/test/uk/ac/ox/cs/pagoda/test_units/PagodaRLU.java b/test/uk/ac/ox/cs/pagoda/test_units/PagodaRLU.java index 8b31c99..c365196 100644 --- a/test/uk/ac/ox/cs/pagoda/test_units/PagodaRLU.java +++ b/test/uk/ac/ox/cs/pagoda/test_units/PagodaRLU.java @@ -2,17 +2,19 @@ package uk.ac.ox.cs.pagoda.test_units; import org.junit.Test; import uk.ac.ox.cs.pagoda.tester.PagodaTester; +import uk.ac.ox.cs.pagoda.util.TestUtil; public class PagodaRLU { @Test public void testRL() { - int number = 1; + int number = 1; + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( - PagodaTester.onto_dir + "uobm/univ-bench-dl.owl", - PagodaTester.onto_dir + "uobm/data/uobm" + number + ".ttl", - PagodaTester.onto_dir + "uobm/queries/standard.sparql" - ); + TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), + TestUtil.combinePaths(ontoDir, "uobm/data/uobm" + number + ".ttl"), + TestUtil.combinePaths(ontoDir, "uobm/queries/standard.sparql") + ); } } diff --git a/test/uk/ac/ox/cs/pagoda/test_units/PagodaUOBM.java b/test/uk/ac/ox/cs/pagoda/test_units/PagodaUOBM.java index 29a9056..f53ed7e 100644 --- a/test/uk/ac/ox/cs/pagoda/test_units/PagodaUOBM.java +++ b/test/uk/ac/ox/cs/pagoda/test_units/PagodaUOBM.java @@ -1,79 +1,24 @@ package uk.ac.ox.cs.pagoda.test_units; import org.testng.annotations.Test; -import uk.ac.ox.cs.pagoda.tester.PagodaTester; -import uk.ac.ox.cs.pagoda.tester.Statistics; -import uk.ac.ox.cs.pagoda.util.Utility; +import uk.ac.ox.cs.pagoda.util.TestUtil; -import java.io.FileInputStream; import java.io.IOException; -import java.util.Properties; +import java.nio.file.Paths; public class PagodaUOBM { - public static final String CONFIG_FILE = "config/test.properties"; - - private static boolean isInit = false; - private static String ontoDir; - - private static void init() { - if(isInit) return; - isInit = true; - - Properties config = new Properties(); - - try(FileInputStream in = new FileInputStream(CONFIG_FILE)) { - config.load(in); - in.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - ontoDir = config.getProperty("ontoDir"); - } - - private void test_all(int number ) { - init(); - - PagodaTester.main( - Utility.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), - Utility.combinePaths(ontoDir, "uobm/data/uobm" + number + ".ttl"), - Utility.combinePaths(ontoDir, "uobm/queries/test.sparql") -// + ";" + -// Utility.combinePaths(ontoDir, "uobm/queries/standard_group3_all_less.sparql") + ";" + -// Utility.combinePaths(ontoDir, "uobm/queries/G3.sparql") + ";" + -// Utility.combinePaths(ontoDir, "uobm/queries/last.sparql") - ); - -// AllTests.copy("log4j.log", "output/jair/newuobm/uobm" + number + ".out"); - } - - private void test_upToSum(int number) { - init(); - - PagodaTester.main( - PagodaTester.onto_dir + "uobm/univ-bench-dl.owl", - PagodaTester.onto_dir + "uobm/data/uobm" + number + ".ttl", - PagodaTester.onto_dir + "uobm/queries/standard_group3_all.sparql" - ); - -// AllTests.copy("log4j.log", "output/jair/uobm" + number + ".out"); + private void testN(int number ) throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); + TestGlobalCorrectness.test(Paths.get(ontoDir, "uobm/univ-bench-dl.owl"), + Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl"), + Paths.get(ontoDir, "uobm/queries/test.sparql"), + Paths.get(ontoDir, "uobm/uobm" + number + ".ans")); } @Test - public void test1() { test_all(1); } - -// @Test - public void test500() { test_upToSum(500); } - -// public static void main(String... args) { -// new PagodaUOBM().test_all(1); -// } - - private void check() { - Statistics stat = new Statistics("results-backup/current/uobm1.out"); - String diff = stat.diff("results-backup/benchmark/uobm1.out"); - System.out.println(diff); + public void test1() throws IOException { + testN(1); } } diff --git a/test/uk/ac/ox/cs/pagoda/test_units/TestGlobalCorrectness.java b/test/uk/ac/ox/cs/pagoda/test_units/TestGlobalCorrectness.java new file mode 100644 index 0000000..34ec8cd --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/test_units/TestGlobalCorrectness.java @@ -0,0 +1,55 @@ +package uk.ac.ox.cs.pagoda.test_units; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; +import org.apache.log4j.Logger; +import org.testng.Assert; +import uk.ac.ox.cs.pagoda.query.AnswerTuple; +import uk.ac.ox.cs.pagoda.query.QueryRecord; +import uk.ac.ox.cs.pagoda.tester.PagodaTester; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.Set; + +/* + * This is a unit test for TestNG. + *

+ * It tests the correctness on the final output. + * */ +public class TestGlobalCorrectness { + + public static final Logger logger = Logger.getLogger(TestGlobalCorrectness.class); + + public static void test(Path ontology, Path data, Path queries, Path givenAnswers) { + try { + Path computedAnswers = Paths.get(File.createTempFile("answers", ".tmp").getAbsolutePath()); + PagodaTester.main(ontology.toString(), data.toString(), queries.toString(), computedAnswers.toString()); + Assert.assertTrue(checkSameContent(computedAnswers, givenAnswers)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static boolean checkSameContent(Path computedAnswersFile, Path givenAnswersFile) throws IOException { + BufferedReader computedReader = Files.newBufferedReader(computedAnswersFile); + BufferedReader givenReader = Files.newBufferedReader(givenAnswersFile); + + Gson gson = new GsonBuilder().create(); + + Type cqType = new TypeToken>() {}.getType(); + Collection computedAnswers = gson.fromJson(computedReader, cqType); + Collection givenAnswers = gson.fromJson(givenReader, cqType); + + return computedAnswers.equals(givenAnswers); + } + + +} diff --git a/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java b/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java index 51b41f9..7dacdac 100644 --- a/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java +++ b/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java @@ -1,17 +1,17 @@ package uk.ac.ox.cs.pagoda.tester; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Scanner; - import uk.ac.ox.cs.pagoda.query.AnswerTuple; import uk.ac.ox.cs.pagoda.query.AnswerTuples; -import uk.ac.ox.cs.pagoda.reasoner.*; +import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; import uk.ac.ox.cs.pagoda.util.Properties; import uk.ac.ox.cs.pagoda.util.Timer; import uk.ac.ox.cs.pagoda.util.Utility; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Scanner; + public class PagodaTester { // public static final String onto_dir = "/media/RDFData/yzhou/"; @@ -93,7 +93,7 @@ public class PagodaTester { public static void main(String... args) { if (args.length == 0) { // args = new String[] {test_tbox, test_abox, test_query}; - args = new String[] {lubm_tbox, lubm_abox, lubm_query}; + args = new String[] {lubm_tbox, lubm_abox, lubm_query, "/home/alessandro/Desktop/lubm1.ans"}; // args = new String[] {uobm_tbox, uobm_abox, uobm_query.replace(".sparql", "_all_pagoda.sparql")}; // args = new String[] {fly, "null", fly_query.replace(".sparql", "_pellet.sparql") }; // args = new String[] {dbpedia_tbox, dbpedia_abox, dbpedia_query}; @@ -145,7 +145,7 @@ public class PagodaTester { if (properties.getQueryPath() != null) for (String queryFile: properties.getQueryPath().split(";")) - pagoda.evaluate(pagoda.getQueryManager().collectQueryRecords(queryFile), properties.getAnswerPath()); + pagoda.evaluate(pagoda.getQueryManager().collectQueryRecords(queryFile)); if (properties.getShellMode()) try { diff --git a/test/uk/ac/ox/cs/pagoda/util/TestUtil.java b/test/uk/ac/ox/cs/pagoda/util/TestUtil.java new file mode 100644 index 0000000..227398b --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/util/TestUtil.java @@ -0,0 +1,64 @@ +package uk.ac.ox.cs.pagoda.util; + +import org.apache.log4j.Appender; +import org.apache.log4j.FileAppender; +import org.apache.log4j.Logger; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Enumeration; +import java.util.Properties; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; + +/** + * A collection of utility methods for testing. + */ +public class TestUtil { + + public static final String CONFIG_FILE = "config/test.properties"; + + private static boolean isConfigLoaded = false; + private static Properties config; + + public static Properties getConfig() { + if(!isConfigLoaded) { + try (FileInputStream in = new FileInputStream(CONFIG_FILE)) { + config = new java.util.Properties(); + config.load(in); + in.close(); + isConfigLoaded = true; + } catch (IOException e) { + e.printStackTrace(); + } + } + return config; + } + + public static String combinePaths(String path1, String path2) { + File file1 = new File(path1); + File file2 = new File(file1, path2); + return file2.getPath(); + } + + public static void copyFile(String src, String dst) throws IOException { + Files.copy(Paths.get(src), Paths.get(dst), REPLACE_EXISTING); + } + + /* + * Get the log file, which is assumed unique. + * */ + public static String getLogFileName() { + Enumeration e = Logger.getRootLogger().getAllAppenders(); + while (e.hasMoreElements()){ + Appender app = (Appender)e.nextElement(); + if (app instanceof FileAppender){ + return ((FileAppender)app).getFile(); + } + } + return null; + } +} -- cgit v1.2.3