r51006 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51005‎ | r51006 | r51007 >
Date:10:52, 26 May 2009
Author:daniel
Status:deferred
Tags:
Comment:
infrastructure for processing mappings
Modified paths:
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/MappingPassThrough.java (added) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/MappingProcessor.java (added) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/MappingStore.java (added) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/OptimalMappingSelector.java (added) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/ResultSetAssociationCursor.java (added) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/OptimalMappingSelector.java
@@ -0,0 +1,46 @@
 2+package de.brightbyte.wikiword.integrator;
 3+
 4+import java.util.Collection;
 5+import java.util.Comparator;
 6+
 7+import de.brightbyte.abstraction.PropertyAccessor;
 8+import de.brightbyte.data.Functor;
 9+import de.brightbyte.data.NaturalComparator;
 10+import de.brightbyte.data.Optimum;
 11+import de.brightbyte.data.PropertyComparator;
 12+import de.brightbyte.data.cursor.DataCursor;
 13+import de.brightbyte.util.PersistenceException;
 14+
 15+public class OptimalMappingSelector implements MappingProcessor {
 16+
 17+ protected Optimum<FeatureSet> optimum;
 18+
 19+ public OptimalMappingSelector(String property, Functor<Number, ? extends Collection<Number>> aggregator) {
 20+ this((Comparator<FeatureSet>)(Object)PropertyComparator.newMultiMapEntryComparator(property, (Comparator<Number>)(Object)NaturalComparator.instance, aggregator, Number.class));
 21+ }
 22+
 23+ public OptimalMappingSelector(PropertyAccessor<FeatureSet, Number> accessor) {
 24+ this(new Optimum<FeatureSet>(accessor));
 25+ }
 26+
 27+ public OptimalMappingSelector(Comparator<FeatureSet> comp) {
 28+ this(new Optimum<FeatureSet>(comp));
 29+ }
 30+
 31+ public OptimalMappingSelector(Optimum<FeatureSet> optimum) {
 32+ if (optimum==null) throw new NullPointerException();
 33+ this.optimum = optimum;
 34+ }
 35+
 36+ public void processMappings(DataCursor<MappingCandidates> cursor,
 37+ MappingStore store) throws PersistenceException {
 38+
 39+ MappingCandidates m;
 40+ while ((m = cursor.next()) != null ) {
 41+ FeatureSet f = optimum.apply(m.getCandidates());
 42+ store.storeMapping(m.getSubject(), f, f);
 43+ }
 44+
 45+ }
 46+
 47+}
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/MappingPassThrough.java
@@ -0,0 +1,20 @@
 2+package de.brightbyte.wikiword.integrator;
 3+
 4+import de.brightbyte.data.cursor.DataCursor;
 5+import de.brightbyte.util.PersistenceException;
 6+
 7+public class MappingPassThrough implements MappingProcessor {
 8+
 9+ public void processMappings(DataCursor<MappingCandidates> cursor,
 10+ MappingStore store) throws PersistenceException {
 11+
 12+ MappingCandidates m;
 13+ while ((m = cursor.next()) != null ) {
 14+ for (FeatureSet f: m.getCandidates()) {
 15+ store.storeMapping(m.getSubject(), f, f);
 16+ }
 17+ }
 18+
 19+ }
 20+
 21+}
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/ResultSetAssociationCursor.java
@@ -0,0 +1,56 @@
 2+package de.brightbyte.wikiword.integrator;
 3+
 4+import java.sql.ResultSet;
 5+
 6+import de.brightbyte.db.DatabaseDataSet;
 7+import de.brightbyte.db.DatabaseDataSet.Factory;
 8+
 9+public class ResultSetAssociationCursor extends DatabaseDataSet.Cursor<Association> {
 10+
 11+ public static class FeatureSetFactory implements Factory<FeatureSet> {
 12+ protected String[] fields;
 13+
 14+ public FeatureSetFactory(String[] fields) {
 15+ super();
 16+ this.fields = fields;
 17+ }
 18+
 19+ public FeatureSet newInstance(ResultSet row) throws Exception {
 20+ FeatureSet f = new DefaultFeatureSet();
 21+
 22+ for (String k: fields) {
 23+ Object v = row.getObject(k);
 24+ f.put(k, v);
 25+ }
 26+
 27+ return f;
 28+ }
 29+
 30+ }
 31+
 32+ public static class AssociationFactory implements Factory<Association> {
 33+ protected Factory<FeatureSet> sourceFactory;
 34+ protected Factory<FeatureSet> targetFactory;
 35+ protected Factory<FeatureSet> propsFactory;
 36+
 37+ public AssociationFactory(Factory<FeatureSet> sourceFactory, Factory<FeatureSet> targetFactory, Factory<FeatureSet> propsFactory) {
 38+ this.sourceFactory = sourceFactory;
 39+ this.targetFactory = targetFactory;
 40+ this.propsFactory = propsFactory;
 41+ }
 42+
 43+ public Association newInstance(ResultSet row) throws Exception {
 44+ FeatureSet source = sourceFactory.newInstance(row);
 45+ FeatureSet target = targetFactory.newInstance(row);
 46+ FeatureSet props = propsFactory.newInstance(row);
 47+
 48+ return new Association(source, target, props);
 49+ }
 50+
 51+ }
 52+
 53+ public ResultSetAssociationCursor(ResultSet resultSet, String[] sourceFields, String[] targetFields, String[] propertyFields) {
 54+ super(resultSet, new AssociationFactory(new FeatureSetFactory(sourceFields), new FeatureSetFactory(targetFields), new FeatureSetFactory(propertyFields)));
 55+ }
 56+
 57+}
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/MappingStore.java
@@ -0,0 +1,7 @@
 2+package de.brightbyte.wikiword.integrator;
 3+
 4+import de.brightbyte.util.PersistenceException;
 5+
 6+public interface MappingStore {
 7+ public void storeMapping(FeatureSet source, FeatureSet target, FeatureSet props) throws PersistenceException;
 8+}
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/MappingProcessor.java
@@ -0,0 +1,8 @@
 2+package de.brightbyte.wikiword.integrator;
 3+
 4+import de.brightbyte.data.cursor.DataCursor;
 5+import de.brightbyte.util.PersistenceException;
 6+
 7+public interface MappingProcessor {
 8+ public void processMappings(DataCursor<MappingCandidates> cursor, MappingStore store) throws PersistenceException;
 9+}

Status & tagging log