r51534 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51533‎ | r51534 | r51535 >
Date:12:58, 6 June 2009
Author:daniel
Status:deferred
Tags:
Comment:
LoadForeignProperties operational
Modified paths:
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/ForeignEntityStoreDescriptor.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/LoadForeignProperties.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/ForeignEntityCursor.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/processor/AbstractProcessor.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/store/DatabaseForeignPropertyStoreBuilder.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/store/IntegratorSchema.java (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/processor/AbstractProcessor.java
@@ -40,7 +40,7 @@
4141 }
4242
4343 public void reset() {
44 - itemTracker = new ImportProgressTracker("pages");
 44+ itemTracker = new ImportProgressTracker("items");
4545 progressTicks = 0;
4646 }
4747
@@ -58,6 +58,7 @@
5959 }
6060
6161 public void tracerStep() {
 62+ itemTracker.step();
6263 progressTicks++;
6364 if (progressTicks>progressInterval) {
6465 trackerChunk();
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/ForeignEntityStoreDescriptor.java
@@ -1,5 +1,8 @@
22 package de.brightbyte.wikiword.integrator;
33
 4+import java.io.File;
 5+import java.net.MalformedURLException;
 6+import java.net.URL;
47 import java.util.List;
58 import java.util.Map;
69
@@ -23,17 +26,17 @@
2427 return getTweak("foreign.query", null);
2528 }
2629
27 - public String getSourceFileName() {
 30+ public String getSourceFileName() { //FIXME
2831 return getTweak("foreign.file", null);
2932 }
3033
3134 public String[] getDataFields() {
32 - List<String> v = getTweak("foreign.field", (List<String>)null);
 35+ List<String> v = getTweak("foreign.fields", (List<String>)null);
3336 if (v==null) return null;
3437 return (String[]) v.toArray(new String[v.size()]);
3538 }
3639
37 - public Map<String, String> getSplitExpressions() {
 40+ public Map<String, String> getSplitExpressions() { //FIXME:!
3841 return getTweak("split", (Map<String, String>)null);
3942 }
4043
@@ -42,11 +45,11 @@
4346 }
4447
4548 public String getPropertyNameField() {
46 - return getTweak("foreign.property-name-field", "value");
 49+ return getTweak("foreign.property-name-field", null);
4750 }
4851
4952 public String getConceptIdField() {
50 - return getTweak("foreign.concept-id-field", "id");
 53+ return getTweak("foreign.concept-id-field", null);
5154 }
5255
5356 public String getConceptNameField() {
@@ -54,9 +57,23 @@
5558 }
5659
5760 public String getAuthorityName() {
58 - String name = getTweak("foreign.authority-name", null);
 61+ String name = getTweak("foreign.authority", null);
5962 if (name==null) throw new RuntimeException("authority name not specified!");
6063 return name;
6164 }
 65+
 66+ public void setBaseURL(URL baseURL) {
 67+ parameters.put(".baseURL", baseURL);
 68+ }
6269
 70+ public URL getBaseURL() {
 71+ try {
 72+ URL u = getTweak(".baseURL", (URL)null);
 73+ if (u==null) u = new File(".").toURI().toURL();
 74+ return u;
 75+ } catch (MalformedURLException e) {
 76+ return null;
 77+ }
 78+ }
 79+
6380 }
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/LoadForeignProperties.java
@@ -25,6 +25,7 @@
2626 import de.brightbyte.wikiword.integrator.data.MangelingFeatureSetCursor;
2727 import de.brightbyte.wikiword.integrator.data.ResultSetFeatureSetCursor;
2828 import de.brightbyte.wikiword.integrator.data.TsvFeatureSetCursor;
 29+import de.brightbyte.wikiword.integrator.processor.ForeignPropertyPassThrough;
2930 import de.brightbyte.wikiword.integrator.processor.ForeignPropertyProcessor;
3031 import de.brightbyte.wikiword.integrator.store.DatabaseForeignPropertyStoreBuilder;
3132 import de.brightbyte.wikiword.integrator.store.ForeignPropertyStoreBuilder;
@@ -37,24 +38,38 @@
3839 */
3940 public class LoadForeignProperties extends StoreBackedApp<ForeignPropertyStoreBuilder> {
4041
41 - protected ForeignPropertyStoreBuilder propertyStore;
 42+ //protected ForeignPropertyStoreBuilder propertyStore;
4243 protected ForeignPropertyProcessor propertyProcessor;
4344 protected InputFileHelper inputHelper;
 45+ private ForeignEntityStoreDescriptor sourceDescriptor;
4446
4547 public LoadForeignProperties() {
4648 super(true, true);
4749 }
4850
 51+ protected InputFileHelper getInputHelper() {
 52+ if (inputHelper==null) {
 53+ inputHelper = new InputFileHelper(tweaks);
 54+ }
 55+ return inputHelper;
 56+ }
 57+
4958 @Override
5059 protected WikiWordStoreFactory<? extends ForeignPropertyStoreBuilder> createConceptStoreFactory() throws IOException, PersistenceException {
5160 return new DatabaseForeignPropertyStoreBuilder.Factory(getTargetTableName(), getConfiguredDataset(), getConfiguredDataSource(), tweaks);
5261 }
5362
54 - protected String getTargetTableName() {
55 - return args.getParameterCount() > 2 ? args.getParameter(2) : "foreign_property";
 63+ protected String getTargetTableName() throws IOException {
 64+ if (args.getParameterCount() > 2) return args.getParameter(2);
 65+
 66+ String authority = getSourceDescriptor().getAuthorityName();
 67+ authority = authority.replaceAll("[^\\w\\d]", "_").toLowerCase();
 68+
 69+ return authority+"_property";
5670 }
5771
5872 protected String getSourceDescriptionFileName() {
 73+ if (args.getParameterCount() < 2) throw new IllegalArgumentException("missing second parameter (descripion file name)");
5974 return args.getParameter(1);
6075 }
6176
@@ -73,13 +88,17 @@
7489 DataCursor<ForeignEntity> cursor = openPropertySource();
7590
7691 section("-- process properties --------------------------------------------------");
 92+ this.conceptStore.prepareImport();
 93+
 94+ this.propertyProcessor = new ForeignPropertyPassThrough(conceptStore); //FIXME
7795 this.propertyProcessor.processProperties(cursor);
78 -
7996 cursor.close();
 97+
 98+ this.conceptStore.finalizeImport();
8099 }
81100
82101 protected DataCursor<ForeignEntity> openPropertySource() throws IOException, SQLException, PersistenceException {
83 - ForeignEntityStoreDescriptor sourceDescriptor = loadSourceDescriptor();
 102+ ForeignEntityStoreDescriptor sourceDescriptor = getSourceDescriptor();
84103
85104 String enc = sourceDescriptor.getDataEncoding();
86105 String sql = sourceDescriptor.getSqlQuery();
@@ -87,8 +106,8 @@
88107
89108 if (sql==null) {
90109 String n = sourceDescriptor.getSourceFileName();
91 - String format = inputHelper.getFormat(n);
92 - in = inputHelper.open(n);
 110+ String format = getInputHelper().getFormat(n); //FIXME: explicit format!
 111+ in = getInputHelper().open(sourceDescriptor.getBaseURL(), n);
93112
94113 if (format!=null && format.equals("sql")) {
95114 sql = IOUtil.slurp(in, enc);
@@ -129,15 +148,21 @@
130149 return new ForeignEntityCursor(fsc, sourceDescriptor.getAuthorityName(), sourceDescriptor.getConceptIdField(), sourceDescriptor.getConceptNameField());
131150 }
132151
133 - protected ForeignEntityStoreDescriptor loadSourceDescriptor() throws IOException {
134 - ForeignEntityStoreDescriptor descriptor = new ForeignEntityStoreDescriptor();
 152+ protected ForeignEntityStoreDescriptor getSourceDescriptor() throws IOException {
 153+ if (sourceDescriptor!=null) return sourceDescriptor;
135154
 155+ sourceDescriptor = new ForeignEntityStoreDescriptor(tweaks);
 156+
136157 String n = getSourceDescriptionFileName();
137 - InputStream in = inputHelper.open(n);
138 - descriptor.loadTweaks(in);
 158+ InputStream in = getInputHelper().open(n);
 159+ sourceDescriptor.setBaseURL(getInputHelper().getBaseURL(n));
 160+ sourceDescriptor.loadTweaks(in);
139161 in.close();
140162
141 - return descriptor;
 163+ sourceDescriptor.setTweaks(System.getProperties(), "wikiword.source."); //XXX: doc
 164+ sourceDescriptor.setTweaks(args, "source."); //XXX: doc
 165+
 166+ return sourceDescriptor;
142167 }
143168
144169 @SuppressWarnings("unchecked")
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/ForeignEntityCursor.java
@@ -12,9 +12,12 @@
1313 protected String nameField;
1414
1515 public ForeignEntityCursor(DataCursor<FeatureSet> source, String authorityId, String idField, String nameField) {
 16+ if (idField==null) throw new NullPointerException();
1617 if (authorityId==null) throw new NullPointerException();
17 - if (idField==null) throw new NullPointerException();
 18+ if (source==null) throw new NullPointerException();
 19+ if (nameField==null) nameField = idField;
1820
 21+ this.source = source;
1922 this.authorityId = authorityId;
2023 this.idField = idField;
2124 this.nameField = nameField;
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/store/IntegratorSchema.java
@@ -32,7 +32,7 @@
3333
3434 table.addField( new DatabaseField(this, "property", getTextType(255), null, true, KeyType.INDEX) );
3535 table.addField( new DatabaseField(this, "value", getTextType(255), null, true, null) );
36 - table.addField( new DatabaseField(this, "qualifier", getTextType(64), null, true, null) );
 36+ table.addField( new DatabaseField(this, "qualifier", getTextType(64), null, false, null) );
3737
3838 table.addKey( new DatabaseKey(this, KeyType.INDEX, "property_value", new String[] {"property", "value"}) );
3939 table.addKey( new DatabaseKey(this, KeyType.INDEX, "external_property", new String[] {"external_authority", "external_id", "property"}) );
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/store/DatabaseForeignPropertyStoreBuilder.java
@@ -52,6 +52,8 @@
5353 protected DatabaseForeignPropertyStoreBuilder(String table, IntegratorSchema integratorSchema, TweakSet tweaks, Agenda agenda) throws SQLException, PersistenceException {
5454 super(integratorSchema, tweaks, agenda);
5555
 56+ integratorSchema.newForeignPropertyTable(table);
 57+
5658 this.propertyInserter = configureTable(table, 128, 4*32);
5759 this.propertyTable = (RelationTable)propertyInserter.getTable();
5860 }
@@ -99,4 +101,9 @@
100102 }
101103 }
102104 */
 105+
 106+ public void prepareImport() throws PersistenceException {
 107+ createTables(true);
 108+ }
 109+
103110 }
\ No newline at end of file

Status & tagging log