r46765 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46764‎ | r46765 | r46766 >
Date:16:21, 3 February 2009
Author:daniel
Status:deferred
Tags:
Comment:
multi-store init (finally compiles, phew)
Modified paths:
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/CliApp.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/ConsoleApp.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/query/QueryConsole.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/rdf/ExportRdf.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseConceptStores.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/WikiWordConceptStore.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/WikiWordConceptStoreBase.java (added) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/WikiWordStoreFactory.java (added) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/BuildConceptInfo.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/BuildStatistics.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/BuildThesaurus.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/ExtractProperties.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/ExtractText.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/ImportApp.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/ImportConcepts.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/ImportDump.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/WalkCats.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseConceptStoreBuilders.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/WikiWordConceptStoreBuilder.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/test/java/de/brightbyte/wikiword/builder/ValidateImport.java (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWordBuilder/src/test/java/de/brightbyte/wikiword/builder/ValidateImport.java
@@ -24,7 +24,8 @@
2525 import de.brightbyte.util.StringUtils;
2626 import de.brightbyte.wikiword.CliApp;
2727 import de.brightbyte.wikiword.TweakSet;
28 -import de.brightbyte.wikiword.store.WikiWordStore;
 28+import de.brightbyte.wikiword.model.WikiWordConcept;
 29+import de.brightbyte.wikiword.store.builder.WikiWordConceptStoreBuilder;
2930
3031 public class ValidateImport {
3132
@@ -69,7 +70,7 @@
7071 protected String dbcheck = "--dummy-x"; //FIXME: set to "--dbcheck" to run consistency checks. but thes FAIL SPURIOUSLY! Something is wrong with db state.
7172
7273 protected String[] languages;
73 -
 74+
7475 protected URL getResource(String name) {
7576 if (baseDir!=null) {
7677 File f = new File(baseDir, name);
@@ -138,7 +139,7 @@
139140 out.println(msg);
140141 }
141142
142 - protected boolean launchApp(ImportApp<? extends WikiWordStore> app, ValidationMonitor monitor, String... argv) throws Exception {
 143+ protected boolean launchApp(ImportApp<? extends WikiWordConceptStoreBuilder<? extends WikiWordConcept>> app, ValidationMonitor monitor, String... argv) throws Exception {
143144 echo("");
144145 echo("============================================================");
145146 echo("== TESTING "+app.getClass(), (Object[])argv);
@@ -148,7 +149,8 @@
149150 app.setKeepAlive(true);
150151 app.setAgendaMonitor(monitor);
151152 app.setTweaks(tweaks);
152 - app.setDataSource(dataSource);
 153+ //app.setConceptStoreFactory(conceptStoreFactory);
 154+ //FIXME: somehow tell it what DB to use!
153155 app.setOperation(ImportApp.Operation.FRESH);
154156 app.launch(argv);
155157
@@ -240,7 +242,7 @@
241243
242244 //--------------------
243245 tweaks.setTweak("dbstore.prefix", args.getOption("prefix", "TEST"));
244 -
 246+
245247 File dbf = CliApp.findConfigFile(args, "db");
246248
247249 if (dbf!=null) echo("Using database connection specified in "+dbf);
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/ImportDump.java
@@ -5,11 +5,11 @@
66 import java.net.URL;
77
88 import de.brightbyte.util.PersistenceException;
9 -import de.brightbyte.wikiword.TweakSet;
109 import de.brightbyte.wikiword.analyzer.WikiTextAnalyzer;
11 -import de.brightbyte.wikiword.store.builder.WikiWordStoreBuilder;
 10+import de.brightbyte.wikiword.model.WikiWordConcept;
 11+import de.brightbyte.wikiword.store.builder.WikiWordConceptStoreBuilder;
1212
13 -public abstract class ImportDump<S extends WikiWordStoreBuilder> extends ImportApp<S> {
 13+public abstract class ImportDump<S extends WikiWordConceptStoreBuilder<? extends WikiWordConcept>> extends ImportApp<S> {
1414
1515 public ImportDump(String agendaTask) {
1616 super(agendaTask, false, true);
@@ -62,7 +62,7 @@
6363 */
6464
6565 WikiTextAnalyzer analyzer = WikiTextAnalyzer.getWikiTextAnalyzer(getCorpus(), tweaks);
66 - WikiWordImporter importer = newImporter(analyzer, store, tweaks);
 66+ WikiWordImporter importer = newImporter(analyzer);
6767 importer.setLogOutput(getLogOutput());
6868 importer.configure(args);
6969
@@ -113,7 +113,7 @@
114114 section("-- dbstats --------------------------------------------------");
115115 dumpTableStats();
116116
117 - int w = getNumberOfWarnings(); //XXX: warnings per root-task!
 117+ int w = conceptStore.getNumberOfWarnings(); //XXX: warnings per root-task!
118118 if (w==0) info("no warnings");
119119 else warn("******* NOTE: "+w+" warnings collected! *******");
120120 }
@@ -122,6 +122,6 @@
123123 //noop
124124 }
125125
126 - protected abstract WikiWordImporter newImporter(WikiTextAnalyzer analyzer, S store, TweakSet tweaks) throws PersistenceException;
 126+ protected abstract WikiWordImporter newImporter(WikiTextAnalyzer analyzer) throws PersistenceException;
127127
128128 }
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/BuildThesaurus.java
@@ -1,15 +1,8 @@
22 package de.brightbyte.wikiword.builder;
33
4 -import java.sql.Connection;
5 -import java.sql.SQLException;
64 import java.util.Arrays;
75
8 -import javax.sql.DataSource;
9 -
10 -import de.brightbyte.util.PersistenceException;
116 import de.brightbyte.wikiword.Corpus;
12 -import de.brightbyte.wikiword.schema.GlobalConceptStoreSchema;
13 -import de.brightbyte.wikiword.store.builder.DatabaseGlobalConceptStoreBuilder;
147 import de.brightbyte.wikiword.store.builder.GlobalConceptStoreBuilder;
158
169 /**
@@ -17,7 +10,7 @@
1811 * ImportDump can be invoked as a standalone program, use --help as a
1912 * command line parameter for usage information.
2013 */
21 -public class BuildThesaurus extends ImportApp<GlobalConceptStoreBuilder> {
 14+public class BuildThesaurus extends ImportApp {
2215
2316 private Corpus[] languages;
2417
@@ -35,7 +28,7 @@
3629 args.declare("languages", null, true, String.class, "languages to combine into the thesaurus. If omitted, all available data-sets will be used.");
3730 }
3831
39 - @Override
 32+ /*@Override
4033 protected GlobalConceptStoreBuilder createStore(DataSource db) throws PersistenceException {...
4134 try {
4235 String lang = args.getStringOption("languages", null);
@@ -67,7 +60,7 @@
6861 } catch (SQLException e) {
6962 throw new PersistenceException(e);
7063 }
71 - }
 64+ }*/
7265
7366
7467 @Override
@@ -76,13 +69,13 @@
7770 info("Using languages: "+Arrays.toString(languages));
7871
7972 if (agenda.beginTask("BuildThesaurus.run", "importConcepts")) {
80 - ((GlobalConceptStoreBuilder)this.store).importConcepts();
 73+ ((GlobalConceptStoreBuilder)this.conceptStore).importConcepts();
8174 agenda.endTask("BuildThesaurus.run", "importConcepts");
8275 }
8376
8477 section("-- buildGlobalConcepts --------------------------------------------------");
8578 if (agenda.beginTask("BuildThesaurus.run", "buildGlobalConcepts")) {
86 - ((GlobalConceptStoreBuilder)this.store).buildGlobalConcepts();
 79+ ((GlobalConceptStoreBuilder)this.conceptStore).buildGlobalConcepts();
8780 agenda.endTask("BuildThesaurus.run", "buildGlobalConcepts");
8881 }
8982
@@ -95,7 +88,7 @@
9689 */
9790
9891 section("-- statistics --------------------------------------------------");
99 - this.store.dumpTableStats(getLogOutput());
 92+ dumpTableStats();
10093 }
10194
10295 public static void main(String[] argv) throws Exception {
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/ImportConcepts.java
@@ -1,14 +1,13 @@
22 package de.brightbyte.wikiword.builder;
33
4 -import java.sql.SQLException;
 4+import java.io.IOException;
55
6 -import javax.sql.DataSource;
7 -
86 import de.brightbyte.util.PersistenceException;
9 -import de.brightbyte.wikiword.TweakSet;
107 import de.brightbyte.wikiword.analyzer.WikiTextAnalyzer;
11 -import de.brightbyte.wikiword.store.builder.DatabaseLocalConceptStoreBuilder;
 8+import de.brightbyte.wikiword.store.WikiWordStoreFactory;
129 import de.brightbyte.wikiword.store.builder.LocalConceptStoreBuilder;
 10+import de.brightbyte.wikiword.store.builder.PropertyStoreBuilder;
 11+import de.brightbyte.wikiword.store.builder.TextStoreBuilder;
1312
1413 /**
1514 * This is the primary entry point to the first phase of a WikiWord analysis.
@@ -17,14 +16,28 @@
1817 */
1918 public class ImportConcepts extends ImportDump<LocalConceptStoreBuilder> {
2019
 20+ private PropertyStoreBuilder propertyStore;
 21+ private TextStoreBuilder textStore;
 22+
2123 public ImportConcepts() {
2224 super("ImportDump");
2325 }
2426
2527 @Override
26 - protected ConceptImporter newImporter(WikiTextAnalyzer analyzer, LocalConceptStoreBuilder store, TweakSet tweaks) throws PersistenceException {
27 - return new ConceptImporter(analyzer, store, tweaks);
 28+ protected void createStores(WikiWordStoreFactory<? extends LocalConceptStoreBuilder> factory) throws IOException, PersistenceException {
 29+ super.createStores(factory);
 30+
 31+ textStore = conceptStore.getTextStoreBuilder();
 32+ registerStore(textStore);
 33+
 34+ propertyStore = conceptStore.getPropertyStoreBuilder();
 35+ registerStore(propertyStore);
2836 }
 37+
 38+ @Override
 39+ protected ConceptImporter newImporter(WikiTextAnalyzer analyzer) throws PersistenceException {
 40+ return new ConceptImporter(analyzer, conceptStore, tweaks);
 41+ }
2942
3043 @Override
3144 protected void afterImport() throws PersistenceException {
@@ -32,15 +45,6 @@
3346 }
3447
3548 @Override
36 - protected LocalConceptStoreBuilder createStore(DataSource db) throws PersistenceException {
37 - try {
38 - return new DatabaseLocalConceptStoreBuilder(getCorpus(), db, tweaks);
39 - } catch (SQLException e) {
40 - throw new PersistenceException(e);
41 - }
42 - }
43 -
44 - @Override
4549 protected boolean getDropWarnings() {
4650 return true;
4751 }
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/WalkCats.java
@@ -3,7 +3,7 @@
44 import de.brightbyte.wikiword.store.builder.DatabaseWikiWordConceptStoreBuilder;
55 import de.brightbyte.wikiword.store.builder.WikiWordConceptStoreBuilder;
66
7 -public class WalkCats extends ImportApp<WikiWordConceptStoreBuilder> {
 7+public class WalkCats extends ImportApp {
88
99 public WalkCats() {
1010 super(null, true, true);
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/BuildStatistics.java
@@ -1,8 +1,10 @@
22 package de.brightbyte.wikiword.builder;
33
4 -import javax.sql.DataSource;
 4+import java.io.IOException;
55
66 import de.brightbyte.util.PersistenceException;
 7+import de.brightbyte.wikiword.model.WikiWordConcept;
 8+import de.brightbyte.wikiword.store.WikiWordStoreFactory;
79 import de.brightbyte.wikiword.store.builder.StatisticsStoreBuilder;
810 import de.brightbyte.wikiword.store.builder.WikiWordConceptStoreBuilder;
911
@@ -11,8 +13,10 @@
1214 * ImportDump can be invoked as a standalone program, use --help as a
1315 * command line parameter for usage information.
1416 */
15 -public class BuildStatistics extends ImportApp<StatisticsStoreBuilder> {
 17+public class BuildStatistics extends ImportApp<WikiWordConceptStoreBuilder<? extends WikiWordConcept>> {
1618
 19+ protected StatisticsStoreBuilder statisticsStore;
 20+
1721 public BuildStatistics() {
1822 super("BuildStatistics", true, true);
1923 }
@@ -24,16 +28,19 @@
2529
2630 protected WikiWordConceptStoreBuilder<?> conceptStore;
2731
 32+
2833 @Override
29 - protected StatisticsStoreBuilder createStore(DataSource db) throws PersistenceException {
30 - conceptStore = createConceptStoreBuilder(db);
31 - return conceptStore.getStatisticsStoreBuilder();...
 34+ protected void createStores(WikiWordStoreFactory<? extends WikiWordConceptStoreBuilder<? extends WikiWordConcept>> factory) throws IOException, PersistenceException {
 35+ super.createStores(factory);
 36+
 37+ statisticsStore = conceptStore.getStatisticsStoreBuilder();
 38+ registerStore(statisticsStore);
3239 }
3340
3441 @Override
3542 protected void run() throws Exception {
3643 section("-- buildstats --------------------------------------------------");
37 - this.store.buildStatistics();
 44+ this.statisticsStore.buildStatistics();
3845
3946 section("-- statistics --------------------------------------------------");
4047 conceptStore.getConceptStore().getStatisticsStore().dumpStatistics(getLogOutput());
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/ImportApp.java
@@ -5,14 +5,14 @@
66
77 import java.io.IOException;
88
9 -import javax.sql.DataSource;
10 -
119 import de.brightbyte.application.Agenda;
1210 import de.brightbyte.application.Agenda.Monitor;
1311 import de.brightbyte.io.Prompt;
1412 import de.brightbyte.util.PersistenceException;
1513 import de.brightbyte.wikiword.CliApp;
1614 import de.brightbyte.wikiword.model.WikiWordConcept;
 15+import de.brightbyte.wikiword.store.WikiWordStore;
 16+import de.brightbyte.wikiword.store.WikiWordStoreFactory;
1717 import de.brightbyte.wikiword.store.builder.DatabaseConceptStoreBuilders;
1818 import de.brightbyte.wikiword.store.builder.WikiWordConceptStoreBuilder;
1919 import de.brightbyte.wikiword.store.builder.WikiWordStoreBuilder;
@@ -20,7 +20,7 @@
2121 /**
2222 * This is the base class for entry points to WikiWord.
2323 */
24 -public abstract class ImportApp<S extends WikiWordStoreBuilder> extends CliApp<S> {
 24+public abstract class ImportApp<S extends WikiWordConceptStoreBuilder<? extends WikiWordConcept>> extends CliApp<S> {
2525
2626 protected static enum Operation {
2727 FRESH,
@@ -41,8 +41,10 @@
4242 this.useAgenda = agendaTask != null;
4343 }
4444
45 - protected WikiWordConceptStoreBuilder<? extends WikiWordConcept> createConceptStoreBuilder(DataSource db) throws PersistenceException {
46 - return DatabaseConceptStoreBuilders.createConceptStoreBuilder(db, dataset, tweaks, allowLocalStore, allowGlobalStore);
 45+ @SuppressWarnings("unchecked")
 46+ @Override
 47+ protected WikiWordStoreFactory<S> createConceptStoreFactory() throws IOException, PersistenceException {
 48+ return new DatabaseConceptStoreBuilders.Factory(getConfiguredDataSource(), getConfiguredDataset(), tweaks, true, true);
4749 }
4850
4951 @Override
@@ -67,19 +69,6 @@
6870 }
6971 }
7072
71 - @Override
72 - protected S createStore() throws IOException, PersistenceException {
73 - S store = super.createStore();
74 - store.setLogLevel(logLevel);
75 - return store;
76 - }
77 -
78 - @SuppressWarnings("unchecked")
79 - @Override
80 - protected S createStore(DataSource db) throws PersistenceException {
81 - return (S)createConceptStoreBuilder(db);
82 - }
83 -
8473 public void setAgendaMonitor(Agenda.Monitor monitor) {
8574 this.agendaMonitor = monitor;
8675 }
@@ -240,7 +229,25 @@
241230 }
242231 */
243232 }
 233+
 234+ protected void initializeStores(boolean purge, boolean dropWarnings) throws PersistenceException {
 235+ for (WikiWordStore store: stores) {
 236+ ((WikiWordStoreBuilder)store).initialize(purge, dropWarnings); //XXX: ugly cast!
 237+ }
 238+ }
244239
 240+ protected void optimizeStores() throws PersistenceException {
 241+ for (WikiWordStore store: stores) {
 242+ ((WikiWordStoreBuilder)store).optimize(); //XXX: ugly cast!
 243+ }
 244+ }
 245+
 246+ protected void checkStores() throws PersistenceException {
 247+ for (WikiWordStore store: stores) {
 248+ ((WikiWordStoreBuilder)store).checkConsistency(); //XXX: ugly cast!
 249+ }
 250+ }
 251+
245252 @Override
246253 protected void execute() throws Exception {
247254 boolean noimport = args.isSet("noimport");
@@ -250,17 +257,16 @@
251258
252259 if (!noimport) {
253260 if (useAgenda) {
254 - agenda = store.getAgenda();
 261+ agenda = conceptStore.getAgenda();
255262 initAgenda(agenda);
256263 }
257264
258265 if (operation == Operation.FRESH) {
259266 section("-- purge --------------------------------------------------");
260 - store.initialize(true, getDropWarnings()); //FIXME: don't purge warning always... but when?!
261 - ...all stores...
 267+ initializeStores(true, getDropWarnings()); //FIXME: don't purge warning always... but when?!
262268 }
263269 else {
264 - store.initialize(false, getDropWarnings());
 270+ initializeStores(false, getDropWarnings());
265271 }
266272
267273 if (!useAgenda || agenda.beginTask("ImportApp.launch", agendaTask)) {
@@ -271,26 +277,26 @@
272278
273279 if (dbstats) {
274280 section("-- dbstats --------------------------------------------------");
275 - store.dumpTableStats(out);
 281+ dumpTableStats();
276282
277 - int w = store.getNumberOfWarnings();
 283+ int w = conceptStore.getNumberOfWarnings();
278284 if (w==0) info("no warnings");
279285 else warn("WARNINGS: "+w);
280286 }
281287
282288 if (dbcheck) {
283289 section("-- check --------------------------------------------------");
284 - store.checkConsistency();
 290+ checkStores();
285291 info("OK.");
286292
287 - int w = store.getNumberOfWarnings();
 293+ int w = conceptStore.getNumberOfWarnings();
288294 if (w==0) info("no warnings");
289295 else warn("WARNINGS: "+w);
290296 }
291297
292298 if (optimize) {
293299 section("-- optimize --------------------------------------------------");
294 - store.optimize();
 300+ optimizeStores();
295301 }
296302 }
297303
@@ -298,10 +304,6 @@
299305 return false;
300306 }
301307
302 - public void checkConsistency() throws PersistenceException {
303 - store.checkConsistency();
304 - }
305 -
306308 public int getExitCode() {
307309 return exitCode;
308310 }
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/ExtractText.java
@@ -1,31 +1,34 @@
22 package de.brightbyte.wikiword.builder;
33
4 -import java.io.BufferedOutputStream;
5 -import java.io.File;
6 -import java.io.FileOutputStream;
74 import java.io.IOException;
8 -import java.io.OutputStream;
9 -import java.sql.SQLException;
105
11 -import javax.sql.DataSource;
12 -
136 import de.brightbyte.util.PersistenceException;
14 -import de.brightbyte.wikiword.TweakSet;
157 import de.brightbyte.wikiword.analyzer.WikiTextAnalyzer;
16 -import de.brightbyte.wikiword.store.builder.DatabaseTextStoreBuilder;
17 -import de.brightbyte.wikiword.store.builder.PlainTextOutput;
 8+import de.brightbyte.wikiword.store.WikiWordStoreFactory;
 9+import de.brightbyte.wikiword.store.builder.LocalConceptStoreBuilder;
1810 import de.brightbyte.wikiword.store.builder.TextStoreBuilder;
1911
20 -public class ExtractText extends ImportDump<TextStoreBuilder> {
 12+public class ExtractText extends ImportDump<LocalConceptStoreBuilder> {
2113
 14+ private TextStoreBuilder textStore;
 15+
2216 public ExtractText() {
2317 super("ExtractText");
2418 }
2519
 20+
2621 @Override
27 - protected TextImporter newImporter(WikiTextAnalyzer analyzer, TextStoreBuilder store, TweakSet tweaks) {
28 - return new TextImporter(analyzer, (TextStoreBuilder)store, tweaks);
 22+ protected void createStores(WikiWordStoreFactory<? extends LocalConceptStoreBuilder> factory) throws IOException, PersistenceException {
 23+ super.createStores(factory);
 24+
 25+ textStore = conceptStore.getTextStoreBuilder();
 26+ registerStore(textStore);
2927 }
 28+
 29+ @Override
 30+ protected TextImporter newImporter(WikiTextAnalyzer analyzer) {
 31+ return new TextImporter(analyzer, textStore, tweaks);
 32+ }
3033
3134 @Override
3235 protected void declareOptions() {
@@ -38,7 +41,7 @@
3942 "guessed from, the <wiki-or-dump> parameter)");
4043 }
4144
42 - @Override
 45+ /*@Override
4346 protected TextStoreBuilder createStore() throws IOException, PersistenceException {...
4447 if (args.isSet("stream")) {
4548 String n = args.getOption("stream", null);
@@ -67,7 +70,7 @@
6871 } catch (SQLException e) {
6972 throw new PersistenceException(e);
7073 }
71 - }
 74+ }*/
7275
7376 public static void main(String[] argv) throws Exception {
7477 ExtractText app = new ExtractText();
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/BuildConceptInfo.java
@@ -1,21 +1,33 @@
22 package de.brightbyte.wikiword.builder;
33
4 -import javax.sql.DataSource;
 4+import java.io.IOException;
55
66 import de.brightbyte.util.PersistenceException;
77 import de.brightbyte.wikiword.model.WikiWordConcept;
 8+import de.brightbyte.wikiword.store.WikiWordStoreFactory;
89 import de.brightbyte.wikiword.store.builder.ConceptInfoStoreBuilder;
 10+import de.brightbyte.wikiword.store.builder.WikiWordConceptStoreBuilder;
911
1012 /**
1113 * This is the primary entry point to the first phase of a WikiWord analysis.
1214 * ImportDump can be invoked as a standalone program, use --help as a
1315 * command line parameter for usage information.
1416 */
15 -public class BuildConceptInfo extends ImportApp<ConceptInfoStoreBuilder<? extends WikiWordConcept>> {
 17+public class BuildConceptInfo extends ImportApp<WikiWordConceptStoreBuilder<? extends WikiWordConcept>> {
1618
 19+ protected ConceptInfoStoreBuilder infoStore;
 20+
1721 public BuildConceptInfo() {
1822 super("BuildConceptInfo", true, true);
1923 }
 24+
 25+ @Override
 26+ protected void createStores(WikiWordStoreFactory<? extends WikiWordConceptStoreBuilder<? extends WikiWordConcept>> factory) throws IOException, PersistenceException {
 27+ super.createStores(factory);
 28+
 29+ infoStore = conceptStore.getConceptInfoStoreBuilder();
 30+ registerStore(infoStore);
 31+ }
2032
2133 @Override
2234 protected void declareOptions() {
@@ -27,14 +39,9 @@
2840 }
2941
3042 @Override
31 - protected ConceptInfoStoreBuilder<? extends WikiWordConcept> createStore(DataSource db) throws PersistenceException {
32 - return createConceptStoreBuilder(db).getConceptInfoStoreBuilder(); ...
33 - }
34 -
35 - @Override
3643 protected void run() throws Exception {
3744 section("-- build info --------------------------------------------------");
38 - this.store.buildConceptInfo();
 45+ this.infoStore.buildConceptInfo();
3946 }
4047
4148 public static void main(String[] argv) throws Exception {
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/ExtractProperties.java
@@ -1,27 +1,35 @@
22 package de.brightbyte.wikiword.builder;
33
4 -import java.sql.SQLException;
 4+import java.io.IOException;
55
6 -import javax.sql.DataSource;
7 -
86 import de.brightbyte.util.PersistenceException;
9 -import de.brightbyte.wikiword.TweakSet;
107 import de.brightbyte.wikiword.analyzer.WikiTextAnalyzer;
11 -import de.brightbyte.wikiword.store.builder.DatabaseLocalConceptStoreBuilder;
 8+import de.brightbyte.wikiword.store.WikiWordStoreFactory;
129 import de.brightbyte.wikiword.store.builder.LocalConceptStoreBuilder;
 10+import de.brightbyte.wikiword.store.builder.PropertyStoreBuilder;
1311
1412 public class ExtractProperties extends ImportDump<LocalConceptStoreBuilder> {
1513
 14+ private PropertyStoreBuilder propertyStore;
 15+
1616 public ExtractProperties() {
1717 super("ExtractProperties");
1818 }
1919
2020 @Override
21 - protected PropertyImporter newImporter(WikiTextAnalyzer analyzer, LocalConceptStoreBuilder store, TweakSet tweaks) throws PersistenceException {
22 - return new PropertyImporter(analyzer, store, tweaks);
 21+ protected void createStores(WikiWordStoreFactory<? extends LocalConceptStoreBuilder> factory) throws IOException, PersistenceException {
 22+ super.createStores(factory);
 23+
 24+ propertyStore = conceptStore.getPropertyStoreBuilder();
 25+ registerStore(propertyStore);
2326 }
2427
2528 @Override
 29+ protected PropertyImporter newImporter(WikiTextAnalyzer analyzer) throws PersistenceException {
 30+ return new PropertyImporter(analyzer, conceptStore, tweaks);
 31+ }
 32+
 33+ @Override
2634 protected void declareOptions() {
2735 super.declareOptions();
2836
@@ -57,15 +65,6 @@
5866 }
5967 */
6068
61 - @Override
62 - protected LocalConceptStoreBuilder createStore(DataSource db) throws PersistenceException {
63 - try {
64 - return new DatabaseLocalConceptStoreBuilder(getCorpus(), db, tweaks);
65 - } catch (SQLException e) {
66 - throw new PersistenceException(e);
67 - }
68 - }
69 -
7069 public static void main(String[] argv) throws Exception {
7170 ExtractProperties app = new ExtractProperties();
7271 app.launch(argv);
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseConceptStoreBuilders.java
@@ -11,9 +11,32 @@
1212 import de.brightbyte.wikiword.TweakSet;
1313 import de.brightbyte.wikiword.model.WikiWordConcept;
1414 import de.brightbyte.wikiword.schema.WikiWordStoreSchema;
 15+import de.brightbyte.wikiword.store.WikiWordStoreFactory;
1516
1617 public class DatabaseConceptStoreBuilders {
1718
 19+ public static class Factory<C extends WikiWordConcept> implements WikiWordStoreFactory<DatabaseWikiWordConceptStoreBuilder<C>> {
 20+ private DataSource db;
 21+ private DatasetIdentifier dataset;
 22+ private TweakSet tweaks;
 23+ private boolean allowCorpus;
 24+ private boolean allowThesaurus;
 25+
 26+ public Factory(DataSource db, DatasetIdentifier dataset, TweakSet tweaks, boolean allowCorpus, boolean allowThesaurus) {
 27+ super();
 28+ this.db = db;
 29+ this.dataset = dataset;
 30+ this.tweaks = tweaks;
 31+ this.allowCorpus = allowCorpus;
 32+ this.allowThesaurus = allowThesaurus;
 33+ }
 34+
 35+ @SuppressWarnings("unchecked")
 36+ public DatabaseWikiWordConceptStoreBuilder<C> newStore() throws PersistenceException {
 37+ return (DatabaseWikiWordConceptStoreBuilder<C>)createConceptStoreBuilder(db, dataset, tweaks, allowCorpus, allowThesaurus);
 38+ }
 39+ }
 40+
1841 public static DatabaseWikiWordConceptStoreBuilder<? extends WikiWordConcept> createConceptStoreBuilder(DataSource db, DatasetIdentifier dataset, TweakSet tweaks, boolean allowCorpus, boolean allowThesaurus) throws PersistenceException {
1942 //XXX: UGLY HACK!
2043 try {
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/WikiWordConceptStoreBuilder.java
@@ -4,8 +4,9 @@
55 import de.brightbyte.wikiword.model.WikiWordConcept;
66 import de.brightbyte.wikiword.model.WikiWordConceptReference;
77 import de.brightbyte.wikiword.store.WikiWordConceptStore;
 8+import de.brightbyte.wikiword.store.WikiWordConceptStoreBase;
89
9 -public interface WikiWordConceptStoreBuilder<T extends WikiWordConcept> extends WikiWordStoreBuilder {
 10+public interface WikiWordConceptStoreBuilder<T extends WikiWordConcept> extends WikiWordStoreBuilder, WikiWordConceptStoreBase {
1011
1112 public StatisticsStoreBuilder getStatisticsStoreBuilder() throws PersistenceException;
1213 public ConceptInfoStoreBuilder<T> getConceptInfoStoreBuilder() throws PersistenceException;
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/ConsoleApp.java
@@ -7,11 +7,9 @@
88
99 import de.brightbyte.io.Prompt;
1010 import de.brightbyte.util.PersistenceException;
11 -import de.brightbyte.wikiword.model.WikiWordConcept;
12 -import de.brightbyte.wikiword.model.WikiWordConceptReference;
13 -import de.brightbyte.wikiword.store.WikiWordConceptStore;
 11+import de.brightbyte.wikiword.store.WikiWordConceptStoreBase;
1412
15 -public abstract class ConsoleApp<C extends WikiWordConcept> extends CliApp< WikiWordConceptStore<C, WikiWordConceptReference<C>> > {
 13+public abstract class ConsoleApp<S extends WikiWordConceptStoreBase> extends CliApp<S> {
1614
1715 protected Prompt prompt;
1816
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/CliApp.java
@@ -5,6 +5,8 @@
66 import java.io.File;
77 import java.io.IOException;
88 import java.io.PrintStream;
 9+import java.util.ArrayList;
 10+import java.util.Collection;
911 import java.util.List;
1012 import java.util.Map;
1113
@@ -20,15 +22,16 @@
2123 import de.brightbyte.util.PersistenceException;
2224 import de.brightbyte.util.SystemUtils;
2325 import de.brightbyte.wikiword.rdf.WikiWordIdentifiers;
24 -import de.brightbyte.wikiword.store.DatabaseConceptStores;
2526 import de.brightbyte.wikiword.store.DatabaseWikiWordStore;
26 -import de.brightbyte.wikiword.store.WikiWordConceptStore;
 27+import de.brightbyte.wikiword.store.WikiWordConceptStoreBase;
2728 import de.brightbyte.wikiword.store.WikiWordLocalStore;
 29+import de.brightbyte.wikiword.store.WikiWordStore;
 30+import de.brightbyte.wikiword.store.WikiWordStoreFactory;
2831
2932 /**
3033 * This is the base class for entry points to WikiWord.
3134 */
32 -public abstract class CliApp<S extends WikiWordConceptStore> {
 35+public abstract class CliApp<S extends WikiWordConceptStoreBase> {
3336
3437 public static final String VERSION_INFO = "WikiWord by Daniel Kinzler, brightbyte.de, 2007-2008";
3538 public static final String LICENSE_INFO = "Developed at the University of Leipzig. Free Software, GNU GPL";
@@ -40,6 +43,7 @@
4144 protected int logLevel;
4245 protected int exitCode;
4346
 47+ protected List<WikiWordStore> stores = new ArrayList<WikiWordStore>();
4448 protected S conceptStore;
4549 //protected DatasetIdentifier dataset;
4650 //protected DataSource dataSource;
@@ -50,7 +54,9 @@
5155
5256 protected boolean allowLocalStore;
5357 protected boolean allowGlobalStore;
54 -
 58+
 59+ protected WikiWordStoreFactory<? extends S> conceptStoreFactory;
 60+
5561 public CliApp(boolean allowGlobal, boolean allowLocal) { //TODO: agenda-params?!
5662 args = new Arguments();
5763 out = new LogOutput();
@@ -59,6 +65,14 @@
6066 allowLocalStore = allowLocal;
6167 }
6268
 69+ protected void registerStore(WikiWordStore store) {
 70+ stores.add(store);
 71+ }
 72+
 73+ protected Collection<WikiWordStore> getStores() {
 74+ return stores;
 75+ }
 76+
6377 public boolean isKeepAlive() {
6478 return keepAlive;
6579 }
@@ -279,7 +293,9 @@
280294 DatasetIdentifier dataset = getConfiguredDataset();
281295 section("*** DATASET: "+dataset.getQName()+" ***");
282296
283 - createStores();
 297+ if (conceptStoreFactory==null) conceptStoreFactory= createConceptStoreFactory();
 298+
 299+ createStores(conceptStoreFactory);
284300 if (conceptStore==null) throw new RuntimeException("createStores() failed to initialize conceptStore");
285301
286302 exitCode = 23;
@@ -330,14 +346,26 @@
331347 }
332348 }
333349
 350+ protected abstract WikiWordStoreFactory<S> createConceptStoreFactory() throws IOException, PersistenceException;
 351+
334352 protected void openStores() throws PersistenceException {
335 - conceptStore.open();
 353+ for (WikiWordStore store: stores) {
 354+ store.open();
 355+ }
336356 }
337357
338358 protected void closeStores(boolean flush) throws PersistenceException {
339 - conceptStore.close(flush);
 359+ for (WikiWordStore store: stores) {
 360+ store.close(flush);
 361+ }
340362 }
341 -
 363+
 364+ protected void dumpTableStats() throws PersistenceException {
 365+ for (WikiWordStore store: stores) {
 366+ store.dumpTableStats(getLogOutput());
 367+ }
 368+ }
 369+
342370 protected void prepareApp() throws Exception {
343371 // noop
344372 }
@@ -346,32 +374,16 @@
347375 run();
348376 }
349377
350 - public void setDataSource(DataSource dataSource) {
351 - this.dataSource = dataSource;
 378+ protected DataSource getConfiguredDataSource() throws IOException, PersistenceException {
 379+ File dbf = getDatabaseFile();
 380+ return new DatabaseConnectionInfo(dbf);
352381 }
353382
354 - protected DataSource getDataSource() throws IOException, PersistenceException {
355 -
 383+ protected void createStores(WikiWordStoreFactory<? extends S> factory) throws IOException, PersistenceException {
 384+ conceptStore = factory.newStore();
 385+ registerStore(conceptStore);
356386 }
357 - protected DataSource getDataSource() throws IOException, PersistenceException {
358 - //TODO: make this more abstract. we may not be storing into a DB at all!
359 - if (dataSource==null) {
360 - File dbf = getDatabaseFile();
361 - dataSource = new DatabaseConnectionInfo(dbf);
362 - }
363 - }
364387
365 - protected void createStores() throws IOException, PersistenceException {
366 - conceptStore = createConceptStore();
367 - }
368 -
369 - @SuppressWarnings("unchecked")
370 - protected S createConceptStore(DataSource db) throws PersistenceException {
371 - DatasetIdentifier ds = getDataset();
372 - S store = (S)DatabaseConceptStores.createConceptStore(db, ds, tweaks, allowLocalStore, allowGlobalStore);
373 - return store;
374 - }
375 -
376388 protected File getDatabaseFile() {
377389 File f = findConfigFile(args, "db");
378390
@@ -479,9 +491,12 @@
480492 //noop
481493 }
482494
483 -
484495 public void setTweaks(TweakSet tweaks) {
485496 this.tweaks = tweaks;
486497 }
 498+
 499+ public void setConceptStoreFactory(WikiWordStoreFactory<? extends S> conceptStoreFactory) {
 500+ this.conceptStoreFactory = conceptStoreFactory;
 501+ }
487502
488503 }
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseConceptStores.java
@@ -15,6 +15,28 @@
1616
1717 public class DatabaseConceptStores {
1818
 19+ public static class Factory<S extends DatabaseWikiWordConceptStore<? extends WikiWordConcept, ? extends WikiWordConceptReference<? extends WikiWordConcept>>> implements WikiWordStoreFactory<S> {
 20+ private DataSource db;
 21+ private DatasetIdentifier dataset;
 22+ private TweakSet tweaks;
 23+ private boolean allowCorpus;
 24+ private boolean allowThesaurus;
 25+
 26+ public Factory(DataSource db, DatasetIdentifier dataset, TweakSet tweaks, boolean allowCorpus, boolean allowThesaurus) {
 27+ super();
 28+ this.db = db;
 29+ this.dataset = dataset;
 30+ this.tweaks = tweaks;
 31+ this.allowCorpus = allowCorpus;
 32+ this.allowThesaurus = allowThesaurus;
 33+ }
 34+
 35+ @SuppressWarnings("unchecked")
 36+ public S newStore() throws PersistenceException {
 37+ return (S)createConceptStore(db, dataset, tweaks, allowCorpus, allowThesaurus);
 38+ }
 39+
 40+ }
1941
2042 public static DatabaseWikiWordConceptStore<? extends WikiWordConcept, ? extends WikiWordConceptReference<? extends WikiWordConcept>> createConceptStore(DataSource db, DatasetIdentifier dataset, TweakSet tweaks, boolean allowCorpus, boolean allowThesaurus) throws PersistenceException {
2143 //XXX: UGLY HACK!
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/WikiWordConceptStoreBase.java
@@ -0,0 +1,5 @@
 2+package de.brightbyte.wikiword.store;
 3+
 4+public interface WikiWordConceptStoreBase extends WikiWordStore {
 5+ //marker
 6+}
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/WikiWordConceptStore.java
@@ -7,7 +7,7 @@
88 import de.brightbyte.wikiword.model.WikiWordConceptReference;
99
1010
11 -public interface WikiWordConceptStore<T extends WikiWordConcept, R extends WikiWordConceptReference<T>> extends WikiWordStore {
 11+public interface WikiWordConceptStore<T extends WikiWordConcept, R extends WikiWordConceptReference<T>> extends WikiWordConceptStoreBase {
1212
1313 public DataSet<? extends R> listAllConcepts() throws PersistenceException;
1414
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/WikiWordStoreFactory.java
@@ -0,0 +1,7 @@
 2+package de.brightbyte.wikiword.store;
 3+
 4+import de.brightbyte.util.PersistenceException;
 5+
 6+public interface WikiWordStoreFactory<S extends WikiWordStore> {
 7+ public S newStore() throws PersistenceException;
 8+}
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/query/QueryConsole.java
@@ -11,8 +11,6 @@
1212 import java.util.List;
1313 import java.util.Map;
1414
15 -import javax.sql.DataSource;
16 -
1715 import de.brightbyte.data.cursor.DataSet;
1816 import de.brightbyte.rdf.RdfException;
1917 import de.brightbyte.util.PersistenceException;
@@ -25,12 +23,13 @@
2624 import de.brightbyte.wikiword.model.WikiWordConcept;
2725 import de.brightbyte.wikiword.model.WikiWordConceptReference;
2826 import de.brightbyte.wikiword.rdf.RdfOutput;
 27+import de.brightbyte.wikiword.store.DatabaseConceptStores;
2928 import de.brightbyte.wikiword.store.GlobalConceptStore;
3029 import de.brightbyte.wikiword.store.LocalConceptStore;
3130 import de.brightbyte.wikiword.store.WikiWordConceptStore;
32 -import de.brightbyte.wikiword.store.WikiWordStore;
 31+import de.brightbyte.wikiword.store.WikiWordStoreFactory;
3332
34 -public class QueryConsole extends ConsoleApp<WikiWordConcept> {
 33+public class QueryConsole extends ConsoleApp<WikiWordConceptStore> {
3534
3635 public QueryConsole() {
3736 super(true, true);
@@ -321,11 +320,11 @@
322321 }
323322
324323 protected GlobalConceptStore getGlobalConceptStore() {
325 - return (GlobalConceptStore)conceptStore;
 324+ return (GlobalConceptStore)(Object)conceptStore; //XXX: FUGLY! generic my ass.
326325 }
327326
328327 protected LocalConceptStore getLocalConceptStore() {
329 - return (LocalConceptStore)conceptStore;
 328+ return (LocalConceptStore)(Object)conceptStore; //XXX: FUGLY! generic my ass.
330329 }
331330
332331 public void dumpStats() throws PersistenceException {
@@ -391,4 +390,8 @@
392391 q.launch(argv);
393392 }
394393
 394+ @Override
 395+ protected WikiWordStoreFactory<WikiWordConceptStore> createConceptStoreFactory() throws IOException, PersistenceException {
 396+ return new DatabaseConceptStores.Factory(getConfiguredDataSource(), getConfiguredDataset(), tweaks, true, true);
 397+ }
395398 }
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/rdf/ExportRdf.java
@@ -29,15 +29,19 @@
3030 import de.brightbyte.wikiword.Corpus;
3131 import de.brightbyte.wikiword.DatasetIdentifier;
3232 import de.brightbyte.wikiword.ExtractionRule;
 33+import de.brightbyte.wikiword.model.WikiWordConcept;
 34+import de.brightbyte.wikiword.model.WikiWordConceptReference;
3335 import de.brightbyte.wikiword.schema.GlobalConceptStoreSchema;
3436 import de.brightbyte.wikiword.schema.LocalConceptStoreSchema;
3537 import de.brightbyte.wikiword.schema.StatisticsStoreSchema;
3638 import de.brightbyte.wikiword.schema.WikiWordConceptStoreSchema;
3739 import de.brightbyte.wikiword.schema.WikiWordStoreSchema;
 40+import de.brightbyte.wikiword.store.DatabaseConceptStores;
3841 import de.brightbyte.wikiword.store.DatabaseGlobalConceptStore;
3942 import de.brightbyte.wikiword.store.DatabaseLocalConceptStore;
4043 import de.brightbyte.wikiword.store.DatabaseWikiWordConceptStore;
4144 import de.brightbyte.wikiword.store.WikiWordConceptStore;
 45+import de.brightbyte.wikiword.store.WikiWordStoreFactory;
4246 import de.brightbyte.wikiword.store.DatabaseWikiWordConceptStore.DatabaseStatisticsStore;
4347
4448 public class ExportRdf<V, R extends V, A, W> extends CliApp<WikiWordConceptStore> {
@@ -961,6 +965,12 @@
962966 this.plainSkos = plainSkos;
963967 }
964968
 969+
 970+ @Override
 971+ protected WikiWordStoreFactory<WikiWordConceptStore> createConceptStoreFactory() throws IOException, PersistenceException {
 972+ return new DatabaseConceptStores.Factory(getConfiguredDataSource(), getConfiguredDataset(), tweaks, true, true);
 973+ }
 974+
965975 public static void main(String[] argv) throws Exception {
966976 ExportRdf app = new ExportRdf();
967977 app.launch(argv);

Status & tagging log