From 5d54af2638a53721b414a41356a93686a9616272 Mon Sep 17 00:00:00 2001 From: RncLsn Date: Tue, 19 May 2015 13:35:52 +0100 Subject: Backup before changes in MyQueryReasoner. --- .gitignore | 3 +- src/uk/ac/ox/cs/pagoda/Pagoda.java | 64 +++-- .../ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java | 176 ++++++------ src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java | 174 ++++++------ test/resources/HeavyTests.xml | 17 ++ test/resources/LightTests.xml | 17 ++ test/uk/ac/ox/cs/hermit/HermitQueryReasoner.java | 48 +--- test/uk/ac/ox/cs/hermit/JAIR_HermiT.java | 20 +- .../ac/ox/cs/pagoda/global_tests/CheckAnswers.java | 35 +++ .../global_tests/CheckAnswersOverDataset.java | 48 ---- .../ac/ox/cs/pagoda/global_tests/JAIR_PAGOdA.java | 48 ++-- .../cs/pagoda/global_tests/JAIR_Scalability.java | 52 ++-- .../ox/cs/pagoda/global_tests/LightEvaluation.java | 5 +- .../ox/cs/pagoda/global_tests/TestPagodaLUBM.java | 35 ++- .../ox/cs/pagoda/global_tests/TestPagodaUOBM.java | 45 +-- test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java | 310 +++++++++++++++++++-- test/uk/ac/ox/cs/pagoda/tester/Statistics.java | 1 + test/uk/ac/ox/cs/pagoda/util/TestUtil.java | 3 +- 18 files changed, 709 insertions(+), 392 deletions(-) create mode 100644 test/resources/HeavyTests.xml create mode 100644 test/resources/LightTests.xml create mode 100644 test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswers.java delete mode 100644 test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswersOverDataset.java diff --git a/.gitignore b/.gitignore index 0d42d8b..55844bd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /backup/ /tmp/ /testcase/ -/log4j.log +/*.log +/*.pdf \ No newline at end of file diff --git a/src/uk/ac/ox/cs/pagoda/Pagoda.java b/src/uk/ac/ox/cs/pagoda/Pagoda.java index 3263c03..4ad7678 100644 --- a/src/uk/ac/ox/cs/pagoda/Pagoda.java +++ b/src/uk/ac/ox/cs/pagoda/Pagoda.java @@ -9,7 +9,7 @@ import uk.ac.ox.cs.pagoda.util.Utility; import java.nio.file.Path; /** - * The main class + * Executable command line user interface. */ public class Pagoda implements Runnable { @@ -19,31 +19,62 @@ public class Pagoda implements Runnable { private static final String OPTION_ANSWER = "a"; private static final String OPTION_CLASSIFY = "c"; private static final String OPTION_HERMIT = "f"; + private final Properties properties; + + /** + * Do not use it + * */ + private Pagoda() { + properties = new Properties(); + } public static void main(String... args) { Options options = new Options(); - options.addOption(Option.builder(OPTION_ONTOLOGY).argName(OPTION_ONTOLOGY).required().hasArg().desc("The ontology path").build()); + options.addOption(Option.builder(OPTION_ONTOLOGY) + .argName(OPTION_ONTOLOGY) + .required() + .hasArg() + .desc("The ontology path") + .build()); options.addOption(Option.builder(OPTION_DATA).argName(OPTION_DATA).hasArg().desc("The data path").build()); - options.addOption(Option.builder(OPTION_QUERY).argName(OPTION_QUERY).required().hasArg().desc("The query path").build()); - options.addOption(Option.builder(OPTION_ANSWER).argName(OPTION_ANSWER).hasArg().desc("The answer path").build()); - options.addOption(Option.builder(OPTION_CLASSIFY).argName(OPTION_CLASSIFY).desc("Tell whether to classify").type(Boolean.class).build()); - options.addOption(Option.builder(OPTION_HERMIT).argName(OPTION_HERMIT).desc("Tell whether to call Hermit").type(Boolean.class).build()); + options.addOption(Option.builder(OPTION_QUERY) + .argName(OPTION_QUERY) + .required() + .hasArg() + .desc("The query path") + .build()); + options.addOption(Option.builder(OPTION_ANSWER) + .argName(OPTION_ANSWER) + .hasArg() + .desc("The answer path") + .build()); + options.addOption(Option.builder(OPTION_CLASSIFY) + .argName(OPTION_CLASSIFY) + .desc("Tell whether to classify") + .type(Boolean.class) + .build()); + options.addOption(Option.builder(OPTION_HERMIT) + .argName(OPTION_HERMIT) + .desc("Tell whether to call Hermit") + .type(Boolean.class) + .build()); CommandLineParser parser = new DefaultParser(); try { - CommandLine cmd = parser.parse( options, args ); + CommandLine cmd = parser.parse(options, args); PagodaBuilder pagodaBuilder = Pagoda.builder() .ontology(cmd.getOptionValue(OPTION_ONTOLOGY)) .query(cmd.getOptionValue(OPTION_QUERY)); if(cmd.hasOption(OPTION_DATA)) pagodaBuilder.data(cmd.getOptionValue(OPTION_DATA)); - if(cmd.hasOption(OPTION_ANSWER)) pagodaBuilder.answer(cmd.getOptionValue(OPTION_ANSWER)); - if(cmd.hasOption(OPTION_CLASSIFY)) pagodaBuilder.classify(Boolean.parseBoolean(cmd.getOptionValue(OPTION_CLASSIFY))); - if(cmd.hasOption(OPTION_HERMIT)) pagodaBuilder.hermit(Boolean.parseBoolean(cmd.getOptionValue(OPTION_HERMIT))); + if(cmd.hasOption(OPTION_ANSWER)) pagodaBuilder.answer(cmd.getOptionValue(OPTION_ANSWER)); + if(cmd.hasOption(OPTION_CLASSIFY)) + pagodaBuilder.classify(Boolean.parseBoolean(cmd.getOptionValue(OPTION_CLASSIFY))); + if(cmd.hasOption(OPTION_HERMIT)) + pagodaBuilder.hermit(Boolean.parseBoolean(cmd.getOptionValue(OPTION_HERMIT))); pagodaBuilder.build().run(); - } - catch( ParseException exp ) { + } catch(ParseException exp) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("PAGOdA", options); Utility.logError("Parsing failed. Reason: " + exp.getMessage()); @@ -51,15 +82,6 @@ public class Pagoda implements Runnable { } } - /** - * Do not use it - * */ - private Pagoda() { - properties = new Properties(); - } - - private final Properties properties; - /** * Get a builder. * */ diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java index 1f435b7..dfbcb4d 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java @@ -37,21 +37,19 @@ public class MyQueryReasoner extends QueryReasoner { BasicQueryEngine limitedSkolemUpperStore; // boolean[] namedIndividuals_lazyUpper; - OWLOntology elho_ontology; - KarmaQueryEngine elLowerStore = null; + OWLOntology elho_ontology; + KarmaQueryEngine elLowerStore = null; BasicQueryEngine trackingStore = null; // boolean[] namedIndividuals_tracking; - - boolean equalityTag; - boolean multiStageTag; TrackingRuleEncoder encoder; - Timer t = new Timer(); + private boolean equalityTag; + private boolean multiStageTag; + private Timer t = new Timer(); private Collection predicatesWithGap = null; - private Boolean satisfiable; + private SatisfiabilityStatus satisfiable; private ConsistencyManager consistency = new ConsistencyManager(this); private boolean useUpperStores = false; - public MyQueryReasoner() { setup(true, true); } @@ -59,7 +57,7 @@ public class MyQueryReasoner extends QueryReasoner { public MyQueryReasoner(boolean multiStageTag, boolean considerEqualities) { setup(multiStageTag, considerEqualities); } - + private BasicQueryEngine getUpperStore(String name, boolean checkValidity) { if (multiStageTag) return new MultiStageQueryEngine(name, checkValidity); @@ -69,7 +67,7 @@ public class MyQueryReasoner extends QueryReasoner { } public void setup(boolean multiStageTag, boolean considerEqualities) { - satisfiable = null; + satisfiable = SatisfiabilityStatus.UNCHECKED; this.multiStageTag = multiStageTag; this.equalityTag = considerEqualities; @@ -90,7 +88,7 @@ public class MyQueryReasoner extends QueryReasoner { @Override public void loadOntology(OWLOntology o) { - if (!equalityTag) { + if(!equalityTag) { EqualitiesEliminator eliminator = new EqualitiesEliminator(o); o = eliminator.getOutputOntology(); eliminator.save(); @@ -103,9 +101,9 @@ public class MyQueryReasoner extends QueryReasoner { // program.getGeneral().save(); useUpperStores = multiStageTag && !program.getGeneral().isHorn(); - if (useUpperStores) { - lazyUpperStore = getUpperStore("lazy-upper-bound", true); // new MultiStageQueryEngine("lazy-upper-bound", true); // - limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true); + if(useUpperStores) { + lazyUpperStore = getUpperStore("lazy-upper-bound", true); + limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true); } importData(program.getAdditionalDataFile()); @@ -113,11 +111,11 @@ public class MyQueryReasoner extends QueryReasoner { elho_ontology = new ELHOProfile().getFragment(ontology); elLowerStore.processOntology(elho_ontology); } - + public Collection getPredicatesWithGap() { return predicatesWithGap; } - + @Override public boolean preprocess() { t.reset(); @@ -127,7 +125,7 @@ public class MyQueryReasoner extends QueryReasoner { rlLowerStore.importRDFData(name, datafile); rlLowerStore.materialise("lower program", program.getLower().toString()); // program.getLower().save(); - if (!consistency.checkRLLowerBound()) return false; + if(!consistency.checkRLLowerBound()) return false; Utility.logInfo("The number of sameAs assertions in RL lower store: " + rlLowerStore.getSameAsNumber()); String originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology); @@ -136,35 +134,35 @@ public class MyQueryReasoner extends QueryReasoner { elLowerStore.materialise("saturate named individuals", originalMarkProgram); elLowerStore.materialise("lower program", program.getLower().toString()); elLowerStore.initialiseKarma(); - if (!consistency.checkELLowerBound()) return false; + if(!consistency.checkELLowerBound()) return false; - if (lazyUpperStore != null) { + if(lazyUpperStore != null) { lazyUpperStore.importRDFData(name, datafile); lazyUpperStore.materialise("saturate named individuals", originalMarkProgram); int tag = lazyUpperStore.materialiseRestrictedly(program, null); - if (tag != 1) { + if(tag != 1) { lazyUpperStore.dispose(); lazyUpperStore = null; } - if (tag == -1) return false; + if(tag == -1) return false; } - if (consistency.checkUpper(lazyUpperStore)) { - satisfiable = true; + if(consistency.checkUpper(lazyUpperStore)) { + satisfiable = SatisfiabilityStatus.SATISFIABLE; Utility.logInfo("time for satisfiability checking: " + t.duration()); } - if (limitedSkolemUpperStore != null) { + if(limitedSkolemUpperStore != null) { limitedSkolemUpperStore.importRDFData(name, datafile); limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram); int tag = limitedSkolemUpperStore.materialiseSkolemly(program, null); - if (tag != 1) { + if(tag != 1) { limitedSkolemUpperStore.dispose(); limitedSkolemUpperStore = null; } - if (tag == -1) return false; + if(tag == -1) return false; } - if (consistency.checkUpper(limitedSkolemUpperStore)) { - satisfiable = true; + if(satisfiable == SatisfiabilityStatus.UNCHECKED && consistency.checkUpper(limitedSkolemUpperStore)) { + satisfiable = SatisfiabilityStatus.SATISFIABLE; Utility.logInfo("time for satisfiability checking: " + t.duration()); } @@ -176,7 +174,7 @@ public class MyQueryReasoner extends QueryReasoner { predicatesWithGap = gap.getPredicatesWithGap(); gap.clear(); - if (program.getGeneral().isHorn()) + if(program.getGeneral().isHorn()) encoder = new TrackingRuleEncoderWithGap(program.getUpper(), trackingStore); else encoder = new TrackingRuleEncoderDisjVar1(program.getUpper(), trackingStore); @@ -186,21 +184,22 @@ public class MyQueryReasoner extends QueryReasoner { program.deleteABoxTurtleFile(); - if (!isConsistent()) + if(!isConsistent()) return false; consistency.extractBottomFragment(); consistency.dispose(); + return true; } - + @Override public boolean isConsistent() { - if (satisfiable == null) { - satisfiable = consistency.check(); + if(satisfiable == SatisfiabilityStatus.UNCHECKED) { + satisfiable = consistency.check() ? SatisfiabilityStatus.SATISFIABLE : SatisfiabilityStatus.UNSATISFIABLE; Utility.logInfo("time for satisfiability checking: " + t.duration()); } - return satisfiable; + return satisfiable == SatisfiabilityStatus.SATISFIABLE ? true : false; } /** @@ -208,8 +207,8 @@ public class MyQueryReasoner extends QueryReasoner { * */ private OWLOntology relevantPart(QueryRecord queryRecord) { AnswerTuples rlAnswer = null, elAnswer = null; - - t.reset(); + + t.reset(); try { rlAnswer = rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); Utility.logDebug(t.duration()); @@ -218,11 +217,11 @@ public class MyQueryReasoner extends QueryReasoner { if (rlAnswer != null) rlAnswer.dispose(); } queryRecord.addProcessingTime(Step.LowerBound, t.duration()); - + t.reset(); - BasicQueryEngine upperStore = queryRecord.isBottom() || lazyUpperStore == null ? trackingStore : lazyUpperStore; - - String[] extendedQuery = queryRecord.getExtendedQueryText(); + BasicQueryEngine upperStore = queryRecord.isBottom() || lazyUpperStore == null ? trackingStore : lazyUpperStore; + + String[] extendedQuery = queryRecord.getExtendedQueryText(); // TODO why the following??? queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); @@ -246,10 +245,10 @@ public class MyQueryReasoner extends QueryReasoner { queryRecord.addProcessingTime(Step.UpperBound, t.duration()); if (queryRecord.processed()) { - queryRecord.setDifficulty(Step.UpperBound); + queryRecord.setDifficulty(Step.UpperBound); return null; } - + t.reset(); try { elAnswer = elLowerStore.evaluate(extendedQuery[0], queryRecord.getAnswerVariables(), queryRecord.getLowerBoundAnswers()); @@ -261,48 +260,46 @@ public class MyQueryReasoner extends QueryReasoner { queryRecord.addProcessingTime(Step.ELLowerBound, t.duration()); if (queryRecord.processed()) { - queryRecord.setDifficulty(Step.ELLowerBound); - return null; + queryRecord.setDifficulty(Step.ELLowerBound); + return null; } - - t.reset(); - + + t.reset(); + QueryTracker tracker = new QueryTracker(encoder, rlLowerStore, queryRecord); - - OWLOntology knowledgebase; - t.reset(); + + OWLOntology knowledgebase; + t.reset(); // if (program.getGeneral().isHorn()) { // knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true); // queryRecord.addProcessingTime(Step.Fragment, t.duration()); -// return knowledgebase; +// return knowledgebase; // } -// else { +// else { knowledgebase = tracker.extract(trackingStore, consistency.getQueryRecords(), true); queryRecord.addProcessingTime(Step.Fragment, t.duration()); // } - - if (knowledgebase.isEmpty() || queryRecord.isBottom()) - return knowledgebase; - - if (program.getGeneral().isHorn()) return knowledgebase; - -// t.reset(); -// if (queryRecord.isHorn() && lazyUpperStore != null) { -//// knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true); + + if(knowledgebase.isEmpty() || queryRecord.isBottom()) + return knowledgebase; + + if(program.getGeneral().isHorn()) return knowledgebase; + +// t.reset(); +// if (queryRecord.isHorn() && lazyUpperStore != null) { +//// knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true); // } else if (queryRecord.getArity() < 3) { // IterativeRefinement iterativeRefinement = new IterativeRefinement(queryRecord, tracker, trackingStore, consistency.getQueryRecords()); // knowledgebase = iterativeRefinement.extractWithFullABox(importedData.toString(), program.getUpperBottomStrategy()); // } -// +// // queryRecord.addProcessingTime(Step.FragmentRefinement, t.duration()); -// +// // if (knowledgebase == null) // queryRecord.setDifficulty(Step.FragmentRefinement); - - return knowledgebase; - } -// int counter = 0; + return knowledgebase; + } private String toJsonKeyValuePair(String key, Object value) { HashMap map = new HashMap<>(); @@ -310,8 +307,10 @@ public class MyQueryReasoner extends QueryReasoner { return QueryRecord.GsonCreator.getInstance().toJson(map); } +// int counter = 0; + private void queryUpperBound(BasicQueryEngine upperStore, QueryRecord queryRecord, String queryText, String[] answerVariables) { - AnswerTuples rlAnswer = null; + AnswerTuples rlAnswer = null; try { Utility.logDebug(queryText); rlAnswer = upperStore.evaluate(queryText, answerVariables); @@ -326,37 +325,38 @@ public class MyQueryReasoner extends QueryReasoner { @Override public void evaluate(QueryRecord queryRecord) { OWLOntology knowledgeBase = relevantPart(queryRecord); - - if (knowledgeBase == null) { + + if(knowledgeBase == null) { Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); - return ; + return; } - + int aBoxCount = knowledgeBase.getABoxAxioms(true).size(); Utility.logDebug("ABox axioms: " + aBoxCount + " TBox axioms: " + (knowledgeBase.getAxiomCount() - aBoxCount)); -// queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl"); - - Timer t = new Timer(); - Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT()); -// int validNumber = - summarisedChecker.check(queryRecord.getGapAnswers()); +// queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl"); + + Timer t = new Timer(); + Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT()); +// int validNumber = + summarisedChecker.check(queryRecord.getGapAnswers()); summarisedChecker.dispose(); Utility.logDebug("Total time for full reasoner: " + t.duration()); -// if (validNumber == 0) { - queryRecord.markAsProcessed(); - Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); +// if (validNumber == 0) { + queryRecord.markAsProcessed(); + Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); // } } - + @Override public void evaluateUpper(QueryRecord queryRecord) { - AnswerTuples rlAnswer = null; - boolean useFull = queryRecord.isBottom() || lazyUpperStore == null; + AnswerTuples rlAnswer = null; + boolean useFull = queryRecord.isBottom() || lazyUpperStore == null; try { - rlAnswer = (useFull ? trackingStore: lazyUpperStore).evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); - queryRecord.updateUpperBoundAnswers(rlAnswer, true); + rlAnswer = + (useFull ? trackingStore : lazyUpperStore).evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); + queryRecord.updateUpperBoundAnswers(rlAnswer, true); } finally { - if (rlAnswer != null) rlAnswer.dispose(); + if(rlAnswer != null) rlAnswer.dispose(); } } @@ -370,4 +370,6 @@ public class MyQueryReasoner extends QueryReasoner { super.dispose(); } + enum SatisfiabilityStatus {SATISFIABLE, UNSATISFIABLE, UNCHECKED} + } diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java index dfe0c5f..d4f4596 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java @@ -19,24 +19,26 @@ import java.util.Collection; // TODO clean APIs public abstract class QueryReasoner { - + + public static final String ImportDataFileSeparator = ";"; + private static final boolean DEFAULT_MULTI_STAGES = true; + private static final boolean DEFAULT_EQUALITIES = true; + public boolean fullReasoner = this instanceof MyQueryReasoner; + protected StringBuilder importedData = new StringBuilder(); // protected boolean forSemFacet = false; Properties properties; + BufferedWriter answerWriter = null; + private QueryManager m_queryManager = new QueryManager(); - private static boolean defaultMultiStages = true; - private static boolean defaultEqualities = true; - - public enum Type { Full, RLU, ELHOU } - public static QueryReasoner getInstance(Properties p) { OWLOntology ontology = OWLHelper.loadOntology(p.getOntologyPath()); QueryReasoner pagoda = getInstance(ontology, p); - pagoda.properties = p; + pagoda.properties = p; pagoda.loadOntology(ontology); pagoda.importData(p.getDataPath()); if (pagoda.preprocess()) { Utility.logInfo("The ontology is consistent!"); - return pagoda; + return pagoda; } else { System.out.println("The ontology is inconsistent!"); @@ -44,60 +46,63 @@ public abstract class QueryReasoner { return null; } } - + public static QueryReasoner getInstance(OWLOntology o) { - QueryReasoner pagoda = getInstance(Type.Full, o, defaultMultiStages, defaultEqualities); - pagoda.properties = new Properties(); - return pagoda; + QueryReasoner pagoda = getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES); + pagoda.properties = new Properties(); + return pagoda; } - - public void setToClassify(boolean flag) { - properties.setToClassify(flag); - } - - public void setToCallHermiT(boolean flag) { - properties.setToCallHermiT(flag); - } - + private static QueryReasoner getInstance(OWLOntology o, Properties p) { - return getInstance(Type.Full, o, defaultMultiStages, defaultEqualities); + return getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES); } - + public static QueryReasoner getInstance(Type type, OWLOntology o, boolean performMultiStages, boolean considerEqualities) { // Utility.initialise(); - QueryReasoner reasoner; + QueryReasoner reasoner; if (OWLHelper.isInOWL2RL(o)) reasoner = new RLQueryReasoner(); else if (OWLHelper.isInELHO(o)) reasoner = new ELHOQueryReasoner(); - else + else switch (type) { - case RLU: - reasoner = new RLUQueryReasoner(performMultiStages, considerEqualities); break; - case ELHOU: - reasoner = new ELHOUQueryReasoner(performMultiStages, considerEqualities); break; - default: - reasoner = new MyQueryReasoner(performMultiStages, considerEqualities); + case RLU: + reasoner = new RLUQueryReasoner(performMultiStages, considerEqualities); + break; + case ELHOU: + reasoner = new ELHOUQueryReasoner(performMultiStages, considerEqualities); + break; + default: + reasoner = new MyQueryReasoner(performMultiStages, considerEqualities); } - return reasoner; + return reasoner; + } + + public static QueryReasoner getHermiTReasoner(boolean toCheckSatisfiability) { + return new HermiTReasoner(toCheckSatisfiability); + } + + public void setToClassify(boolean flag) { + properties.setToClassify(flag); + } + + public void setToCallHermiT(boolean flag) { + properties.setToCallHermiT(flag); } - - public static final String ImportDataFileSeparator = ";"; - protected StringBuilder importedData = new StringBuilder(); public void importData(String datafile) { if (datafile != null && !datafile.equalsIgnoreCase("null")) - importData(datafile.split(ImportDataFileSeparator)); + importData(datafile.split(ImportDataFileSeparator)); } public void importData(String[] datafiles) { if (datafiles != null) { for (String datafile: datafiles) { - File file = new File(datafile); + File file = new File(datafile); if (file.exists()) { if (file.isFile()) importDataFile(file); else importDataDirectory(file); } else { - Utility.logError("warning: file " + datafile + " doesn't exists."); + Utility.logError("warning: file " + datafile + " doesn't exists."); } } } @@ -115,80 +120,75 @@ public abstract class QueryReasoner { datafile = file.getCanonicalPath(); } catch (IOException e) { e.printStackTrace(); - return ; - } - importDataFile(datafile); + return; + } + importDataFile(datafile); } - + protected final void importDataFile(String datafile) { if (importedData.length() == 0) - importedData.append(datafile); - else + importedData.append(datafile); + else importedData.append(ImportDataFileSeparator).append(datafile); } - - public abstract void loadOntology(OWLOntology ontology); - - public abstract boolean preprocess(); - public abstract boolean isConsistent(); + public abstract void loadOntology(OWLOntology ontology); - public boolean fullReasoner = this instanceof MyQueryReasoner; + public abstract boolean preprocess(); - public abstract void evaluate(QueryRecord record); + public abstract boolean isConsistent(); - public abstract void evaluateUpper(QueryRecord record); + public abstract void evaluate(QueryRecord record); + + public abstract void evaluateUpper(QueryRecord record); public AnswerTuples evaluate(String queryText, boolean forFacetGeneration) { if (forFacetGeneration) { QueryRecord record = m_queryManager.create(queryText); Utility.logInfo("---------- start evaluating upper bound for Query " + record.getQueryID() + " ----------", queryText); - if (!record.processed()) + if(!record.processed()) evaluateUpper(record); // AnswerTuples tuples = record.getUpperBoundAnswers(); // for (AnswerTuple tuple; tuples.isValid(); tuples.moveNext()) { -// tuple = tuples.getTuple(); +// tuple = tuples.getTuple(); // if (tuple.toString().contains("NC")) -// System.out.println(tuple.toString()); +// System.out.println(tuple.toString()); // } - return record.getUpperBoundAnswers(); - } - else - return evaluate(queryText); + return record.getUpperBoundAnswers(); + } else + return evaluate(queryText); } +// public void evaluate(Collection queryRecords) { +// evaluate(queryRecords); +// } + public AnswerTuples evaluate(String queryText) { - QueryRecord record = m_queryManager.create(queryText); + QueryRecord record = m_queryManager.create(queryText); Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); - if (!record.processed()) + if(!record.processed()) evaluate(record); - AnswerTuples answer = record.getAnswers(); + AnswerTuples answer = record.getAnswers(); record.dispose(); return answer; - + } - + public void evaluate_shell(String queryText) { - QueryRecord record = m_queryManager.create(queryText); + QueryRecord record = m_queryManager.create(queryText); Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); - if (!record.processed()) + if(!record.processed()) evaluate(record); Utility.logInfo("Answers to this query: ", record.outputSoundAnswerTuple()); record.dispose(); - + } -// public void evaluate(Collection queryRecords) { -// evaluate(queryRecords); -// } - - BufferedWriter answerWriter = null; - public void evaluate(Collection queryRecords) { if (!isConsistent()) { - Utility.logDebug("The ontology and dataset is inconsistent."); - return ; + Utility.logDebug("The ontology and dataset is inconsistent."); + return; } if(properties.getAnswerPath() != null && answerWriter == null) { @@ -199,21 +199,21 @@ public abstract class QueryReasoner { e.printStackTrace(); } } - + Timer t = new Timer(); Gson gson = QueryRecord.GsonCreator.getInstance(); for (QueryRecord record: queryRecords) { -// if (Integer.parseInt(record.getQueryID()) != 218) continue; - Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", +// if (Integer.parseInt(record.getQueryID()) != 218) continue; + Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", record.getQueryText()); if (!record.processed()) { t.reset(); if (!record.processed()) - evaluate(record); - Utility.logInfo("Total time to answer this query: " + t.duration()); + evaluate(record); + Utility.logInfo("Total time to answer this query: " + t.duration()); if (!fullReasoner && !record.processed()) { - Utility.logInfo("The query has not been fully answered in " + t.duration() + " seconds."); - continue; + Utility.logInfo("The query has not been fully answered in " + t.duration() + " seconds."); + continue; } } record.outputAnswerStatistics(); @@ -225,7 +225,7 @@ public abstract class QueryReasoner { // queryRecords.stream().forEach(record -> Utility.logDebug(gson.toJson(record))); queryRecords.stream().forEach(record -> record.dispose()); } - + public void dispose() { if (answerWriter != null) { try { @@ -235,17 +235,13 @@ public abstract class QueryReasoner { } } // Utility.cleanup(); - } - - private QueryManager m_queryManager = new QueryManager(); + } public QueryManager getQueryManager() { return m_queryManager; } - public static QueryReasoner getHermiTReasoner(boolean toCheckSatisfiability) { - return new HermiTReasoner(toCheckSatisfiability); - } + public enum Type {Full, RLU, ELHOU} } diff --git a/test/resources/HeavyTests.xml b/test/resources/HeavyTests.xml new file mode 100644 index 0000000..4a96553 --- /dev/null +++ b/test/resources/HeavyTests.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/resources/LightTests.xml b/test/resources/LightTests.xml new file mode 100644 index 0000000..dcac0dd --- /dev/null +++ b/test/resources/LightTests.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/uk/ac/ox/cs/hermit/HermitQueryReasoner.java b/test/uk/ac/ox/cs/hermit/HermitQueryReasoner.java index f6246f8..008fcb2 100644 --- a/test/uk/ac/ox/cs/hermit/HermitQueryReasoner.java +++ b/test/uk/ac/ox/cs/hermit/HermitQueryReasoner.java @@ -1,43 +1,21 @@ package uk.ac.ox.cs.hermit; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - import org.semanticweb.HermiT.Reasoner; import org.semanticweb.HermiT.model.Atom; import org.semanticweb.HermiT.model.AtomicRole; -import org.semanticweb.owlapi.model.IRI; -import org.semanticweb.owlapi.model.OWLAxiom; -import org.semanticweb.owlapi.model.OWLClassExpression; -import org.semanticweb.owlapi.model.OWLDataFactory; -import org.semanticweb.owlapi.model.OWLDatatype; -import org.semanticweb.owlapi.model.OWLIndividual; -import org.semanticweb.owlapi.model.OWLNamedIndividual; -import org.semanticweb.owlapi.model.OWLObjectProperty; -import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.model.OWLOntologyCreationException; -import org.semanticweb.owlapi.model.OWLOntologyManager; -import org.semanticweb.owlapi.model.OWLOntologyStorageException; +import org.semanticweb.owlapi.model.*; import org.semanticweb.owlapi.reasoner.Node; - import uk.ac.ox.cs.pagoda.owl.OWLHelper; import uk.ac.ox.cs.pagoda.owl.QueryRoller; import uk.ac.ox.cs.pagoda.query.QueryManager; import uk.ac.ox.cs.pagoda.query.QueryRecord; import uk.ac.ox.cs.pagoda.util.Timer; +import java.io.*; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.*; + public class HermitQueryReasoner { public static void main(String... args) throws FileNotFoundException, OWLOntologyCreationException, OWLOntologyStorageException { @@ -48,11 +26,13 @@ public class HermitQueryReasoner { // args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/npd/npd-all-minus-datatype.owl", "/media/krr-nas-share/Yujiao/ontologies/npd/data/npd-data-dump-minus-datatype-new.ttl", "/users/yzhou/ontologies/npd/queries/atomic.sparql"}; // args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/npd/npd-all.owl", "/media/krr-nas-share/Yujiao/ontologies/npd/data/npd-data-dump-processed.ttl", "/users/yzhou/ontologies/npd/queries/atomic.sparql"}; // args = new String[] {PagodaTester.dbpedia_tbox, PagodaTester.dbpedia_abox, PagodaTester.dbpedia_query}; -// args = new String[] {"/users/yzhou/ontologies/test/unsatisfiable.owl", null, "/users/yzhou/ontologies/test/unsatisfiable_queries.sparql"}; +// args = new String[] {"/users/yzhou/ontologies/answersCorrectness/unsatisfiable.owl", null, "/users/yzhou/ontologies/answersCorrectness/unsatisfiable_queries.sparql"}; -// args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/cco-processed-noDPR-noDPD.ttl", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/graph sampling/sample_100.nt", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/queries/atomic_one_filtered.sparql", "../test-share/results/chembl/hermit_1p"}; - args = new String[] {"/users/yzhou/temp/uniprot_debug/core-processed-noDis.owl", "/users/yzhou/temp/uniprot_debug/sample_1_removed.nt", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/queries/atomic_one.sparql", "../test-share/results/uniprot/hermit_1p"}; } -// args = new String[] {"imported.owl", "", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/queries/atomic_one.sparql", "../test-share/results/uniprot/hermit_1p"}; } +// args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/cco-processed-noDPR-noDPD.ttl", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/graph sampling/sample_100.nt", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/queries/atomic_one_filtered.sparql", "../answersCorrectness-share/results/chembl/hermit_1p"}; + args = + new String[]{"/users/yzhou/temp/uniprot_debug/core-processed-noDis.owl", "/users/yzhou/temp/uniprot_debug/sample_1_removed.nt", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/queries/atomic_one.sparql", "../answersCorrectness-share/results/uniprot/hermit_1p"}; + } +// args = new String[] {"imported.owl", "", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/queries/atomic_one.sparql", "../answersCorrectness-share/results/uniprot/hermit_1p"}; } PrintStream ps = args.length < 4 ? null : new PrintStream(new File(args[3])); @@ -60,8 +40,8 @@ public class HermitQueryReasoner { if (args[i] == null || args[i].equalsIgnoreCase("null")) args[i] = ""; System.out.println("Argument " + i + ": " + args[i]); } - -// PrintStream ps = null; // new PrintStream(new File("../test-share/results/reactome/ ")); + +// PrintStream ps = null; // new PrintStream(new File("../answersCorrectness-share/results/reactome/ ")); if (ps != null) System.setOut(ps); Timer t = new Timer(); diff --git a/test/uk/ac/ox/cs/hermit/JAIR_HermiT.java b/test/uk/ac/ox/cs/hermit/JAIR_HermiT.java index a3264ba..72e7af8 100644 --- a/test/uk/ac/ox/cs/hermit/JAIR_HermiT.java +++ b/test/uk/ac/ox/cs/hermit/JAIR_HermiT.java @@ -11,8 +11,8 @@ public class JAIR_HermiT { String[] args = new String[] { TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), TestUtil.combinePaths(ontoDir, "lubm/data/lubm1_owl"), - TestUtil.combinePaths(ontoDir, "lubm/queries/test.sparql") -// , "/home/yzhou/java-workspace/test-share/results_new/lubm1/hermit" + TestUtil.combinePaths(ontoDir, "lubm/queries/answersCorrectness.sparql") +// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/lubm1/hermit" }; HermitQueryReasoner.main(args); } @@ -24,7 +24,7 @@ public class JAIR_HermiT { "/home/yzhou/backup/20141212/univ-bench-queries.owl", TestUtil.combinePaths(ontoDir, "lubm/data/lubm1_owl"), TestUtil.combinePaths(ontoDir, "lubm/queries/atomic_lubm.sparql") -// , "/home/yzhou/java-workspace/test-share/results_new/lubm1/hermit_rolledUp" +// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/lubm1/hermit_rolledUp" }; HermitQueryReasoner.main(args); } @@ -37,7 +37,7 @@ public class JAIR_HermiT { TestUtil.combinePaths(ontoDir, "uobm/data/uobm1_owl_withDeclaration"), TestUtil.combinePaths(ontoDir, "uobm/queries/standard.sparql") // , "hermit_uobm1.out" -// , "/home/yzhou/java-workspace/test-share/results_new/uobm1/hermit" +// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uobm1/hermit" }; HermitQueryReasoner.main(args); } @@ -50,7 +50,7 @@ public class JAIR_HermiT { TestUtil.combinePaths(ontoDir, "uobm/data/uobm1_owl_withDeclaration"), TestUtil.combinePaths(ontoDir, "uobm/queries/atomic_uobm.sparql") , "hermit_uobm1_rolledUp.out" -// , "/home/yzhou/java-workspace/test-share/results_new/uobm1/hermit_rolledUp" +// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uobm1/hermit_rolledUp" }; HermitQueryReasoner.main(args); } @@ -75,7 +75,7 @@ public class JAIR_HermiT { TestUtil.combinePaths(ontoDir, "npd/data/npd-data-dump-minus-datatype-new.ttl"), TestUtil.combinePaths(ontoDir, "npd/queries/atomic_ground.sparql") , "hermit_npd.out" -// , "/home/yzhou/java-workspace/test-share/results_new/npd/hermit" +// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/npd/hermit" ); } @@ -86,7 +86,7 @@ public class JAIR_HermiT { 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") - , "/home/yzhou/java-workspace/test-share/results_new/dbpedia/hermit" + , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/dbpedia/hermit" ); } @@ -97,7 +97,7 @@ public class JAIR_HermiT { TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/biopax-level3-processed.owl"), TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/graph sampling/reactome_sample_10.ttl"), TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/queries/atomic_ground.sparql") - , "/home/yzhou/java-workspace/test-share/results_new/reactome/hermit_10p" + , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/reactome/hermit_10p" ); } @@ -110,7 +110,7 @@ public class JAIR_HermiT { TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/graph sampling/sample_1.nt"), TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/queries/atomic_ground.sparql") , "hermit_chembl.out" -// , "/home/yzhou/java-workspace/test-share/results_new/chembl/hermit_1p" +// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/chembl/hermit_1p" ); } @@ -122,7 +122,7 @@ public class JAIR_HermiT { TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/graph sampling/sample_1.nt"), TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/queries/atomic_ground.sparql") , "hermit_uniprot.out" -// , "/home/yzhou/java-workspace/test-share/results_new/uniprot/hermit_1p" +// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uniprot/hermit_1p" ); } diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswers.java b/test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswers.java new file mode 100644 index 0000000..14050ce --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswers.java @@ -0,0 +1,35 @@ +package uk.ac.ox.cs.pagoda.global_tests; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import org.testng.Assert; +import uk.ac.ox.cs.pagoda.query.QueryRecord; + +import java.io.BufferedReader; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Set; + +/** + * It provides auxiliary methods for checking answers. + * */ +public class CheckAnswers { + + private CheckAnswers() { + } + + public static void assertSameAnswers(Path computedAnswersFile, Path givenAnswersFile) throws IOException { + BufferedReader computedReader = Files.newBufferedReader(computedAnswersFile); + BufferedReader givenReader = Files.newBufferedReader(givenAnswersFile); + + Gson gson = QueryRecord.GsonCreator.getInstance(); + + Type cqType = new TypeToken>() {}.getType(); + Set computedAnswers = gson.fromJson(computedReader, cqType); + Set givenAnswers = gson.fromJson(givenReader, cqType); + + Assert.assertEquals(computedAnswers, givenAnswers); + } +} diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswersOverDataset.java b/test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswersOverDataset.java deleted file mode 100644 index 424afa2..0000000 --- a/test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswersOverDataset.java +++ /dev/null @@ -1,48 +0,0 @@ -package uk.ac.ox.cs.pagoda.global_tests; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import org.testng.Assert; -import uk.ac.ox.cs.pagoda.Pagoda; -import uk.ac.ox.cs.pagoda.query.QueryRecord; - -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.Set; - -/** - * Given an instance of Pagoda, it checks the returned answers. - * */ -public class CheckAnswersOverDataset { - - public static void check(Pagoda pagoda, Path givenAnswers) { - try { -// Utility.setLogLevel(Level.DEBUG); // uncomment for outputting partial results - Path computedAnswers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); - new File(computedAnswers.toString()).deleteOnExit(); - - pagoda.run(); - assertSameContent(computedAnswers, givenAnswers); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private static void assertSameContent(Path computedAnswersFile, Path givenAnswersFile) throws IOException { - BufferedReader computedReader = Files.newBufferedReader(computedAnswersFile); - BufferedReader givenReader = Files.newBufferedReader(givenAnswersFile); - - Gson gson = QueryRecord.GsonCreator.getInstance(); - - Type cqType = new TypeToken>() {}.getType(); - Set computedAnswers = gson.fromJson(computedReader, cqType); - Set givenAnswers = gson.fromJson(givenReader, cqType); - - Assert.assertEquals(computedAnswers, givenAnswers); - } -} diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/JAIR_PAGOdA.java b/test/uk/ac/ox/cs/pagoda/global_tests/JAIR_PAGOdA.java index 0d77fdb..18f6cf9 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/JAIR_PAGOdA.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/JAIR_PAGOdA.java @@ -8,16 +8,24 @@ import java.io.IOException; public class JAIR_PAGOdA { + public static void main(String... args) { + try { + new JAIR_PAGOdA().lubm1(); + } catch(IOException e) { + e.printStackTrace(); + } + } + @Test public void lubm1() throws IOException { String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); String[] args = new String[] { TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), TestUtil.combinePaths(ontoDir, "lubm/data/lubm1.ttl"), - TestUtil.combinePaths(ontoDir, "lubm/queries/test.sparql") + TestUtil.combinePaths(ontoDir, "lubm/queries/answersCorrectness.sparql") }; PagodaTester.main(args); - TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/lubm1/pagoda"); + TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/lubm1/pagoda"); } @Test @@ -29,7 +37,7 @@ public class JAIR_PAGOdA { TestUtil.combinePaths(ontoDir, "lubm/queries/test_pellet.sparql") }; PagodaTester.main(args); - TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/lubm1/pagoda_conj"); + TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/lubm1/pagoda_conj"); } @Test @@ -40,7 +48,7 @@ public class JAIR_PAGOdA { 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"); + TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/lubm1/pagoda_rolledUp"); } @Test @@ -52,7 +60,7 @@ public class JAIR_PAGOdA { TestUtil.combinePaths(ontoDir, "uobm/queries/standard.sparql") }; PagodaTester.main(args); - TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uobm1/pagoda"); + TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uobm1/pagoda"); } @Test @@ -64,7 +72,7 @@ public class JAIR_PAGOdA { TestUtil.combinePaths(ontoDir, "uobm/queries/standard_pellet.sparql") }; PagodaTester.main(args); - TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uobm1/pagoda_conj"); + TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uobm1/pagoda_conj"); } @Test @@ -76,7 +84,7 @@ public class JAIR_PAGOdA { TestUtil.combinePaths(ontoDir, "uobm/queries/atomic_uobm.sparql") }; PagodaTester.main(args); -// TestUtil.copyFile(("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/uobm1/pagoda_rolledUp"); +// TestUtil.copyFile(("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uobm1/pagoda_rolledUp"); } @Test @@ -88,7 +96,7 @@ public class JAIR_PAGOdA { TestUtil.combinePaths(ontoDir, "fly/queries/fly_pellet.sparql") }; PagodaTester.main(args); -// TestUtil.copyFile(("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/fly/pagoda"); +// TestUtil.copyFile(("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/fly/pagoda"); } @Test @@ -100,10 +108,9 @@ public class JAIR_PAGOdA { TestUtil.combinePaths(ontoDir, "fly/queries/fly_pellet.sparql") }; PagodaTester.main(args); - TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/fly/pagoda_conj"); + TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/fly/pagoda_conj"); } - public void fly_rolledUp() { String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main( @@ -112,7 +119,7 @@ public class JAIR_PAGOdA { null, TestUtil.combinePaths(ontoDir, "fly/queries/fly_atomic.sparql") ); -// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/fly/pagoda_rolledUp"); +// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/fly/pagoda_rolledUp"); } public void dbpedia() { @@ -124,7 +131,7 @@ public class JAIR_PAGOdA { "dbpedia.ans" ); -// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/dbpedia/pagoda"); +// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/dbpedia/pagoda"); } public void npd() { @@ -136,7 +143,7 @@ public class JAIR_PAGOdA { , "npd.ans" ); -// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/npd/pagoda"); +// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/npd/pagoda"); } public void reactome() throws IOException { @@ -151,7 +158,7 @@ public class JAIR_PAGOdA { ); TestUtil.copyFile("log4j.log", "output/jair/pagoda_reactome.example"); -// TestUtil.copyFile(("output/log4j.log", "/home/yzhou/java-workspace/test-share/results_new/reactome/pagoda_10p"); +// TestUtil.copyFile(("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/reactome/pagoda_10p"); } public void chembl() throws IOException { @@ -164,7 +171,7 @@ public class JAIR_PAGOdA { , "pagoda_chembl.ans" ); 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"); +// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/chembl/pagoda_1p"); } public void uniprot() throws IOException { @@ -178,16 +185,7 @@ public class JAIR_PAGOdA { , "pagoda_uniprot.ans" ); 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"); - } - - - public static void main(String... args) { - try { - new JAIR_PAGOdA().lubm1(); - } catch (IOException e) { - e.printStackTrace(); - } +// TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uniprot/pagoda_1p"); } } diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/JAIR_Scalability.java b/test/uk/ac/ox/cs/pagoda/global_tests/JAIR_Scalability.java index 687ffee..5feda35 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/JAIR_Scalability.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/JAIR_Scalability.java @@ -9,13 +9,18 @@ import java.io.IOException; public class JAIR_Scalability { - private static final String date = "_0123"; + private static final String date = "_0123"; + public static void main(String... args) throws IOException { + Properties.shellModeDefault = true; + new JAIR_Scalability().testUniProt(50, false); + } + @Test public void reactome() throws IOException { testReactome(10, false); } - + @Test public void chembl() throws IOException { testChEMBL(1, false); @@ -31,15 +36,15 @@ public class JAIR_Scalability { String[] args = new String[] { 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") + TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/queries/answersCorrectness.sparql") , "reactome.ans" - }; + }; if (percentage == 10) args[1] = args[1].replace("simplifed", "reactome"); - - PagodaTester.main(args); + + PagodaTester.main(args); if (save) - TestUtil.copyFile("log4j.log", "/home/yzhou/java-workspace/test-share/results_new/reactome/pagoda_" + percentage + "p" + date); + TestUtil.copyFile("log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/reactome/pagoda_" + percentage + "p" + date); } public void testChEMBL(int percentage, boolean save) throws IOException { @@ -48,18 +53,18 @@ public class JAIR_Scalability { 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") + TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/queries/answersCorrectness.sparql") , "chembl.ans" - }; + }; if (percentage == 1 || percentage == 10 || percentage == 50) args[1] = args[1].replace("chembl", "chembl/graph sampling"); - else + else if (percentage == 100) - args[1] = "/home/yzhou/RDFData/ChEMBL/facts/ChEMBL.ttl"; - + args[1] = "/home/yzhou/RDFData/ChEMBL/facts/ChEMBL.ttl"; + PagodaTester.main(args); if (save) - TestUtil.copyFile("log4j.log", "/home/yzhou/java-workspace/test-share/results_new/chembl/pagoda_" + percentage + "p" + date); + TestUtil.copyFile("log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/chembl/pagoda_" + percentage + "p" + date); } public void testUniProt(int percentage, boolean save) throws IOException { @@ -68,24 +73,19 @@ public class JAIR_Scalability { 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") + TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/queries/answersCorrectness.sparql") , "uniprot.ans" - }; - + }; + if (percentage == 1 || percentage == 10 || percentage == 50) args[1] = args[1].replace("uniprot", "uniprot/graph sampling"); - else + else if (percentage == 100) - args[1] = "/home/yzhou/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/data/uniprot_cleaned.nt"; - - PagodaTester.main(args); + args[1] = "/home/yzhou/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/data/uniprot_cleaned.nt"; + + PagodaTester.main(args); if (save) - 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 { - Properties.shellModeDefault = true; - new JAIR_Scalability().testUniProt(50, false); + TestUtil.copyFile("log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uniprot/pagoda_" + percentage + "p" + date); } } diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/LightEvaluation.java b/test/uk/ac/ox/cs/pagoda/global_tests/LightEvaluation.java index b073a26..7fc5da8 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/LightEvaluation.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/LightEvaluation.java @@ -4,12 +4,13 @@ import org.testng.annotations.Test; import java.io.IOException; +@Deprecated public class LightEvaluation { @Test public void evaluation() throws IOException { - new TestPagodaUOBM().test(1); - new TestPagodaLUBM().test(100); + new TestPagodaUOBM().answersCorrectness(1); + new TestPagodaLUBM().answersCorrecntess(100); new TestPagodaFLY().test(); new TestPagodaDBPedia().test(); new TestPagodaNPD().testNPDwithoutDataType(); diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java index bb58681..8cbe022 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java @@ -4,42 +4,57 @@ import org.testng.annotations.Test; import uk.ac.ox.cs.pagoda.Pagoda; import uk.ac.ox.cs.pagoda.util.TestUtil; +import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.nio.file.Paths; public class TestPagodaLUBM { - public void test(int number) throws IOException { + /** + * Just execute on LUBM 100 + */ + public static void main(String... args) { + new TestPagodaLUBM().justExecute_100(); + } + + public void answersCorrecntess(int number) throws IOException { String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); + Path computedAnswers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); + new File(computedAnswers.toString()).deleteOnExit(); + Pagoda pagoda = Pagoda.builder() .ontology(Paths.get(ontoDir, "lubm/univ-bench.owl")) .data(Paths.get(ontoDir, "lubm/data/lubm" + number + ".ttl")) .query(Paths.get(ontoDir, "lubm/queries/test.sparql")) + .answer(computedAnswers) .classify(true) .hermit(true) .build(); - CheckAnswersOverDataset.check(pagoda, Paths.get(ontoDir, "lubm/lubm" + number + ".json")); + pagoda.run(); + + Path givenAnswers = Paths.get(ontoDir, "lubm/lubm" + number + ".json"); + CheckAnswers.assertSameAnswers(computedAnswers, givenAnswers); } - @Test - public void test_1() throws IOException { - test(1); + @Test(groups = {"light"}) + public void answersCorrectness_1() throws IOException { + answersCorrecntess(1); } + /** + * Just execute on LUBM 100 + * */ public void justExecute_100() { int number = 100; String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); Pagoda pagoda = Pagoda.builder() .ontology(Paths.get(ontoDir, "lubm/univ-bench.owl")) .data(Paths.get(ontoDir, "lubm/data/lubm" + number + ".ttl")) - .query(Paths.get(ontoDir, "lubm/queries/test.sparql")) + .query(Paths.get(ontoDir, "lubm/queries/answersCorrectness.sparql")) .classify(true) .hermit(true) .build(); pagoda.run(); } - - public static void main(String... args) { - new TestPagodaLUBM().justExecute_100(); - } } diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java index 61235d3..23d79ab 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java @@ -6,48 +6,57 @@ import uk.ac.ox.cs.pagoda.Pagoda; import uk.ac.ox.cs.pagoda.tester.PagodaTester; import uk.ac.ox.cs.pagoda.util.TestUtil; +import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.nio.file.Paths; import static uk.ac.ox.cs.pagoda.util.TestUtil.combinePaths; public class TestPagodaUOBM { - public void test(int number) throws IOException { + + private static final int N_1 = 1; + private static final int N_2 = 10; + + @DataProvider(name = "uobmNumbers") + public static Object[][] uobmNumbers() { + Integer[][] integers = new Integer[N_2 - N_1 + 1][1]; + for(int i = 0; i < N_2 - N_1 + 1; i++) + integers[i][0] = N_1 + i; + return integers; + } + + public void answersCorrectness(int number) throws IOException { String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); + Path computedAnswers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); + new File(computedAnswers.toString()).deleteOnExit(); + Pagoda pagoda = Pagoda.builder() .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl")) .query(Paths.get(ontoDir, "uobm/queries/test.sparql")) + .answer(computedAnswers) .classify(true) .hermit(true) .build(); - CheckAnswersOverDataset.check(pagoda, - Paths.get(ontoDir, "uobm/uobm" + number + ".json")); - } + pagoda.run(); - @Test - public void test_1() throws IOException { - test(1); + String given_answers = "uobm/uobm" + number + ".json"; + CheckAnswers.assertSameAnswers(computedAnswers, Paths.get(ontoDir, given_answers)); } - private static final int N_1 = 1; - private static final int N_2 = 10; - - @DataProvider(name = "uobmNumbers") - public static Object[][] uobmNumbers() { - Integer[][] integers = new Integer[N_2 - N_1 + 1][1]; - for (int i = 0; i < N_2 - N_1 + 1; i++) - integers[i][0]= N_1 + i; - return integers; + @Test(groups = {"light"}) + public void answersCorrectness_1() throws IOException { + answersCorrectness(1); } - @Test(dataProvider = "uobmNumbers") + @Test(groups = {"heavy"}, dataProvider = "uobmNumbers") public void justExecute(int number) { String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); PagodaTester.main(combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), combinePaths(ontoDir, "uobm/data/uobm" + number + ".ttl"), - combinePaths(ontoDir, "uobm/queries/test.sparql")); + combinePaths(ontoDir, "uobm/queries/answersCorrectness.sparql")); } } diff --git a/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java b/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java index 7d9b49c..274946d 100644 --- a/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java +++ b/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java @@ -1,46 +1,318 @@ package uk.ac.ox.cs.pagoda.tester; +import uk.ac.ox.cs.pagoda.query.AnswerTuple; +import uk.ac.ox.cs.pagoda.query.AnswerTuples; 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; -// TODO clean it, or code another one +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Scanner; + +@Deprecated public class PagodaTester { + // public static final String onto_dir = "/media/RDFData/yzhou/"; +// public static final String onto_dir = "/users/yzhou/ontologies/"; +// public static final String onto_dir = "/home/scratch/yzhou/ontologies/"; + public static final String onto_dir = "/home/alessandro/Big_files/Ontologies/"; + + public static final String fly = onto_dir + "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl"; + public static final String fly_query = onto_dir + "fly/queries/fly.sparql"; + + public static final String test_tbox = onto_dir + "smallExampleFromAna/dummy.owl"; + public static final String test_abox = onto_dir + "smallExampleFromAna/initialABox.ttl"; + public static final String test_query = onto_dir + "smallExampleFromAna/queries.dlog"; + + public static final int lubm_number = 1; + public static final String lubm_tbox = onto_dir + "lubm/univ-bench.owl"; + public static final String lubm_abox = onto_dir + "lubm/data/lubm" + lubm_number + ".ttl"; + public static final String lubm_abox_copy = onto_dir + "lubm/data/lubm" + lubm_number + " (copy).ttl"; + public static final String lubm_query = onto_dir + "lubm/queries/test.sparql"; + public static final String lubm_query6 = onto_dir + "lubm/queries/test_q6.sparql"; + public static final String lubm_query20 = onto_dir + "lubm/queries/test_q16.sparql"; + + public static final int uobm_number = 1; + public static final String uobm_tbox = onto_dir + "uobm/univ-bench-dl.owl"; + public static final String uobm_abox = onto_dir + "uobm/data/uobm" + uobm_number + ".ttl"; + public static final String uobm_query = onto_dir + "uobm/queries/test.sparql"; + public static final String uobm_query_temp = onto_dir + "uobm/queries/temp.sparql"; + public static final String uobm_query2 = onto_dir + "uobm/queries/standard_q2.sparql"; + public static final String uobm_query9 = onto_dir + "uobm/queries/standard_q9.sparql"; + public static final String uobm_query11 = onto_dir + "uobm/queries/standard_q11.sparql"; + public static final String uobm_query12 = onto_dir + "uobm/queries/standard_q12.sparql"; + public static final String uobm_query14 = onto_dir + "uobm/queries/standard_q14.sparql"; + public static final String uobm_query15 = onto_dir + "uobm/queries/standard_q15.sparql"; + public static final String uobm_query_multi = onto_dir + "uobm/queries/standard_multi.sparql"; + public static final String uobm_generated_query1 = onto_dir + "uobm/queries/generated_q1.sparql"; + public static final String uobm_query_group3 = onto_dir + "uobm/queries/standard_group3.sparql"; + + public static final String npd_tbox = onto_dir + "npd/npd-all-minus-datatype.owl"; + // "npd/npd-all.owl"; + // "npd-all-minus-datatype.owl"; + public static final String npd_abox = onto_dir + "npd/data/npd-data-dump-minus-datatype-new.ttl"; + // "npd/data/npd-data-dump-processed.ttl"; + // "npd-data-dump-minus-datatype-old.ttl"; + public static final String npd_query = onto_dir + "npd/queries/atomic.sparql"; + + public static final String npd_bench_tbox = onto_dir + "npd-benchmark/npd-v2-ql_a.owl"; + // npd-all-minus-datatype.owl"; + public static final String npd_bench_abox = onto_dir + "npd-benchmark/npd-v2-ql_a.ttl"; + // npd-data-dump-minus-datatype-old.ttl"; + public static final String npd_bench_query = onto_dir + "npd-benchmark/queries/all.sparql"; + + public static final String dbpedia_tbox = onto_dir + "dbpedia/integratedOntology-all-in-one-minus-datatype.owl"; + public static final String dbpedia_abox = onto_dir + "dbpedia/data/dbpedia-minus-datatype-new.ttl"; + public static final String dbpedia_query = onto_dir + "dbpedia/queries/atomic_ground.sparql"; + public static final String dbpedia_query274 = onto_dir + "dbpedia/atomic_q274.sparql"; + + public static final String dbpedia_latest_tbox = onto_dir + "dbpedia/dbpedia_2014.owl"; + public static final String travel_tbox = onto_dir + "dbpedia/travel.owl"; + public static final String dbpedia_tbox_simple = onto_dir + "dbpedia/dbpedia_simple.owl"; + + public static final String bioModels_tbox = onto_dir + "biomodels/biomodels-21.owl"; + public static final String bioModels_abox = onto_dir + "biomodels/data_processed_1.ttl"; + public static final String bioModels_queries = onto_dir + "biomodels/queries/queries.sparql"; + + public static final String chembl_tbox = onto_dir + "bio2rdf/chembl/cco-processed-noDPR-noDPD.ttl"; + public static final String chembl_abox = onto_dir + "bio2rdf/chembl/graph sampling old/sample_100.nt"; + public static final String chembl_queries = onto_dir + "bio2rdf/chembl/queries/problematic.sparql"; + //"bio2rdf/chembl/queries/atomic_one_filtered.sparql"; // + + public static final String reactome_tbox = onto_dir + "bio2rdf/reactome/biopax-level3-processed.owl"; + public static final String reactome_abox = onto_dir + "bio2rdf/reactome/graph sampling old/sample.ttl"; + //data/data.ttl"; //graph sampling old/reactome_sample_10.ttl"; // + public static final String reactome_queries = onto_dir + "bio2rdf/reactome/queries/atomic.sparql"; + + public static final String uniprot_tbox = onto_dir + "bio2rdf/uniprot/core-processed.owl"; + public static final String uniprot_abox = onto_dir + "bio2rdf/uniprot/graph sampling/sample_1.nt"; + public static final String uniprot_queries = onto_dir + "bio2rdf/uniprot/queries/atomic_one.sparql"; + + public static final String atlas_tbox = onto_dir + "bio2rdf/atlas/gxaterms.owl"; + public static final String atlas_abox = onto_dir + "bio2rdf/atlas/graph sampling/sample_1.nt"; + public static final String atlas_queries = onto_dir + "bio2rdf/atlas/queries/atomic_one.sparql"; + QueryReasoner pagoda; + + // private void printPredicatesWithGap() { +// for (String p: ((MyQueryReasoner) pagoda).getPredicatesWithGap()) { +// System.out.println(p); +// } +// } + Timer timer = new Timer(); + + public PagodaTester(QueryReasoner reasoner) { + pagoda = reasoner; + } + public static void main(String... args) { -// Properties properties = new Properties(PagodaTester.class. -// getClassLoader().getResource("uobm.properties").getPath()); - Properties properties = new Properties(); - - int index = 0; - if (args.length > index) properties.setOntologyPath(args[index++]); - if (args.length > index && (args[index].endsWith(".ttl") || args[index].endsWith(".nt"))) properties.setDataPath(args[index++]); - if (args.length > index && args[index].endsWith(".sparql")) properties.setQueryPath(args[index++]); - if (args.length > index && !args[index].startsWith("-")) properties.setAnswerPath(args[index++]); - if (args.length > index) properties.setToClassify(Boolean.parseBoolean(args[index++].substring(1))); - if (args.length > index) properties.setToCallHermiT(Boolean.parseBoolean(args[index++].substring(1))); - + 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[] {uobm_tbox, uobm_abox, uobm_query}; +// args = new String[] {fly, "null", fly_query}; +// args = new String[] {dbpedia_tbox, dbpedia_abox, dbpedia_query}; +// args = new String[] {travel_tbox, null, dbpedia_query274}; + args = new String[]{fly, fly_query}; +// args = new String[] {npd_tbox, npd_abox, npd_query}; +// args = new String[] {npd_bench_tbox, npd_bench_abox, npd_bench_query}; +// args = new String[] {"../SemFacet/WebContent/WEB-INF/data/dbpedia.owl", "../SemFacet/WebContent/WEB-INF/data/dbpediaA.nt", null}; +// args = new String[] {"../core/WebContent/WEB-INF/data/fly.owl", "../core/WebContent/WEB-INF/data/fly-data.nt", null}; +// args = new String[] {"data/lubm/univ-bench.owl", "data/lubm/lubm1.ttl", "data/lubm/lubm.sparql", "lubm.ans"}; +// args = new String[] {"data/uobm/univ-bench-dl.owl", "data/uobm/uobm1.ttl", "data/uobm/uobm.sparql", "uobm.ans"}; +// args = new String[] {"data/fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", "data/fly/fly.sparql", "fly.ans"}; +// args = new String[] {bioModels_tbox, bioModels_abox, bioModels_queries}; +// args = new String[] {chembl_tbox, chembl_abox, chembl_queries}; +// args = new String[] {reactome_tbox, reactome_abox, reactome_queries}; +// args = new String[] {reactome_tbox, "/users/yzhou/temp/reactome_debug.ttl", onto_dir +"bio2rdf/reactome/queries/atomic_one_q65.sparql"}; +// args = new String[] {uniprot_tbox.replace(".owl", "-noDis.owl"), "/users/yzhou/temp/uniprot_debug/sample_1_string.nt", uniprot_queries}; +// args = new String[] {uniprot_tbox.replace(".owl", "-noDis.owl"), uniprot_abox, uniprot_queries}; +// args = new String[] {atlas_tbox, atlas_abox, atlas_queries}; +// args = new String[] {onto_dir + "test/unsatisfiable.owl", null, onto_dir + "test/unsatisfiable_queries.sparql"}; +// args = new String[] {onto_dir + "test/jair-example.owl", null, onto_dir + "test/jair-example_query.sparql"}; +// args[2] = args[2].replace(".sparql", "_all_pagoda.sparql"); +// args[2] = args[2].replace(".sparql", "_pellet.sparql"); + } + + Properties properties = new Properties("config/uobm.properties"); + + int index = 0; + if(args.length > index) properties.setOntologyPath(args[index++]); + if(args.length > index && (args[index].endsWith(".ttl") || args[index].endsWith(".nt"))) + properties.setDataPath(args[index++]); + if(args.length > index && args[index].endsWith(".sparql")) properties.setQueryPath(args[index++]); + if(args.length > index && !args[index].startsWith("-")) properties.setAnswerPath(args[index++]); + if(args.length > index) properties.setToClassify(Boolean.parseBoolean(args[index++].substring(1))); + if(args.length > index) properties.setToCallHermiT(Boolean.parseBoolean(args[index++].substring(1))); + Utility.logInfo("Ontology file: " + properties.getOntologyPath()); Utility.logInfo("Data files: " + properties.getDataPath()); Utility.logInfo("Query files: " + properties.getQueryPath()); Utility.logInfo("Answer file: " + properties.getAnswerPath()); - - QueryReasoner pagoda = null; - + + QueryReasoner pagoda = null; + try { Timer t = new Timer(); - pagoda = QueryReasoner.getInstance(properties); + pagoda = QueryReasoner.getInstance(properties); if (pagoda == null) return; - + Utility.logInfo("Preprocessing Done in " + t.duration() + " seconds."); - + if (properties.getQueryPath() != null) for (String queryFile: properties.getQueryPath().split(";")) pagoda.evaluate(pagoda.getQueryManager().collectQueryRecords(queryFile)); + + if(properties.getShellMode()) + try { + evaluateConsoleQuery(pagoda); + } catch(IOException e) { + e.printStackTrace(); + } } finally { if (pagoda != null) pagoda.dispose(); } + +// Utility.closeCurrentOut(); + + if(properties.getShellMode()) System.exit(0); + } + + private static void evaluateConsoleQuery(QueryReasoner pagoda) throws IOException { + int ending = (int) '$', symbol; + while(true) { + Utility.logInfo("Input your query ending with $"); + StringBuilder queryBuilder = new StringBuilder(); + while((symbol = System.in.read()) != ending) { + queryBuilder.append((char) symbol); + } + System.in.read(); + if(queryBuilder.length() == 0) return; + pagoda.evaluate_shell(queryBuilder.toString()); + } + } + + void testReactomeQueries() { + evaluate("select ?x where { ?x . }"); + evaluate("select ?y ?z where { ?y ?z . }"); + evaluate("select ?y where { ?y . }", true); + + } + + void testSemFacetQueries() { +// try { +// BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("query.line"))); +// for (String line; (line = reader.readLine()) != null && !line.isEmpty(); ) +// evaluate(line, true); +// reader.close(); +// } catch (FileNotFoundException e) { +// e.printStackTrace(); +// } catch (IOException e) { +// e.printStackTrace(); +// } + evaluate("select ?x ?z where { ?x ?z }", true); + evaluate("select distinct ?y where { ?x ?y ?z }", true); + evaluate("select distinct ?z where { ?x ?z }", true); + evaluate("select ?y ?z where { ?y ?z .}", true); + } + + void testISGQueries() { + evaluate("select ?z where { ?z .}", false); + evaluate("select ?x where {?x .}", false); + } + + void testSomeTravelQueries() { + evaluate("select ?y ?z where { ?y ?z. }", true); + evaluate("select ?x where {?x . }"); + evaluate("select ?x where {?x . }"); + } + + void testSomeFlyQueries() { + evaluate("select ?x where { ?x . }", false); + + evaluate("select DISTINCT ?z where { ?x ?any . ?any ?z . ?x . } ", true); + + evaluate("Select ?x where { ?x " + + ". ?x " + + " ?any . ?any " + + " " + + " . }", true); + + evaluate("Select ?x where {?x " + + " . ?x " + + " ?any . ?any " + + " " + + " . }", true); + +// evaluate("Select ?x where { " +// + "?x . " +// + "?x ?any . " +// + "?any . }", true); + + evaluate("select DISTINCT ?z where { ?x ?any . " + + "?any ?z . " + + "?x . } ", true); + + evaluate("Select * where {" + + " . " + + " ?z }", true); + + evaluate("SELECT DISTINCT ?x ?z WHERE {?x ?z}", true); + evaluate("SELECT DISTINCT ?x ?z WHERE {?x ?z}", true); + + evaluate("select DISTINCT ?y where { ?x ?y ?z . " + + "?x }", true); + + evaluateQueriesFromFile("/users/yzhou/Downloads/logs(1).log"); + evaluateQueriesFromFile("/users/yzhou/Downloads/logs.log"); + + evaluate("SELECT DISTINCT ?x ?z WHERE {?x ?z}", true); + evaluate("SELECT DISTINCT ?x ?z WHERE {?x ?z}", true); + + evaluate("select ?x ?z where { ?x ?z } ", true); + evaluate("select ?x ?z where { ?x ?z } ", true); + } + + public void evaluateQueriesFromFile(String fileName) { + Scanner scanner = null; + try { + scanner = new Scanner(new File(fileName)); + String line; + while(scanner.hasNextLine()) { + line = scanner.nextLine(); + if(line.startsWith("select")) + evaluate(line, true); + } + } catch(FileNotFoundException e) { + e.printStackTrace(); + } finally { + if(scanner != null) + scanner.close(); + } + } + + private void evaluate(String query) { + evaluate(query, false); + } + + private void evaluate(String query, boolean tag) { + timer.reset(); + AnswerTuples tuples = pagoda.evaluate(query, tag); + int arity = tuples.getArity(); + int count = 0; + for(AnswerTuple tuple; tuples.isValid(); tuples.moveNext()) { + tuple = tuples.getTuple(); + for(int i = 0; i < arity; ++i) + tuple.getGroundTerm(i).toString(); +// System.out.print(tuple.getGroundTerm(i).toString() + "\t"); +// System.out.println(); + ++count; + } + tuples.dispose(); + Utility.logInfo("The number of answers for this SemFacet query: " + count); + Utility.logInfo("Total time for this SemFacet query: " + timer.duration()); } } diff --git a/test/uk/ac/ox/cs/pagoda/tester/Statistics.java b/test/uk/ac/ox/cs/pagoda/tester/Statistics.java index 71f1726..13d7f90 100644 --- a/test/uk/ac/ox/cs/pagoda/tester/Statistics.java +++ b/test/uk/ac/ox/cs/pagoda/tester/Statistics.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.Scanner; +@Deprecated public class Statistics { double satCheckTime; diff --git a/test/uk/ac/ox/cs/pagoda/util/TestUtil.java b/test/uk/ac/ox/cs/pagoda/util/TestUtil.java index 1802147..ad0d494 100644 --- a/test/uk/ac/ox/cs/pagoda/util/TestUtil.java +++ b/test/uk/ac/ox/cs/pagoda/util/TestUtil.java @@ -26,8 +26,7 @@ public class TestUtil { public static Properties getConfig() { if(!isConfigLoaded) { - try (InputStream in = TestUtil.class.getClassLoader() - .getResourceAsStream(CONFIG_FILE)) { + try(InputStream in = TestUtil.class.getClassLoader().getResourceAsStream(CONFIG_FILE)) { config = new java.util.Properties(); config.load(in); in.close(); -- cgit v1.2.3