diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-07-03 19:09:31 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-07-03 19:09:31 +0100 |
| commit | 39b60d4225f5efa4e0287a2c6ce69d90391c69db (patch) | |
| tree | 18c5b05726f39baa4d3ca8b228e24ad1f0182f2a /src/uk/ac/ox/cs/pagoda/Pagoda.java | |
| parent | 133dab6e21f263df2baca913d3d0b7a4fd152d08 (diff) | |
| download | ACQuA-39b60d4225f5efa4e0287a2c6ce69d90391c69db.tar.gz ACQuA-39b60d4225f5efa4e0287a2c6ce69d90391c69db.zip | |
Many little changes.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/Pagoda.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/Pagoda.java | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/Pagoda.java b/src/uk/ac/ox/cs/pagoda/Pagoda.java index f5dce15..7d2317d 100644 --- a/src/uk/ac/ox/cs/pagoda/Pagoda.java +++ b/src/uk/ac/ox/cs/pagoda/Pagoda.java | |||
| @@ -1,12 +1,21 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda; | 1 | package uk.ac.ox.cs.pagoda; |
| 2 | 2 | ||
| 3 | import org.apache.commons.cli.*; | 3 | import org.apache.commons.cli.*; |
| 4 | import org.apache.commons.io.FilenameUtils; | ||
| 5 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 4 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | 6 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; |
| 5 | import uk.ac.ox.cs.pagoda.util.PagodaProperties; | 7 | import uk.ac.ox.cs.pagoda.util.PagodaProperties; |
| 6 | import uk.ac.ox.cs.pagoda.util.Timer; | 8 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 7 | import uk.ac.ox.cs.pagoda.util.Utility; | 9 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 8 | 10 | ||
| 11 | import java.io.BufferedWriter; | ||
| 12 | import java.io.IOException; | ||
| 13 | import java.nio.file.Files; | ||
| 9 | import java.nio.file.Path; | 14 | import java.nio.file.Path; |
| 15 | import java.nio.file.Paths; | ||
| 16 | import java.util.Collection; | ||
| 17 | import java.util.HashMap; | ||
| 18 | import java.util.Map; | ||
| 10 | 19 | ||
| 11 | /** | 20 | /** |
| 12 | * Executable command line user interface. | 21 | * Executable command line user interface. |
| @@ -23,7 +32,7 @@ public class Pagoda implements Runnable { | |||
| 23 | 32 | ||
| 24 | /** | 33 | /** |
| 25 | * Do not use it | 34 | * Do not use it |
| 26 | * */ | 35 | */ |
| 27 | private Pagoda() { | 36 | private Pagoda() { |
| 28 | properties = new PagodaProperties(); | 37 | properties = new PagodaProperties(); |
| 29 | } | 38 | } |
| @@ -85,7 +94,7 @@ public class Pagoda implements Runnable { | |||
| 85 | 94 | ||
| 86 | /** | 95 | /** |
| 87 | * Get a builder. | 96 | * Get a builder. |
| 88 | * */ | 97 | */ |
| 89 | public static PagodaBuilder builder() { | 98 | public static PagodaBuilder builder() { |
| 90 | return new PagodaBuilder(); | 99 | return new PagodaBuilder(); |
| 91 | } | 100 | } |
| @@ -102,21 +111,48 @@ public class Pagoda implements Runnable { | |||
| 102 | try { | 111 | try { |
| 103 | Timer t = new Timer(); | 112 | Timer t = new Timer(); |
| 104 | pagoda = QueryReasoner.getInstance(properties); | 113 | pagoda = QueryReasoner.getInstance(properties); |
| 105 | if (pagoda == null) return; | 114 | if(pagoda == null) return; |
| 106 | 115 | ||
| 107 | Utility.logInfo("Preprocessing Done in " + t.duration() + " seconds."); | 116 | Utility.logInfo("Preprocessing Done in " + t.duration() + " seconds."); |
| 108 | 117 | ||
| 109 | if (properties.getQueryPath() != null) | 118 | if(properties.getQueryPath() != null) { |
| 110 | for (String queryFile: properties.getQueryPath().split(";")) | 119 | for(String queryFile : properties.getQueryPath().split(";")) { |
| 111 | pagoda.evaluate(pagoda.getQueryManager().collectQueryRecords(queryFile)); | 120 | Collection<QueryRecord> queryRecords = pagoda.getQueryManager().collectQueryRecords(queryFile); |
| 121 | pagoda.evaluate(queryRecords); | ||
| 122 | |||
| 123 | if(PagodaProperties.isDebuggingMode()) { | ||
| 124 | HashMap<String, Map<String, String>> statistics = new HashMap<>(); | ||
| 125 | for(QueryRecord queryRecord : queryRecords) { | ||
| 126 | statistics.put(queryRecord.getQueryID(), queryRecord.getStatistics()); | ||
| 127 | } | ||
| 128 | String statisticsFilename = getStatisticsFilename(properties, queryFile); | ||
| 129 | try(BufferedWriter writer = Files.newBufferedWriter(Paths.get(statisticsFilename))) { | ||
| 130 | QueryRecord.GsonCreator.getInstance().toJson(statistics, writer); | ||
| 131 | } catch(IOException e) { | ||
| 132 | Utility.logError("Unable to save statistics"); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | } | ||
| 136 | } | ||
| 112 | } finally { | 137 | } finally { |
| 113 | if (pagoda != null) pagoda.dispose(); | 138 | if(pagoda != null) pagoda.dispose(); |
| 114 | } | 139 | } |
| 115 | } | 140 | } |
| 116 | 141 | ||
| 142 | private String getStatisticsFilename(PagodaProperties properties, String queryFile) { | ||
| 143 | String statisticsFilename = "statistics_" + | ||
| 144 | FilenameUtils.removeExtension(FilenameUtils.getName(properties.getOntologyPath().replaceAll("_", "-"))); | ||
| 145 | statisticsFilename += "_" + FilenameUtils.removeExtension(FilenameUtils.getName(queryFile).replaceAll("_", "-")); | ||
| 146 | statisticsFilename += "_" + ((properties.getUseSkolemUpperBound()) ? "skolem" : ""); | ||
| 147 | statisticsFilename += ".json"; | ||
| 148 | statisticsFilename = FilenameUtils.concat(properties.getStatisticsDir().toString(), | ||
| 149 | statisticsFilename); | ||
| 150 | return statisticsFilename; | ||
| 151 | } | ||
| 152 | |||
| 117 | /** | 153 | /** |
| 118 | * Allows to set the parameters before creating a Pagoda instance. | 154 | * Allows to set the parameters before creating a Pagoda instance. |
| 119 | * */ | 155 | */ |
| 120 | public static class PagodaBuilder { | 156 | public static class PagodaBuilder { |
| 121 | 157 | ||
| 122 | private Pagoda instance; | 158 | private Pagoda instance; |
