From c7dbc7c61c7094ea4ec49bd630023f23b92fd9d1 Mon Sep 17 00:00:00 2001 From: RncLsn Date: Mon, 18 May 2015 18:27:32 +0100 Subject: Configured Maven and improved executable class and tests. --- src/resources/fly.properties | 19 +++ src/resources/log4j.properties | 25 ++++ src/resources/lubm.properties | 20 +++ src/resources/uobm.properties | 20 +++ src/uk/ac/ox/cs/pagoda/Pagoda.java | 164 +++++++++++++++++++++ src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java | 1 + .../rules/approximators/SkolemTermsManager.java | 1 + src/uk/ac/ox/cs/pagoda/util/Properties.java | 4 +- 8 files changed, 252 insertions(+), 2 deletions(-) create mode 100644 src/resources/fly.properties create mode 100644 src/resources/log4j.properties create mode 100644 src/resources/lubm.properties create mode 100644 src/resources/uobm.properties create mode 100644 src/uk/ac/ox/cs/pagoda/Pagoda.java (limited to 'src') diff --git a/src/resources/fly.properties b/src/resources/fly.properties new file mode 100644 index 0000000..88c85c3 --- /dev/null +++ b/src/resources/fly.properties @@ -0,0 +1,19 @@ +#ONTOLOGY variable points to the file that stores ontology of interest +ONTOLOGY=data/fly/fly_anatomy_XP_with_GJ_FC_individuals.owl +#ONTOLOGY=data/fly/fbbt_vfb_ind_pr_nr.owl + +#QUERY variable points to the file that stores all queries +QUERY=data/fly/fly.sparql +#QUERY=data/fly/test.sparql + +#ANSWER variable points to the file to output all answers +#ANSWER=data/fly/fly.ans + +#TO_CLASSIFY switch for the optimisation to specify if the ontology is first classified by HermiT +TO_CLASSIFY=false + +#CALL_HERMIT variable to specify if HermiT is called or not +CALL_HERMIT=true + +#SHELL_MODE to enable query execution from console input +SHELL_MODE=false \ No newline at end of file diff --git a/src/resources/log4j.properties b/src/resources/log4j.properties new file mode 100644 index 0000000..3bfd32e --- /dev/null +++ b/src/resources/log4j.properties @@ -0,0 +1,25 @@ +log = . +log4j.rootLogger=DEBUG, CONSOLE, FILE_LAST, FILE + +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %c - %m%n +log4j.appender.CONSOLE.Target=System.out +log4j.appender.CONSOLE.Threshold=INFO + +log4j.appender.FILE_LAST=org.apache.log4j.RollingFileAppender +log4j.appender.FILE_LAST.File=${log}/pagoda_last_only.log +log4j.appender.FILE_LAST.MaxFileSize=10MB +log4j.appender.FILE_LAST.MaxBackupIndex=3 +log4j.appender.FILE_LAST.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE_LAST.layout.conversionPattern=[%5p] %d{yyyy-MM-dd HH:mm:ss} %c - %m%n +log4j.appender.FILE_LAST.append=false +log4j.appender.FILE_LAST.Threshold=DEBUG + +log4j.appender.FILE=org.apache.log4j.RollingFileAppender +log4j.appender.FILE.File=${log}/pagoda.log +log4j.appender.FILE.MaxFileSize=10MB +log4j.appender.FILE.MaxBackupIndex=3 +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.conversionPattern=[%5p] %d{yyyy-MM-dd HH:mm:ss} %c - %m%n +log4j.appender.FILE.Threshold=DEBUG \ No newline at end of file diff --git a/src/resources/lubm.properties b/src/resources/lubm.properties new file mode 100644 index 0000000..73ed470 --- /dev/null +++ b/src/resources/lubm.properties @@ -0,0 +1,20 @@ +#DATA variable points to the file that stores data +DATA=data/lubm/lubm1.ttl + +#ONTOLOGY variable points to the file that stores ontology of interest +ONTOLOGY=data/lubm/univ-bench.owl + +#QUERY variable points to the file that stores all queries +QUERY=data/lubm/lubm.sparql + +#ANSWER variable points to the file to output all answers +#ANSWER=data/lubm/lubm.ans + +#TO_CLASSIFY switch for the optimisation to specify if the ontology is first classified by HermiT +TO_CLASSIFY=true + +#CALL_HERMIT variable to specify if HermiT is called or not +CALL_HERMIT=true + +#SHELL_MODE to enable query execution from console input +SHELL_MODE=false \ No newline at end of file diff --git a/src/resources/uobm.properties b/src/resources/uobm.properties new file mode 100644 index 0000000..acbe78e --- /dev/null +++ b/src/resources/uobm.properties @@ -0,0 +1,20 @@ +#DATA variable points to the file that stores data +DATA=data/uobm/uobm1.ttl + +#ONTOLOGY variable points to the file that stores ontology of interest +ONTOLOGY=data/uobm/univ-bench-dl.owl + +#QUERY variable points to the file that stores all queries +QUERY=data/uobm/uobm.sparql + +#ANSWER variable points to the file to output all answers +#ANSWER=data/uobm/uobm.ans + +#TO_CLASSIFY switch for the optimisation to specify if the ontology is first classified by HermiT +TO_CLASSIFY=true + +#CALL_HERMIT variable to specify if HermiT is called or not +CALL_HERMIT=true + +#SHELL_MODE to enable query execution from console input +SHELL_MODE=false \ 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 new file mode 100644 index 0000000..3263c03 --- /dev/null +++ b/src/uk/ac/ox/cs/pagoda/Pagoda.java @@ -0,0 +1,164 @@ +package uk.ac.ox.cs.pagoda; + +import org.apache.commons.cli.*; +import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; +import uk.ac.ox.cs.pagoda.util.Properties; +import uk.ac.ox.cs.pagoda.util.Timer; +import uk.ac.ox.cs.pagoda.util.Utility; + +import java.nio.file.Path; + +/** + * The main class + */ +public class Pagoda implements Runnable { + + private static final String OPTION_ONTOLOGY = "o"; + private static final String OPTION_DATA = "d"; + private static final String OPTION_QUERY = "q"; + private static final String OPTION_ANSWER = "a"; + private static final String OPTION_CLASSIFY = "c"; + private static final String OPTION_HERMIT = "f"; + + 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_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()); + + CommandLineParser parser = new DefaultParser(); + try { + 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))); + + pagodaBuilder.build().run(); + } + catch( ParseException exp ) { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp("PAGOdA", options); + Utility.logError("Parsing failed. Reason: " + exp.getMessage()); + System.exit(0); + } + } + + /** + * Do not use it + * */ + private Pagoda() { + properties = new Properties(); + } + + private final Properties properties; + + /** + * Get a builder. + * */ + public static PagodaBuilder builder() { + return new PagodaBuilder(); + } + + @Override + public void run() { + 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; + + try { + Timer t = new Timer(); + 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)); + } finally { + if (pagoda != null) pagoda.dispose(); + } + } + + /** + * Allows to set the parameters before creating a Pagoda instance. + * */ + public static class PagodaBuilder { + + private Pagoda instance; + + private PagodaBuilder() { + instance = new Pagoda(); + } + + public PagodaBuilder ontology(String ontologyPath) { + if(instance == null) return null; + instance.properties.setOntologyPath(ontologyPath); + return this; + } + + public PagodaBuilder ontology(Path ontologyPath) { + return ontology(ontologyPath.toString()); + } + + public PagodaBuilder data(String dataPath) { + if(instance == null) return null; + instance.properties.setDataPath(dataPath); + return this; + } + + public PagodaBuilder data(Path dataPath) { + return data(dataPath.toString()); + } + + public PagodaBuilder query(String queryPath) { + if(instance == null) return null; + instance.properties.setQueryPath(queryPath); + return this; + } + + public PagodaBuilder query(Path queryPath) { + return query(queryPath.toString()); + } + + public PagodaBuilder answer(String answerPath) { + if(instance == null) return null; + instance.properties.setAnswerPath(answerPath); + return this; + } + + public PagodaBuilder answer(Path answerPath) { + return answer(answerPath.toString()); + } + + public PagodaBuilder classify(Boolean toClassify) { + if(instance == null) return null; + instance.properties.setToClassify(toClassify); + return this; + } + + public PagodaBuilder hermit(Boolean callHermit) { + if(instance == null) return null; + instance.properties.setToCallHermiT(callHermit); + return this; + } + + public Pagoda build() { + Pagoda builtInstance = instance; + instance = null; + return builtInstance; + } + + } +} diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java index 97bab50..dfe0c5f 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java @@ -17,6 +17,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.Collection; +// TODO clean APIs public abstract class QueryReasoner { // protected boolean forSemFacet = false; diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java index 0413e65..0c12a27 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java +++ b/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java @@ -22,6 +22,7 @@ public class SkolemTermsManager { private int dependenciesCounter = 0; // replace with hashcode. in case of collision you get only a different upper bound model. + // or, better, use perfect hashing (i.e. devise an ad-hoc hash function without collisions) private Map, Integer> mapDependencyToId = new HashMap<>(); /** diff --git a/src/uk/ac/ox/cs/pagoda/util/Properties.java b/src/uk/ac/ox/cs/pagoda/util/Properties.java index b687b53..9ebebb6 100644 --- a/src/uk/ac/ox/cs/pagoda/util/Properties.java +++ b/src/uk/ac/ox/cs/pagoda/util/Properties.java @@ -30,9 +30,9 @@ public class Properties { public boolean getToCallHermiT() { return toCallHermiT; } public void setToCallHermiT(boolean flag) { toCallHermiT = flag; } - public static boolean ShellModeDefault = false; + public static boolean shellModeDefault = false; - boolean shellMode = ShellModeDefault; + boolean shellMode = shellModeDefault; public boolean getShellMode() { return shellMode; } public void setShellMode(boolean flag) { shellMode = flag; } -- cgit v1.2.3