diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-05-18 18:27:32 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-05-18 18:27:32 +0100 |
| commit | c7dbc7c61c7094ea4ec49bd630023f23b92fd9d1 (patch) | |
| tree | 45ff5a535e7d519b58d60c0c214a1f9ecc5a35ef /src/uk/ac/ox/cs | |
| parent | 1b6a128137e5d7a6ff75566869232fc054afabef (diff) | |
| download | ACQuA-c7dbc7c61c7094ea4ec49bd630023f23b92fd9d1.tar.gz ACQuA-c7dbc7c61c7094ea4ec49bd630023f23b92fd9d1.zip | |
Configured Maven and improved executable class and tests.
Diffstat (limited to 'src/uk/ac/ox/cs')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/Pagoda.java | 164 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java | 1 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java | 1 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/util/Properties.java | 4 |
4 files changed, 168 insertions, 2 deletions
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 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda; | ||
| 2 | |||
| 3 | import org.apache.commons.cli.*; | ||
| 4 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | ||
| 5 | import uk.ac.ox.cs.pagoda.util.Properties; | ||
| 6 | import uk.ac.ox.cs.pagoda.util.Timer; | ||
| 7 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 8 | |||
| 9 | import java.nio.file.Path; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * The main class | ||
| 13 | */ | ||
| 14 | public class Pagoda implements Runnable { | ||
| 15 | |||
| 16 | private static final String OPTION_ONTOLOGY = "o"; | ||
| 17 | private static final String OPTION_DATA = "d"; | ||
| 18 | private static final String OPTION_QUERY = "q"; | ||
| 19 | private static final String OPTION_ANSWER = "a"; | ||
| 20 | private static final String OPTION_CLASSIFY = "c"; | ||
| 21 | private static final String OPTION_HERMIT = "f"; | ||
| 22 | |||
| 23 | public static void main(String... args) { | ||
| 24 | |||
| 25 | Options options = new Options(); | ||
| 26 | options.addOption(Option.builder(OPTION_ONTOLOGY).argName(OPTION_ONTOLOGY).required().hasArg().desc("The ontology path").build()); | ||
| 27 | options.addOption(Option.builder(OPTION_DATA).argName(OPTION_DATA).hasArg().desc("The data path").build()); | ||
| 28 | options.addOption(Option.builder(OPTION_QUERY).argName(OPTION_QUERY).required().hasArg().desc("The query path").build()); | ||
| 29 | options.addOption(Option.builder(OPTION_ANSWER).argName(OPTION_ANSWER).hasArg().desc("The answer path").build()); | ||
| 30 | options.addOption(Option.builder(OPTION_CLASSIFY).argName(OPTION_CLASSIFY).desc("Tell whether to classify").type(Boolean.class).build()); | ||
| 31 | options.addOption(Option.builder(OPTION_HERMIT).argName(OPTION_HERMIT).desc("Tell whether to call Hermit").type(Boolean.class).build()); | ||
| 32 | |||
| 33 | CommandLineParser parser = new DefaultParser(); | ||
| 34 | try { | ||
| 35 | CommandLine cmd = parser.parse( options, args ); | ||
| 36 | PagodaBuilder pagodaBuilder = Pagoda.builder() | ||
| 37 | .ontology(cmd.getOptionValue(OPTION_ONTOLOGY)) | ||
| 38 | .query(cmd.getOptionValue(OPTION_QUERY)); | ||
| 39 | if(cmd.hasOption(OPTION_DATA)) pagodaBuilder.data(cmd.getOptionValue(OPTION_DATA)); | ||
| 40 | if(cmd.hasOption(OPTION_ANSWER)) pagodaBuilder.answer(cmd.getOptionValue(OPTION_ANSWER)); | ||
| 41 | if(cmd.hasOption(OPTION_CLASSIFY)) pagodaBuilder.classify(Boolean.parseBoolean(cmd.getOptionValue(OPTION_CLASSIFY))); | ||
| 42 | if(cmd.hasOption(OPTION_HERMIT)) pagodaBuilder.hermit(Boolean.parseBoolean(cmd.getOptionValue(OPTION_HERMIT))); | ||
| 43 | |||
| 44 | pagodaBuilder.build().run(); | ||
| 45 | } | ||
| 46 | catch( ParseException exp ) { | ||
| 47 | HelpFormatter formatter = new HelpFormatter(); | ||
| 48 | formatter.printHelp("PAGOdA", options); | ||
| 49 | Utility.logError("Parsing failed. Reason: " + exp.getMessage()); | ||
| 50 | System.exit(0); | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | /** | ||
| 55 | * Do not use it | ||
| 56 | * */ | ||
| 57 | private Pagoda() { | ||
| 58 | properties = new Properties(); | ||
| 59 | } | ||
| 60 | |||
| 61 | private final Properties properties; | ||
| 62 | |||
| 63 | /** | ||
| 64 | * Get a builder. | ||
| 65 | * */ | ||
| 66 | public static PagodaBuilder builder() { | ||
| 67 | return new PagodaBuilder(); | ||
| 68 | } | ||
| 69 | |||
| 70 | @Override | ||
| 71 | public void run() { | ||
| 72 | Utility.logInfo("Ontology file: " + properties.getOntologyPath()); | ||
| 73 | Utility.logInfo("Data files: " + properties.getDataPath()); | ||
| 74 | Utility.logInfo("Query files: " + properties.getQueryPath()); | ||
| 75 | Utility.logInfo("Answer file: " + properties.getAnswerPath()); | ||
| 76 | |||
| 77 | QueryReasoner pagoda = null; | ||
| 78 | |||
| 79 | try { | ||
| 80 | Timer t = new Timer(); | ||
| 81 | pagoda = QueryReasoner.getInstance(properties); | ||
| 82 | if (pagoda == null) return; | ||
| 83 | |||
| 84 | Utility.logInfo("Preprocessing Done in " + t.duration() + " seconds."); | ||
| 85 | |||
| 86 | if (properties.getQueryPath() != null) | ||
| 87 | for (String queryFile: properties.getQueryPath().split(";")) | ||
| 88 | pagoda.evaluate(pagoda.getQueryManager().collectQueryRecords(queryFile)); | ||
| 89 | } finally { | ||
| 90 | if (pagoda != null) pagoda.dispose(); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | /** | ||
| 95 | * Allows to set the parameters before creating a Pagoda instance. | ||
| 96 | * */ | ||
| 97 | public static class PagodaBuilder { | ||
| 98 | |||
| 99 | private Pagoda instance; | ||
| 100 | |||
| 101 | private PagodaBuilder() { | ||
| 102 | instance = new Pagoda(); | ||
| 103 | } | ||
| 104 | |||
| 105 | public PagodaBuilder ontology(String ontologyPath) { | ||
| 106 | if(instance == null) return null; | ||
| 107 | instance.properties.setOntologyPath(ontologyPath); | ||
| 108 | return this; | ||
| 109 | } | ||
| 110 | |||
| 111 | public PagodaBuilder ontology(Path ontologyPath) { | ||
| 112 | return ontology(ontologyPath.toString()); | ||
| 113 | } | ||
| 114 | |||
| 115 | public PagodaBuilder data(String dataPath) { | ||
| 116 | if(instance == null) return null; | ||
| 117 | instance.properties.setDataPath(dataPath); | ||
| 118 | return this; | ||
| 119 | } | ||
| 120 | |||
| 121 | public PagodaBuilder data(Path dataPath) { | ||
| 122 | return data(dataPath.toString()); | ||
| 123 | } | ||
| 124 | |||
| 125 | public PagodaBuilder query(String queryPath) { | ||
| 126 | if(instance == null) return null; | ||
| 127 | instance.properties.setQueryPath(queryPath); | ||
| 128 | return this; | ||
| 129 | } | ||
| 130 | |||
| 131 | public PagodaBuilder query(Path queryPath) { | ||
| 132 | return query(queryPath.toString()); | ||
| 133 | } | ||
| 134 | |||
| 135 | public PagodaBuilder answer(String answerPath) { | ||
| 136 | if(instance == null) return null; | ||
| 137 | instance.properties.setAnswerPath(answerPath); | ||
| 138 | return this; | ||
| 139 | } | ||
| 140 | |||
| 141 | public PagodaBuilder answer(Path answerPath) { | ||
| 142 | return answer(answerPath.toString()); | ||
| 143 | } | ||
| 144 | |||
| 145 | public PagodaBuilder classify(Boolean toClassify) { | ||
| 146 | if(instance == null) return null; | ||
| 147 | instance.properties.setToClassify(toClassify); | ||
| 148 | return this; | ||
| 149 | } | ||
| 150 | |||
| 151 | public PagodaBuilder hermit(Boolean callHermit) { | ||
| 152 | if(instance == null) return null; | ||
| 153 | instance.properties.setToCallHermiT(callHermit); | ||
| 154 | return this; | ||
| 155 | } | ||
| 156 | |||
| 157 | public Pagoda build() { | ||
| 158 | Pagoda builtInstance = instance; | ||
| 159 | instance = null; | ||
| 160 | return builtInstance; | ||
| 161 | } | ||
| 162 | |||
| 163 | } | ||
| 164 | } | ||
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; | |||
| 17 | import java.nio.file.Paths; | 17 | import java.nio.file.Paths; |
| 18 | import java.util.Collection; | 18 | import java.util.Collection; |
| 19 | 19 | ||
| 20 | // TODO clean APIs | ||
| 20 | public abstract class QueryReasoner { | 21 | public abstract class QueryReasoner { |
| 21 | 22 | ||
| 22 | // protected boolean forSemFacet = false; | 23 | // 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 { | |||
| 22 | private int dependenciesCounter = 0; | 22 | private int dependenciesCounter = 0; |
| 23 | 23 | ||
| 24 | // replace with hashcode. in case of collision you get only a different upper bound model. | 24 | // replace with hashcode. in case of collision you get only a different upper bound model. |
| 25 | // or, better, use perfect hashing (i.e. devise an ad-hoc hash function without collisions) | ||
| 25 | private Map<Tuple<Individual>, Integer> mapDependencyToId = new HashMap<>(); | 26 | private Map<Tuple<Individual>, Integer> mapDependencyToId = new HashMap<>(); |
| 26 | 27 | ||
| 27 | /** | 28 | /** |
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 { | |||
| 30 | public boolean getToCallHermiT() { return toCallHermiT; } | 30 | public boolean getToCallHermiT() { return toCallHermiT; } |
| 31 | public void setToCallHermiT(boolean flag) { toCallHermiT = flag; } | 31 | public void setToCallHermiT(boolean flag) { toCallHermiT = flag; } |
| 32 | 32 | ||
| 33 | public static boolean ShellModeDefault = false; | 33 | public static boolean shellModeDefault = false; |
| 34 | 34 | ||
| 35 | boolean shellMode = ShellModeDefault; | 35 | boolean shellMode = shellModeDefault; |
| 36 | public boolean getShellMode() { return shellMode; } | 36 | public boolean getShellMode() { return shellMode; } |
| 37 | public void setShellMode(boolean flag) { shellMode = flag; } | 37 | public void setShellMode(boolean flag) { shellMode = flag; } |
| 38 | 38 | ||
