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. --- 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 ++++++++++---------- 3 files changed, 217 insertions(+), 197 deletions(-) (limited to 'src/uk/ac/ox/cs') 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} } -- cgit v1.2.3