r46640 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46639‎ | r46640 | r46641 >
Date:12:40, 31 January 2009
Author:daniel
Status:deferred
Tags:
Comment:
handle resource <-> concept link as n:m relation
Modified paths:
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/schema/LocalConceptStoreSchema.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/schema/WikiWordConceptStoreSchema.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/AbstractImporter.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseGlobalConceptStoreBuilder.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseLocalConceptStoreBuilder.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseLocalStoreBuilder.java (added) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabasePropertyStoreBuilder.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseTextStoreBuilder.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseWikiWordConceptStoreBuilder.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseWikiWordStoreBuilder.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DebugLocalConceptStoreBuilder.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/IncrementalStoreBuilder.java (added) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/LocalConceptStoreBuilder.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/PropertyStoreBuilder.java (modified) (history)
  • /trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/WikiWordStoreBuilder.java (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/schema/LocalConceptStoreSchema.java
@@ -23,6 +23,7 @@
2424
2525 protected RelationTable meaningTable;
2626 protected RelationTable aliasTable;
 27+ protected RelationTable aboutTable;
2728
2829 //protected EntityTable conceptDescriptionTable;
2930
@@ -41,8 +42,6 @@
4243 private void init(Corpus corpus, TweakSet tweaks) {
4344 this.corpus = corpus;
4445
45 - conceptTable.addField( new ReferenceField(this, "resource", "INT", null, false, KeyType.INDEX, "resource", "id", null ) );
46 -
4746 broaderTable.addField( new ReferenceField(this, "resource", "INT", null, false, KeyType.INDEX, "resource", "id", null ) ); //NOTE: not required. see buildSectionBroader.
4847 broaderTable.addField( new DatabaseField(this, "rule", "INT", null, true, KeyType.INDEX) );
4948 broaderTable.addField( new ReferenceField(this, "narrow_name", getTextType(255), null, true, KeyType.INDEX, "concept", "name", null ) );
@@ -69,6 +68,7 @@
7069 resourceTable.addField( new DatabaseField(this, "name", getTextType(255), null, true, KeyType.UNIQUE ) );
7170 resourceTable.addField( new DatabaseField(this, "type", "INT", null, true, KeyType.INDEX ) ); //TODO: enum
7271 resourceTable.addField( new DatabaseField(this, "timestamp", "CHAR(14)", null, true, null ) ); //TODO: which type in which db?
 72+
7373 resourceTable.setAutomaticField("id");
7474 addTable(resourceTable);
7575
@@ -100,6 +100,14 @@
101101 //aliasTable.addKey( new DatabaseKey(this, KeyType.UNIQUE, "ident", new String[] {"resource", "concept_name", "term_text"}) );
102102 addTable(aliasTable);
103103
 104+ aboutTable = new RelationTable(this, "about", defaultTableAttributes);
 105+ //aliasTable.addField( new DatabaseField(this, "id", "INT", "AUTO_INCREMENT", false, KeyType.PRIMARY) );
 106+ aboutTable.addField( new ReferenceField(this, "resource", "INT", null, true, null, "resource", "id", null ) );
 107+ aboutTable.addField( new ReferenceField(this, "concept", "INT", null, false, KeyType.INDEX, "concept", "id", null ) );
 108+ aboutTable.addField( new ReferenceField(this, "concept_name", getTextType(255), null, true, KeyType.INDEX, "concept", "name", null ) );
 109+ aboutTable.addKey( new DatabaseKey(this, KeyType.PRIMARY, "about", new String[] {"resource", "concept"}) );
 110+ addTable(aliasTable);
 111+
104112 meaningTable = new RelationTable(this, "meaning", defaultTableAttributes);
105113 //meaningTable.addField( new DatabaseField(this, "id", "INT", "AUTO_INCREMENT", false, KeyType.PRIMARY) );
106114 meaningTable.addField( new ReferenceField(this, "concept", "INT", null, true, KeyType.INDEX, "concept", "id", null ) );
@@ -133,6 +141,8 @@
134142 public void checkConsistency() throws SQLException {
135143 super.checkConsistency();
136144
 145+ checkReferentialIntegrity(conceptTable, "resource", true); //NOTE: red links generate concepts with no resource assigned
 146+
137147 checkReferentialIntegrity(meaningTable, "concept", false);
138148
139149 checkIdSanity(resourceTable, "id");
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/schema/WikiWordConceptStoreSchema.java
@@ -82,8 +82,6 @@
8383 public void checkConsistency() throws SQLException {
8484 checkIdSanity(conceptTable, "id"); //FIXME: this barfs spuriously. something insconsistent about th db state?!
8585
86 - checkReferentialIntegrity(conceptTable, "resource", true); //NOTE: red links generate concepts with no resource assigned
87 -
8886 checkReferentialIntegrity(broaderTable, "narrow", false);
8987 checkReferentialIntegrity(broaderTable, "broad", false);
9088
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/builder/AbstractImporter.java
@@ -19,6 +19,7 @@
2020 import de.brightbyte.wikiword.TweakSet;
2121 import de.brightbyte.wikiword.analyzer.WikiTextAnalyzer;
2222 import de.brightbyte.wikiword.analyzer.WikiTextSniffer;
 23+import de.brightbyte.wikiword.store.builder.IncrementalStoreBuilder;
2324 import de.brightbyte.wikiword.store.builder.WikiWordStoreBuilder;
2425
2526 public abstract class AbstractImporter implements WikiWordImporter {
@@ -168,12 +169,12 @@
169170 doit = false;
170171 }
171172 else {
172 - if (getAgenda().isTaskDirty()) {
 173+ if (getAgenda().isTaskDirty() && store instanceof IncrementalStoreBuilder) {
173174 Agenda.Record rec = getAgenda().getCurrentRecord();
174175
175176 int delAfter = (Integer)rec.parameters.get("lastRcId_");
176177 out.info("=== DIRTY BLOCK FOR SAFEPOINT#"+safepointNumber+", Deleting entries starting after id: #"+delAfter+" ===");
177 - store.deleteDataAfter(delAfter, false); //FIXME: make sure we are not off by one!
 178+ ((IncrementalStoreBuilder)store).deleteDataAfter(delAfter, false); //FIXME: make sure we are not off by one!
178179 }
179180
180181 out.info("=== BEGINNING BLOCK FOR SAFEPOINT#"+safepointNumber+": "+getAgenda().getCurrentRecord().parameters+" ===");
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DebugLocalConceptStoreBuilder.java
@@ -108,103 +108,71 @@
109109 log("* finishAliases *");
110110 }
111111
112 - public int storeConcept(int rcId, String name, ConceptType ctype) throws PersistenceException {
113 - // TODO Auto-generated method stub
114 - return 0;
115 - }
116 -
117 - public void storeConceptAlias(int rcId, int source, String sourceName, int target, String targetName, AliasScope scope) throws PersistenceException {
118 - // TODO Auto-generated method stub
119 -
120 - }
121 -
122112 public void storeProperty(int resourceId, int conceptId, String concept, String property, String value) throws PersistenceException {
123 - // TODO Auto-generated method stub
124 -
 113+ log("* storeProperty("+resourceId+", "+conceptId+", "+concept+", "+property+", "+value+") *");
125114 }
126115
127 - public int storeResource(String name, ResourceType ptype, Date time) throws PersistenceException {
128 - // TODO Auto-generated method stub
129 - return 0;
130 - }
131 -
132116 public void checkConsistency() throws PersistenceException {
133 - // TODO Auto-generated method stub
134 -
 117+ log("* checkConsistency *");
135118 }
136119
137120 public void close(boolean flush) throws PersistenceException {
138 - // TODO Auto-generated method stub
139 -
 121+ log("* close *");
140122 }
141123
142124 public void deleteDataAfter(int lastId, boolean inclusive) throws PersistenceException {
143 - // TODO Auto-generated method stub
144 -
 125+ log("* deleteDataAfter("+lastId+", "+inclusive+") *");
145126 }
146127
147128 public void deleteDataFrom(int lastId) throws PersistenceException {
148 - // TODO Auto-generated method stub
149 -
 129+ log("* deleteDataFrom("+lastId+") *");
150130 }
151131
152132 public void dumpTableStats(Output out) throws PersistenceException {
153 - // TODO Auto-generated method stub
154 -
 133+ log("* dumpTableStats *");
155134 }
156135
157136 public void flush() throws PersistenceException {
158 - // TODO Auto-generated method stub
159 -
 137+ log("* flush *");
160138 }
161139
162140 public Agenda getAgenda() throws PersistenceException {
163 - // TODO Auto-generated method stub
164141 return null;
165142 }
166143
167144 public int getNumberOfWarnings() throws PersistenceException {
168 - // TODO Auto-generated method stub
169145 return 0;
170146 }
171147
172148 public void open() throws PersistenceException {
173 - // TODO Auto-generated method stub
174 -
 149+ log("* open *");
175150 }
176151
177152 public void optimize() throws PersistenceException {
178 - // TODO Auto-generated method stub
179 -
 153+ log("* optimize *");
180154 }
181155
182156 public void prepare(boolean purge, boolean dropAll) throws PersistenceException {
183 - // TODO Auto-generated method stub
184 -
 157+ log("* prepare *");
185158 }
186159
187160 public void setLogLevel(int loglevel) {
188 - // TODO Auto-generated method stub
189 -
 161+ // noop
190162 }
191163
192164 public void storeWarning(int rcId, String problem, String details) throws PersistenceException {
193 - // TODO Auto-generated method stub
194 -
 165+ log("+ warning: rcId = "+rcId+", problem = "+problem+", details = "+details);
195166 }
196167
197168 public Map<String, ? extends Number> getTableStats() throws PersistenceException {
198 - // TODO Auto-generated method stub
199169 return null;
200170 }
201171
202172 public boolean isComplete() throws PersistenceException {
203 - // TODO Auto-generated method stub
204173 return false;
205174 }
206175
207176 public Corpus getCorpus() {
208 - // TODO Auto-generated method stub
209177 return null;
210178 }
211179
@@ -459,7 +427,13 @@
460428 return resourceCounter;
461429 }
462430
 431+ public int storeResourceAbout(String name, ResourceType ptype, Date time, int conceptId, String conceptName) {
 432+ int resourceId = storeResource(name, ptype, time);
 433+ storeAbout(resourceId, conceptId, conceptName);
 434+ return resourceId;
 435+ }
463436
 437+
464438 public void storeDefinition(int rcId, int conceptId, String definition) {
465439 definitionCounter++;
466440 trace("+ storeDefinition: conceptId = "+conceptId+": "+definition);
@@ -653,5 +627,13 @@
654628 //noop
655629 return 0;
656630 }
 631+
 632+ public void storeAbout(int resource, String conceptName) {
 633+ trace("+ storeAbout: resource = "+resource+", conceptName = "+conceptName);
 634+ }
 635+
 636+ public void storeAbout(int resource, int concept, String conceptName) {
 637+ trace("+ storeAbout: resource = "+resource+", concept = "+concept+", conceptName = "+conceptName);
 638+ }
657639
658640 }
\ No newline at end of file
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseLocalStoreBuilder.java
@@ -0,0 +1,29 @@
 2+package de.brightbyte.wikiword.store.builder;
 3+
 4+import java.sql.SQLException;
 5+
 6+import de.brightbyte.util.PersistenceException;
 7+import de.brightbyte.wikiword.TweakSet;
 8+import de.brightbyte.wikiword.schema.WikiWordStoreSchema;
 9+
 10+public abstract class DatabaseLocalStoreBuilder extends DatabaseWikiWordStoreBuilder implements IncrementalStoreBuilder {
 11+
 12+ public DatabaseLocalStoreBuilder(WikiWordStoreSchema database, TweakSet tweaks) throws SQLException {
 13+ super(database, tweaks);
 14+ }
 15+
 16+ protected abstract void deleteDataFrom(int rcId, String op) throws PersistenceException;
 17+
 18+
 19+ public void deleteDataFrom(int rcId) throws PersistenceException {
 20+ log("deleting data from "+rcId);
 21+ deleteDataFrom(rcId, "=");
 22+ }
 23+
 24+ public void deleteDataAfter(int rcId, boolean inclusive) throws PersistenceException {
 25+ String op = inclusive ? ">=" : ">";
 26+ log("deleting data from with id "+op+" "+rcId);
 27+ deleteDataFrom(rcId, op);
 28+ }
 29+
 30+}
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/PropertyStoreBuilder.java
@@ -1,11 +1,6 @@
22 package de.brightbyte.wikiword.store.builder;
33
4 -import java.util.Date;
5 -
64 import de.brightbyte.util.PersistenceException;
7 -import de.brightbyte.wikiword.ConceptType;
8 -import de.brightbyte.wikiword.ResourceType;
9 -import de.brightbyte.wikiword.schema.AliasScope;
105 import de.brightbyte.wikiword.store.WikiWordLocalStore;
116
127 public interface PropertyStoreBuilder extends WikiWordStoreBuilder, WikiWordLocalStore {
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseWikiWordStoreBuilder.java
@@ -10,9 +10,11 @@
1111 import de.brightbyte.db.BufferBasedInserter;
1212 import de.brightbyte.db.DatabaseAccess;
1313 import de.brightbyte.db.DatabaseAgendaPersistor;
 14+import de.brightbyte.db.DatabaseField;
1415 import de.brightbyte.db.DatabaseTable;
1516 import de.brightbyte.db.Inserter;
1617 import de.brightbyte.db.InserterFactory;
 18+import de.brightbyte.db.ReferenceField;
1719 import de.brightbyte.db.RelationTable;
1820 import de.brightbyte.db.StatementBasedInserter;
1921 import de.brightbyte.util.PersistenceException;
@@ -260,6 +262,23 @@
261263 trace("deleted "+c+" rows from "+rel.getName()+" where "+field+" "+op+" "+rcId+(via!=null?" via "+via.getName():"")+", took "+(System.currentTimeMillis()-t)/1000+" sec");
262264 }
263265
 266+ protected void deleteOrphansFrom(int rcId, String op, DatabaseTable table, RelationTable ref, String refField) throws PersistenceException {
 267+ String sql;
 268+
 269+ ReferenceField f = (ReferenceField)ref.getField(refField);
 270+ String field = f.getTargetField();
 271+
 272+ sql = "DELETE FROM " + table.getSQLName() + " AS T ";
 273+ sql += " WHERE NOT EXISTS ( ";
 274+ sql += " SELECT * FROM " + ref.getSQLName() + " AS R ";
 275+ sql += " WHERE R." + refField + " = T." + field;
 276+ sql += " )";
 277+
 278+ long t = System.currentTimeMillis();
 279+ int c = executeUpdate("deleteDataFrom", sql);
 280+ trace("deleted "+c+" orphan rows from "+table.getName()+" where no reference exists from "+ref.getSQLName()+"."+refField+", took "+(System.currentTimeMillis()-t)/1000+" sec");
 281+ }
 282+
264283 protected int executeUpdate(String name, String sql) throws PersistenceException {
265284 try {
266285 return database.executeUpdate(name, sql);
@@ -311,28 +330,12 @@
312331 }
313332 }
314333
315 - protected void deleteDataFrom(int rcId, String op) throws PersistenceException {
316 - throw new UnsupportedOperationException();
317 - }
318 -
319 -
320334 protected int deleteLoops(DatabaseTable t, String id1, String id2) throws SQLException {
321335 String sql = "DELETE FROM "+t.getSQLName()+" WHERE "+id1+" = "+id2;
322336
323337 return database.executeUpdate("deleteLoops", sql);
324338 }
325 -
326 - public void deleteDataFrom(int rcId) throws PersistenceException {
327 - log("deleting data from "+rcId);
328 - deleteDataFrom(rcId, "=");
329 - }
330339
331 - public void deleteDataAfter(int rcId, boolean inclusive) throws PersistenceException {
332 - String op = inclusive ? ">=" : ">";
333 - log("deleting data from with id "+op+" "+rcId);
334 - deleteDataFrom(rcId, op);
335 - }
336 -
337340 /*
338341 public void purge() throws PersistenceException {
339342 dropTables(true);
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseLocalConceptStoreBuilder.java
@@ -70,6 +70,9 @@
7171 protected Inserter aliasInserter;
7272 protected Inserter meaningInserter;
7373
 74+ protected Inserter aboutInserter;
 75+ protected RelationTable aboutTable;
 76+
7477 protected Random random;
7578
7679 protected TweakSet tweaks;
@@ -133,6 +136,9 @@
134137 aliasTable = (RelationTable)aliasInserter.getTable();
135138 meaningTable = (RelationTable)meaningInserter.getTable();
136139
 140+ aboutInserter = configureTable("about", 1024, 64);
 141+ aboutTable = (RelationTable)aboutInserter.getTable();
 142+
137143 long seed = tweaks.getTweak("dbstore.randomSeed", -1); //TODO: doc
138144 if (seed>0) random = new Random(seed);
139145 else random = new Random();
@@ -187,13 +193,17 @@
188194 }
189195
190196
191 - @Override
192197 protected void deleteDataFrom(int rcId, String op) throws PersistenceException {
193198 deleteDataFrom(rcId, op, definitionTable, "concept", conceptTable, "resource");
194199 //deleteDataFrom(rcId, op, conceptDescriptionTable, "concept", conceptTable, "resource");
195200
196 - super.deleteDataFrom(rcId, op);
 201+ deleteDataFrom(rcId, op, linkTable, "resource");
 202+ deleteDataFrom(rcId, op, langlinkTable, "resource");
 203+ deleteDataFrom(rcId, op, broaderTable, "resource");
197204
 205+ deleteDataFrom(rcId, op, aboutTable, "resource");
 206+ deleteOrphansFrom(rcId, op, conceptTable, aboutTable, "resource");
 207+
198208 deleteDataFrom(rcId, op, aliasTable, "resource");
199209 deleteDataFrom(rcId, op, sectionTable, "resource");
200210 deleteDataFrom(rcId, op, resourceTable, "id");
@@ -245,6 +255,15 @@
246256
247257
248258 /**
 259+ * @see de.brightbyte.wikiword.store.builder.LocalConceptStoreBuilder#storeResourceAbout(java.lang.String, de.brightbyte.wikiword.ResourceType, java.util.Date, int conceptId, String conceptName)
 260+ */
 261+ public int storeResourceAbout(String name, ResourceType ptype, Date time, int conceptId, String conceptName) throws PersistenceException {
 262+ int rcId = storeResource(name, ptype, time);
 263+ storeAbout(rcId, conceptId, conceptName);
 264+ return rcId;
 265+ }
 266+
 267+ /**
249268 * @see de.brightbyte.wikiword.store.builder.LocalConceptStoreBuilder#storeResource(java.lang.String, de.brightbyte.wikiword.ResourceType, java.util.Date)
250269 */
251270 public int storeResource(String name, ResourceType ptype, Date time) throws PersistenceException {
@@ -256,7 +275,9 @@
257276 resourceInserter.updateString("timestamp", timestampFormatter.format(time));
258277 resourceInserter.updateRow();
259278
260 - return resourceInserter.getLastId();
 279+ int rcId = resourceInserter.getLastId();
 280+
 281+ return rcId;
261282 } catch (SQLException e) {
262283 throw new PersistenceException(e);
263284 }
@@ -278,7 +299,6 @@
279300 }
280301
281302 conceptInserter.updateDouble("random", random.nextDouble());
282 - if (rcId>=0) conceptInserter.updateInt("resource", rcId);
283303 conceptInserter.updateString("name", name);
284304 conceptInserter.updateInt("type", ctype.getCode());
285305 conceptInserter.updateRow();
@@ -287,6 +307,8 @@
288308 id = conceptInserter.getLastId();
289309 }
290310
 311+ if (rcId>=0) storeAbout(rcId, id, name);
 312+
291313 return id;
292314 } catch (SQLException e) {
293315 throw new PersistenceException(e);
@@ -412,6 +434,33 @@
413435 }
414436
415437 /**
 438+ * @see de.brightbyte.wikiword.store.builder.LocalConceptStoreBuilder#storeAbout(int, String)
 439+ */
 440+ public void storeAbout(int rcId, String conceptName) throws PersistenceException {
 441+ storeAbout(rcId, -1, conceptName);
 442+ }
 443+
 444+ /**
 445+ * @see de.brightbyte.wikiword.store.builder.LocalConceptStoreBuilder#storeAbout(int, int, String)
 446+ */
 447+ public void storeAbout(int rcId, int concept, String conceptName) throws PersistenceException {
 448+ try {
 449+ if (rcId<0) throw new IllegalArgumentException("bad resource id "+rcId);
 450+ conceptName = checkName(rcId, conceptName, "concept name (resource #{0})", rcId);
 451+
 452+ aboutInserter.updateInt("resource", rcId);
 453+ aboutInserter.updateString("concept_name", conceptName);
 454+
 455+ if (concept>0) aboutInserter.updateInt("concept", concept);
 456+ else if (idManager!=null) aboutInserter.updateInt("concept", idManager.aquireId(conceptName));
 457+
 458+ aliasInserter.updateRow();
 459+ } catch (SQLException e) {
 460+ throw new PersistenceException(e);
 461+ }
 462+ }
 463+
 464+ /**
416465 * @see de.brightbyte.wikiword.builder.WikiStoreBuilder#storeConceptReference(int, int, java.lang.String, java.lang.String)
417466 */
418467 /*public void storeConceptReference(int rcId, int source, String sourceName, String target) throws PersistenceException {
@@ -606,6 +655,11 @@
607656 }
608657
609658 public void finishMissingConcepts() throws PersistenceException {
 659+ if (beginTask("finishMissingConcpets", "buildMissingConcepts:about")) {
 660+ int n = buildMissingConcepts(aboutTable, "concept", "concept_name");
 661+ endTask("finishMissingConcpets", "buildMissingConcepts:about", n+" concepts");
 662+ }
 663+
610664 if (beginTask("finishMissingConcpets", "buildMissingConcepts:link")) {
611665 int n = buildMissingConcepts(linkTable, "target", "target_name");
612666 endTask("finishMissingConcpets", "buildMissingConcepts:link", n+" concepts");
@@ -655,10 +709,16 @@
656710 }
657711
658712 public void finishIdReferences() throws PersistenceException {
 713+ if (idManager==null && beginTask("finishIdReferences", "buildIdLinks:about")) {
 714+ int n = buildIdLinks(aboutTable, "concept_name", "concept", 1);
 715+ endTask("finishIdReferences", "buildIdLinks:about", n+" references");
 716+ }
 717+
659718 //XXX: if (beginTask("finish.buildIdLinks:link.term_text")) buildIdLinks(useTable, "term_text", "term");
660719 //NOTE: don't need this, anchor-id is only null if anchor_name is null too. //XXX: really?! if (beginTask("finish.buildIdLinks:link.anchor_name")) buildIdLinks(linkTable, "anchor_name", "anchor"); //Uses index _use.target (and unique key _concept.name)
 720+
661721 if (idManager==null && beginTask("finishIdReferences", "buildIdLinks:link.target")) {
662 - int n = buildIdLinks(linkTable, "target_name", "target", 3);
 722+ int n = buildIdLinks(linkTable, "target_name", "target", 5);
663723 endTask("finishIdReferences", "buildIdLinks:link.target", n+" references");
664724 }
665725 if (idManager==null && beginTask("finishIdReferences", "buildIdLinks:broader")) {
@@ -670,7 +730,7 @@
671731 endTask("finishIdReferences", "buildIdLinks:narrower", n+" references");
672732 }
673733 if (idManager==null && beginTask("finishIdReferences", "buildIdLinks:alias")) {
674 - int n = buildIdLinks(aliasTable, "target_name", "target", 1);
 734+ int n = buildIdLinks(aliasTable, "target_name", "target", -5);
675735 endTask("finishIdReferences", "buildIdLinks:alias", n+" references");
676736 }
677737 //if (beginTask("finishIdReferences", "buildIdLinks:reference")) buildIdLinks(referenceTable, "target_name", "target");
@@ -678,12 +738,19 @@
679739
680740 public void finishAliases() throws PersistenceException {
681741 if (beginTask("finishAliases", "resolveRedirects:link")) {
682 - int n = resolveRedirects(linkTable, "target_name", "target", AliasScope.REDIRECT, 3);
 742+ //XXX: SLOW!
 743+ //TODO: smaller chunks? chunk on target table, not alias table? force index?
 744+ int n = resolveRedirects(linkTable, "target_name", "target", AliasScope.REDIRECT, 8);
683745 endTask("finishAliases", "resolveRedirects:link", n+" entries");
684746 }
685747
686748 //NOTE: broader.broad_name already done in finishMissingConcepts for AliasScope.BROADER
687749
 750+ if (beginTask("finishAliases", "resolveRedirects:about")) {
 751+ int n = resolveRedirects(aboutTable, null, "concept", null, 1);
 752+ endTask("finishAliases", "resolveRedirects:about", n+" entries");
 753+ }
 754+
688755 if (beginTask("finishAliases", "resolveRedirects:narrow")) {
689756 int n = resolveRedirects(broaderTable, "narrow_name", "narrow", null, 1);
690757 endTask("finishAliases", "resolveRedirects:narrow", n+" entries");
@@ -1297,4 +1364,16 @@
12981365 c = executeUpdate("resetTermsForUnknownConcepts", sql); //XXX: chunk?!
12991366 log("deleted "+c+" entries for unknown concepts from broader table");
13001367 }
 1368+
 1369+
 1370+ public void deleteDataFrom(int rcId) throws PersistenceException {
 1371+ log("deleting data from "+rcId);
 1372+ deleteDataFrom(rcId, "=");
 1373+ }
 1374+
 1375+ public void deleteDataAfter(int rcId, boolean inclusive) throws PersistenceException {
 1376+ String op = inclusive ? ">=" : ">";
 1377+ log("deleting data from with id "+op+" "+rcId);
 1378+ deleteDataFrom(rcId, op);
 1379+ }
13011380 }
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/WikiWordStoreBuilder.java
@@ -33,10 +33,6 @@
3434
3535 //public abstract void clearStatistics() throws PersistenceException;
3636
37 - public abstract void deleteDataAfter(int lastId, boolean inclusive) throws PersistenceException;
38 -
39 - public abstract void deleteDataFrom(int lastId) throws PersistenceException;
40 -
4137 public abstract void checkConsistency() throws PersistenceException;
4238
4339 public abstract void dumpTableStats(Output out) throws PersistenceException;
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseWikiWordConceptStoreBuilder.java
@@ -76,14 +76,6 @@
7777 relationTable = (RelationTable)relationInserter.getTable();
7878 }
7979
80 - @Override
81 - protected void deleteDataFrom(int rcId, String op) throws PersistenceException {
82 - deleteDataFrom(rcId, op, linkTable, "resource");
83 - deleteDataFrom(rcId, op, langlinkTable, "resource");
84 - deleteDataFrom(rcId, op, broaderTable, "resource");
85 - deleteDataFrom(rcId, op, conceptTable, "resource");
86 - }
87 -
8880 protected int deleteConceptBroader(int narrow, int broad) throws SQLException {
8981 String sql = "DELETE FROM "+broaderTable.getSQLName()+" " +
9082 " WHERE narrow = "+narrow+" " +
@@ -482,12 +474,6 @@
483475 degreeTable = (EntityTable)degreeInserter.getTable();
484476 }
485477
486 -
487 - @Override
488 - protected void deleteDataFrom(int rcId, String op) throws PersistenceException {
489 - throw new UnsupportedOperationException();
490 - }
491 -
492478 protected int getNumberOfConcepts() throws PersistenceException {
493479 String sql = "select count(*) from "+conceptTable.getSQLName();
494480 try {
@@ -890,10 +876,5 @@
891877 return executeChunkedUpdate(query, chunkFactor);
892878 }
893879
894 - @Override
895 - protected void deleteDataFrom(int rcId, String op) throws PersistenceException {
896 - //deleteDataFrom(rcId, op, conceptInfoTable, "concept", conceptTable, "resource");
897 - throw new UnsupportedOperationException();
898 - }
899880 }
900881 }
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseGlobalConceptStoreBuilder.java
@@ -173,11 +173,6 @@
174174
175175 //---------------------------------
176176
177 - @Override
178 - protected void deleteDataFrom(int rcId, String op) throws PersistenceException {
179 - throw new UnsupportedOperationException();
180 - }
181 -
182177 public void importConcepts() throws PersistenceException {
183178 Corpus[] cc = getLanguages();
184179
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/IncrementalStoreBuilder.java
@@ -0,0 +1,9 @@
 2+package de.brightbyte.wikiword.store.builder;
 3+
 4+import de.brightbyte.util.PersistenceException;
 5+
 6+public interface IncrementalStoreBuilder {
 7+
 8+ public void deleteDataAfter(int delAfter, boolean inclusive) throws PersistenceException;
 9+
 10+}
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/LocalConceptStoreBuilder.java
@@ -18,7 +18,7 @@
1919 * (generally by a WikiTextAnalyzer) may be written to. It may be backed by
2020 * a RDBMS, or some other way of storing the data.
2121 */
22 -public interface LocalConceptStoreBuilder extends WikiWordConceptStoreBuilder<LocalConcept> {
 22+public interface LocalConceptStoreBuilder extends WikiWordConceptStoreBuilder<LocalConcept>, IncrementalStoreBuilder {
2323
2424 public abstract void storeDefinition(int rcId, int conceptId, String definition)
2525 throws PersistenceException;
@@ -26,6 +26,9 @@
2727 public abstract int storeResource(String name, ResourceType ptype,
2828 Date time) throws PersistenceException;
2929
 30+ public abstract int storeResourceAbout(String name, ResourceType ptype,
 31+ Date time, int concept, String conceptName) throws PersistenceException;
 32+
3033 public abstract int storeConcept(int rcId, String name, ConceptType ctype)
3134 throws PersistenceException;
3235
@@ -51,6 +54,12 @@
5255 String sourceName, int target, String targetName, AliasScope scope)
5356 throws PersistenceException;
5457
 58+ public abstract void storeAbout(int resource, String conceptName)
 59+ throws PersistenceException;
 60+
 61+ public abstract void storeAbout(int resource, int concept, String conceptName)
 62+ throws PersistenceException;
 63+
5564 //public abstract void storeConceptReference(int rcId, int source,
5665 // String sourceName, String target) throws PersistenceException;
5766
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabaseTextStoreBuilder.java
@@ -22,7 +22,7 @@
2323 * The TweakSet supplied to the constructur is used by
2424 * {@link de.brightbyte.wikiword.store.DatabaseTextStore}, see there.
2525 */
26 -public class DatabaseTextStoreBuilder extends DatabaseWikiWordStoreBuilder implements TextStoreBuilder {
 26+public class DatabaseTextStoreBuilder extends DatabaseLocalStoreBuilder implements TextStoreBuilder {
2727
2828 protected LocalConceptStoreSchema localConceptDatabase;
2929
Index: trunk/WikiWord/WikiWordBuilder/src/main/java/de/brightbyte/wikiword/store/builder/DatabasePropertyStoreBuilder.java
@@ -13,7 +13,7 @@
1414 import de.brightbyte.wikiword.schema.AliasScope;
1515 import de.brightbyte.wikiword.schema.PropertyStoreSchema;
1616
17 -public class DatabasePropertyStoreBuilder extends DatabaseWikiWordStoreBuilder implements PropertyStoreBuilder {
 17+public class DatabasePropertyStoreBuilder extends DatabaseLocalStoreBuilder implements PropertyStoreBuilder {
1818
1919 protected DatabaseLocalConceptStoreBuilder conceptStore;
2020

Status & tagging log