r53579 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53578‎ | r53579 | r53580 >
Date:10:44, 21 July 2009
Author:daniel
Status:deferred
Tags:
Comment:
data model revamp complete, most test cases pass again
Modified paths:
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/AggregatingAssociationCursor.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/ConceptEntityRecord.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultAssociation.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultConceptEntityRecord.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultForeignEntityRecord.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultRecord.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/FeatureSet.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/FilteredMappingCandidateCursor.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/ForeignEntityRecord.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/GenericAssociation.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/MappingCandidateCursor.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/Record.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/BuildConceptMappingsTest.java (deleted) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/AggregatingAssociationCursorTest.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/CollapsingFeatureSetCursorTest.java (deleted) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/CollapsingMappingCandidateCursorTest.java (deleted) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureAssemblingCursorTest.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureBuilderCursorTest.java (added) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureSetValueSplitterTest.java (deleted) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureSetsTest.java (deleted) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FilteredMappingCandidateCursorTest.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/MappingCandidateCursorTest.java+(from+/trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/CollapsingMappingCandidateCursorTest.java (added) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/BuildConceptMappingsTest.java
@@ -1,22 +0,0 @@
2 -package de.brightbyte.wikiword.integrator;
3 -
4 -public class BuildConceptMappingsTest extends IntegratorAppTestBase<BuildConceptMappings> {
5 -
6 - public BuildConceptMappingsTest() {
7 - super("BuildConceptMappingsTest");
8 -
9 - dumpActual = true;
10 - dumpExpected = true;
11 - }
12 -
13 - //-----------------------------------------------------------------------------------------------------
14 - public void testPassThrough() throws Exception {
15 - runApp("passThrough");
16 - }
17 -
18 - @Override
19 - protected BuildConceptMappings createApp() {
20 - return new BuildConceptMappings();
21 - }
22 -
23 -}
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureSetsTest.java
@@ -1,74 +0,0 @@
2 -package de.brightbyte.wikiword.integrator.data;
3 -
4 -import java.util.ArrayList;
5 -
6 -import junit.framework.TestCase;
7 -import de.brightbyte.data.LabeledVector;
8 -import de.brightbyte.data.MapLabeledVector;
9 -
10 -public class FeatureSetsTest extends TestCase {
11 -
12 - public void testMerge() {
13 - FeatureSet a = new DefaultFeatureSet("name");
14 - a.put("name", "A");
15 -
16 - FeatureSet b = new DefaultFeatureSet("name");
17 - b.put("name", "B");
18 - b.put("x", 23);
19 -
20 - FeatureSet c = new DefaultFeatureSet("name");
21 - c.put("name", "C");
22 -
23 - //---------------------------------------------------
24 -
25 - FeatureSet ab = new DefaultFeatureSet("name");
26 - ab.put("name", "A");
27 - ab.put("name", "B");
28 - ab.put("x", 23);
29 -
30 - assertEquals(ab, FeatureSets.merge(a, b));
31 -
32 - //---------------------------------------------------
33 -
34 - FeatureSet abc = new DefaultFeatureSet("name");
35 - abc.put("name", "A");
36 - abc.put("name", "B");
37 - abc.put("x", 23);
38 - abc.put("name", "C");
39 -
40 - assertEquals(abc, FeatureSets.merge(a, b, c));
41 - }
42 -
43 - public void testHistogram() {
44 - ArrayList<String> list = new ArrayList<String>();
45 - list.add("x");
46 - list.add("y");
47 - list.add("z");
48 - list.add("x");
49 - list.add("z");
50 - list.add("z");
51 -
52 - LabeledVector<String> v = FeatureSets.histogram(list);
53 - LabeledVector<String> w = new MapLabeledVector<String>();
54 - w.set("x", 2);
55 - w.set("y", 1);
56 - w.set("z", 3);
57 -
58 - assertEquals(w, v);
59 - }
60 -
61 - public void testCount() {
62 - ArrayList<String> list = new ArrayList<String>();
63 - list.add("x");
64 - list.add("y");
65 - list.add("z");
66 - list.add("x");
67 - list.add("z");
68 - list.add("z");
69 -
70 - assertEquals(2, FeatureSets.count(list, "x"));
71 - assertEquals(1, FeatureSets.count(list, "y"));
72 - assertEquals(3, FeatureSets.count(list, "z"));
73 - }
74 -
75 -}
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureSetValueSplitterTest.java
@@ -1,44 +0,0 @@
2 -package de.brightbyte.wikiword.integrator.data;
3 -
4 -import junit.framework.TestCase;
5 -
6 -public class FeatureSetValueSplitterTest extends TestCase {
7 -
8 - public void testApply() {
9 - FeatureSet in = new DefaultFeatureSet("name");
10 - in.put("name", "A");
11 - in.put("name", "");
12 - in.put("name", "B,C,");
13 - in.put("name", "D; E ,F");
14 - in.put("name", ";G");
15 - in.put("foo", "A,B,C");
16 -
17 - FeatureSet exp = new DefaultFeatureSet("name");
18 - exp.put("name", "A");
19 - exp.put("name", "");
20 - exp.put("name", "B");
21 - exp.put("name", "C");
22 - exp.put("name", "D");
23 - exp.put("name", "E");
24 - exp.put("name", "F");
25 - exp.put("name", "");
26 - exp.put("name", "G");
27 - exp.put("foo", "A,B,C");
28 -
29 - FeatureSetValueSplitter splitter = new FeatureSetValueSplitter("name", "\\s*[,;]\\s*", 0);
30 - assertEquals(exp, splitter.apply(in));
31 -
32 - in = new DefaultFeatureSet("name");
33 - in.put("name", "A");
34 - in.put("name", "");
35 - in.put("foo", "A,B,C");
36 -
37 - exp = new DefaultFeatureSet("name");
38 - exp.put("name", "A");
39 - exp.put("name", "");
40 - exp.put("foo", "A,B,C");
41 -
42 - assertEquals(exp, splitter.apply(in));
43 - }
44 -
45 -}
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/CollapsingFeatureSetCursorTest.java
@@ -1,84 +0,0 @@
2 -package de.brightbyte.wikiword.integrator.data;
3 -
4 -import java.util.ArrayList;
5 -import java.util.Collection;
6 -
7 -import junit.framework.TestCase;
8 -import de.brightbyte.data.cursor.DataCursor;
9 -import de.brightbyte.data.cursor.IteratorCursor;
10 -import de.brightbyte.util.PersistenceException;
11 -
12 -public class CollapsingFeatureSetCursorTest extends TestCase {
13 -
14 - private static <T> Collection<T> slurp(DataCursor<T> cursor) throws PersistenceException {
15 - ArrayList<T> list = new ArrayList<T>();
16 - T obj;
17 - while ((obj = cursor.next()) != null) list.add(obj);
18 - return list;
19 - }
20 -
21 - public void testNext() throws PersistenceException {
22 - FeatureSet a = new DefaultFeatureSet("id");
23 - a.put("id", 1);
24 - a.put("foo", "A");
25 -
26 - FeatureSet b = new DefaultFeatureSet("id");
27 - b.put("id", 1);
28 - b.put("foo", "B");
29 -
30 - FeatureSet x = new DefaultFeatureSet("id");
31 - x.put("id", 2);
32 - x.put("foo", "X");
33 -
34 - FeatureSet y = new DefaultFeatureSet("id");
35 - y.put("id", 2);
36 - y.put("foo", "Y");
37 -
38 - FeatureSet p = new DefaultFeatureSet("id");
39 - p.put("id", 3);
40 - p.put("foo", "P");
41 -
42 - FeatureSet q = new DefaultFeatureSet("id");
43 - q.put("id", 3);
44 - q.put("foo", "Q");
45 -
46 - //--------------------------------------
47 - FeatureSet ab = new DefaultFeatureSet("id");
48 - ab.put("id", 1);
49 - ab.put("id", 1);
50 - ab.put("foo", "A");
51 - ab.put("foo", "B");
52 -
53 - FeatureSet xy = new DefaultFeatureSet("id");
54 - xy.put("id", 2);
55 - xy.put("id", 2);
56 - xy.put("foo", "X");
57 - xy.put("foo", "Y");
58 -
59 - FeatureSet pq = new DefaultFeatureSet("id");
60 - pq.put("id", 3);
61 - pq.put("id", 3);
62 - pq.put("foo", "P");
63 - pq.put("foo", "Q");
64 -
65 - //--------------------------------------
66 - ArrayList<FeatureSet> source = new ArrayList<FeatureSet>();
67 - source.add(a);
68 - source.add(b);
69 - source.add(x);
70 - source.add(y);
71 - source.add(p);
72 - source.add(q);
73 -
74 - ArrayList<FeatureSet> exp = new ArrayList<FeatureSet>();
75 - exp.add(ab);
76 - exp.add(xy);
77 - exp.add(pq);
78 -
79 - DataCursor<FeatureSet> sourceCursor = new IteratorCursor<FeatureSet>(source.iterator());
80 - DataCursor<FeatureSet> cursor = new FeatureBuilderCursor(sourceCursor, "id");
81 -
82 - assertEquals(exp, slurp(cursor));
83 - }
84 -
85 -}
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/CollapsingMappingCandidateCursorTest.java
@@ -1,62 +0,0 @@
2 -package de.brightbyte.wikiword.integrator.data;
3 -
4 -import java.util.ArrayList;
5 -import java.util.Collection;
6 -
7 -import junit.framework.TestCase;
8 -import de.brightbyte.data.cursor.DataCursor;
9 -import de.brightbyte.data.cursor.IteratorCursor;
10 -import de.brightbyte.util.PersistenceException;
11 -
12 -public class CollapsingMappingCandidateCursorTest extends TestCase {
13 -
14 - private static <T> Collection<T> slurp(DataCursor<T> cursor) throws PersistenceException {
15 - ArrayList<T> list = new ArrayList<T>();
16 - T obj;
17 - while ((obj = cursor.next()) != null) list.add(obj);
18 - return list;
19 - }
20 -
21 - public void testNext() throws PersistenceException {
22 - FeatureSet a = new DefaultFeatureSet("name");
23 - a.put("authority", "ACME");
24 - a.put("name", "A");
25 -
26 - FeatureSet b = new DefaultFeatureSet("name");
27 - b.put("authority", "ACME");
28 - b.put("name", "B");
29 -
30 - FeatureSet x = new DefaultFeatureSet("name");
31 - x.put("authority", "ACME");
32 - x.put("name", "X");
33 -
34 - FeatureSet y = new DefaultFeatureSet("name");
35 - y.put("authority", "ACME");
36 - y.put("name", "Y");
37 -
38 - FeatureSet p = new DefaultFeatureSet("foo");
39 - p.put("foo", "P");
40 -
41 - FeatureSet q = new DefaultFeatureSet("foo");
42 - q.put("foo", "Q");
43 -
44 - //--------------------------------------
45 - ArrayList<Association> source = new ArrayList<Association>();
46 - source.add(new Association(a, x, p));
47 - source.add(new Association(a, y, p));
48 - source.add(new Association(a, y, q));
49 - source.add(new Association(b, y, q));
50 - source.add(new Association(a, y, q));
51 -
52 - ArrayList<MappingCandidates> exp = new ArrayList<MappingCandidates>();
53 - exp.add(new MappingCandidates(FeatureSets.merge(a, a), FeatureSets.merge(x, p), FeatureSets.merge(y, y, p, q)));
54 - exp.add(new MappingCandidates(b, FeatureSets.merge(y, q)));
55 - exp.add(new MappingCandidates(a, FeatureSets.merge(y, q)));
56 -
57 - DataCursor<Association> sourceCursor = new IteratorCursor<Association>(source.iterator());
58 - DataCursor<MappingCandidates> cursor = new MappingCandidateCursor(sourceCursor, "authority", "name", "name");
59 -
60 - assertEquals(exp, slurp(cursor));
61 - }
62 -
63 -}
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/AggregatingAssociationCursorTest.java
@@ -55,19 +55,21 @@
5656 source.add(new GenericAssociation(a, x, p));
5757 source.add(new GenericAssociation(a, y, p));
5858 source.add(new GenericAssociation(a, y, q));
59 - source.add(new GenericAssociation(b, y, q));
 59+ source.add(new DefaultAssociation(new DefaultRecord(b, y, q), "authority", "id", "name", "concept", "label"));
6060 source.add(new GenericAssociation(a, y, q));
6161
6262 ArrayList<Association> exp = new ArrayList<Association>();
63 - exp.add(new GenericAssociation(a, x, p));
64 - exp.add(new GenericAssociation(a, y, pq));
65 - exp.add(new GenericAssociation(b, y, q));
66 - exp.add(new GenericAssociation(a, y, q));
 63+ exp.add(new GenericAssociation(a, x, new DefaultRecord(a, x, p)));
 64+ exp.add(new GenericAssociation(a, y, new DefaultRecord(a, y, pq)));
 65+ exp.add(new GenericAssociation(b, y, new DefaultRecord(b, y, q)));
 66+ exp.add(new GenericAssociation(a, y, new DefaultRecord(a, y, q)));
6767
6868 DataCursor<Association> sourceCursor = new IteratorCursor<Association>(source.iterator());
69 - DataCursor<Association> cursor = new AggregatingAssociationCursor(sourceCursor);
 69+ AggregatingAssociationCursor cursor = new AggregatingAssociationCursor(sourceCursor);
 70+ cursor.addAccumulator("foo", null); ///XXX: adding "no" accumulator preserves the field as multi-value!
7071
71 - assertEquals(exp, slurp(cursor));
 72+ Collection<Association> act = slurp(cursor);
 73+ assertEquals(exp, act);
7274 }
7375
7476 }
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureAssemblingCursorTest.java
@@ -24,14 +24,18 @@
2525 a.add("id", 1);
2626 a.add("property", "name");
2727 a.add("value", "A");
28 - a.add("value", "a");
2928 a.add("xyzzy", "bla");
3029
 30+ DefaultRecord a2 = new DefaultRecord();
 31+ a2.add("id", 1);
 32+ a2.add("property", "name");
 33+ a2.add("value", "a");
 34+
3135 DefaultRecord b = new DefaultRecord();
3236 b.add("id", 1);
3337 b.add("property", "foo");
3438 b.add("value", "X");
35 - b.add("value", "Y");
 39+ //b.add("value", "Y"); //NOTE: multi-value records are not supported in this context!
3640
3741 DefaultRecord x = new DefaultRecord();
3842 x.add("id", 2);
@@ -50,7 +54,7 @@
5155 one.addFeature("name", "A", null);
5256 one.addFeature("name", "a", null);
5357 one.addFeature("foo", "X", null);
54 - one.addFeature("foo", "Y", null);
 58+ //one.addFeature("foo", "Y", null);
5559
5660 DefaultFeatureSet two = new DefaultFeatureSet();
5761 two.addFeature("id", 2, null);
@@ -58,7 +62,7 @@
5963 two.addFeature("alias", "Foo", null);
6064
6165 List<FeatureSet> exp= Arrays.asList(new FeatureSet[] {one, two});
62 - List<Record> source= Arrays.asList(new Record[] {a, b, x, y});
 66+ List<Record> source= Arrays.asList(new Record[] {a, a2, b, x, y});
6367
6468 DataCursor<Record> sourceCursor = new IteratorCursor<Record>(source.iterator());
6569 DataCursor<FeatureSet> cursor = FeatureAssemblingCursor.newForRecordCursor(sourceCursor, "id", "property", "value");
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureBuilderCursorTest.java
@@ -0,0 +1,88 @@
 2+package de.brightbyte.wikiword.integrator.data;
 3+
 4+import java.util.ArrayList;
 5+import java.util.Collection;
 6+
 7+import junit.framework.TestCase;
 8+import de.brightbyte.data.cursor.DataCursor;
 9+import de.brightbyte.data.cursor.IteratorCursor;
 10+import de.brightbyte.util.PersistenceException;
 11+
 12+public class FeatureBuilderCursorTest extends TestCase {
 13+
 14+ private static <T> Collection<T> slurp(DataCursor<T> cursor) throws PersistenceException {
 15+ ArrayList<T> list = new ArrayList<T>();
 16+ T obj;
 17+ while ((obj = cursor.next()) != null) list.add(obj);
 18+ return list;
 19+ }
 20+
 21+ public void testNext() throws PersistenceException {
 22+ DefaultRecord a = new DefaultRecord();
 23+ a.add("id", 1);
 24+ a.add("foo", "A");
 25+
 26+ DefaultRecord b = new DefaultRecord();
 27+ b.add("id", 1);
 28+ b.add("foo", "B");
 29+
 30+ DefaultRecord x = new DefaultRecord();
 31+ x.add("id", 2);
 32+ x.add("foo", "X");
 33+
 34+ DefaultRecord y = new DefaultRecord();
 35+ y.add("id", 2);
 36+ y.add("foo", "Y");
 37+
 38+ DefaultRecord p = new DefaultRecord();
 39+ p.add("id", 3);
 40+ p.add("foo", "P");
 41+
 42+ DefaultRecord q = new DefaultRecord();
 43+ q.add("id", 3);
 44+ q.add("foo", "Q");
 45+
 46+ //--------------------------------------
 47+ FeatureSet ab = new DefaultFeatureSet();
 48+ ab.addFeature("id", 1, null);
 49+ ab.addFeature("id", 1, null);
 50+ ab.addFeature("FOO", "A", null);
 51+ ab.addFeature("FOO", "B", null);
 52+
 53+ FeatureSet xy = new DefaultFeatureSet();
 54+ xy.addFeature("id", 2, null);
 55+ xy.addFeature("id", 2, null);
 56+ xy.addFeature("FOO", "X", null);
 57+ xy.addFeature("FOO", "Y", null);
 58+
 59+ FeatureSet pq = new DefaultFeatureSet();
 60+ pq.addFeature("id", 3, null);
 61+ pq.addFeature("id", 3, null);
 62+ pq.addFeature("FOO", "P", null);
 63+ pq.addFeature("FOO", "Q", null);
 64+
 65+ //--------------------------------------
 66+ ArrayList<Record> source = new ArrayList<Record>();
 67+ source.add(a);
 68+ source.add(b);
 69+ source.add(x);
 70+ source.add(y);
 71+ source.add(p);
 72+ source.add(q);
 73+
 74+ ArrayList<FeatureSet> exp = new ArrayList<FeatureSet>();
 75+ exp.add(ab);
 76+ exp.add(xy);
 77+ exp.add(pq);
 78+
 79+ FeatureBuilder<Record> mapping = new FeatureBuilder<Record>();
 80+ mapping.addMapping("id", new Record.Accessor<Integer>("id", Integer.class), null);
 81+ mapping.addMapping("FOO", new Record.Accessor<String>("foo", String.class), null); //TODO: califiers
 82+
 83+ DataCursor<Record> sourceCursor = new IteratorCursor<Record>(source.iterator());
 84+ DataCursor<FeatureSet> cursor = new FeatureBuilderCursor(sourceCursor, mapping, "id");
 85+
 86+ assertEquals(exp, slurp(cursor));
 87+ }
 88+
 89+}
Property changes on: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureBuilderCursorTest.java
___________________________________________________________________
Added: svn:mergeinfo
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FilteredMappingCandidateCursorTest.java
@@ -18,30 +18,32 @@
1919 }
2020
2121 public void testNext() throws PersistenceException {
22 - FeatureSet a = new DefaultFeatureSet("name");
23 - a.put("name", "A");
 22+ DefaultForeignEntityRecord a = new DefaultForeignEntityRecord("authority", "name", "name");
 23+ a.add("auhtority", "ACME");
 24+ a.add("name", "A");
2425
25 - FeatureSet b = new DefaultFeatureSet("name");
26 - b.put("name", "B");
 26+ DefaultForeignEntityRecord b = new DefaultForeignEntityRecord("authority", "name", "name");
 27+ b.add("auhtority", "ACME");
 28+ b.add("name", "B");
2729
28 - FeatureSet x = new DefaultFeatureSet("name");
29 - x.put("id", 10);
30 - x.put("value", 3);
31 - x.put("value", 3);
 30+ DefaultConceptEntityRecord x = new DefaultConceptEntityRecord("id", "name");
 31+ x.add("id", 10);
 32+ x.add("value", 3);
 33+ x.add("value", 3);
3234
33 - FeatureSet y = new DefaultFeatureSet("name");
34 - y.put("id", 11);
35 - y.put("value", 4);
36 - y.put("value", 1);
 35+ DefaultConceptEntityRecord y = new DefaultConceptEntityRecord("id", "name");
 36+ y.add("id", 11);
 37+ y.add("value", 4);
 38+ y.add("value", 1);
3739
38 - FeatureSet p = new DefaultFeatureSet("foo");
39 - p.put("id", 20);
40 - p.put("concept", "five");
41 - p.put("value", 3);
 40+ DefaultConceptEntityRecord p = new DefaultConceptEntityRecord("id", "name");
 41+ p.add("id", 20);
 42+ p.add("concept", "five");
 43+ p.add("value", 7);
4244
43 - FeatureSet q = new DefaultFeatureSet("foo");
44 - q.put("id", 21);
45 - q.put("value", 7);
 45+ DefaultConceptEntityRecord q = new DefaultConceptEntityRecord("id", "name");
 46+ q.add("id", 21);
 47+ q.add("value", 3);
4648
4749 //--------------------------------------
4850 ArrayList<MappingCandidates> source = new ArrayList<MappingCandidates>();
@@ -49,8 +51,8 @@
5052 source.add(new MappingCandidates(b, p, q));
5153
5254 ArrayList<MappingCandidates> exp = new ArrayList<MappingCandidates>();
53 - exp.add(new MappingCandidates(a, x));
54 - exp.add(new MappingCandidates(b, q));
 55+ exp.add(new MappingCandidates(a, y));
 56+ exp.add(new MappingCandidates(b, p));
5557
5658 DataCursor<MappingCandidates> sourceCursor = new IteratorCursor<MappingCandidates>(source.iterator());
5759 DataCursor<MappingCandidates> cursor = new FilteredMappingCandidateCursor(sourceCursor, "value");
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/MappingCandidateCursorTest.java
@@ -0,0 +1,67 @@
 2+package de.brightbyte.wikiword.integrator.data;
 3+
 4+import java.util.ArrayList;
 5+import java.util.Collection;
 6+
 7+import junit.framework.TestCase;
 8+import de.brightbyte.data.cursor.DataCursor;
 9+import de.brightbyte.data.cursor.IteratorCursor;
 10+import de.brightbyte.util.PersistenceException;
 11+
 12+public class MappingCandidateCursorTest extends TestCase {
 13+
 14+ private static <T> Collection<T> slurp(DataCursor<T> cursor) throws PersistenceException {
 15+ ArrayList<T> list = new ArrayList<T>();
 16+ T obj;
 17+ while ((obj = cursor.next()) != null) list.add(obj);
 18+ return list;
 19+ }
 20+
 21+ public void testNext() throws PersistenceException {
 22+ DefaultForeignEntityRecord a = new DefaultForeignEntityRecord("authority", "name", "name");
 23+ a.add("authority", "ACME");
 24+ a.add("name", "A");
 25+
 26+ DefaultForeignEntityRecord b = new DefaultForeignEntityRecord("authority", "name", "name");
 27+ b.add("authority", "ACME");
 28+ b.add("name", "B");
 29+
 30+ DefaultConceptEntityRecord x = new DefaultConceptEntityRecord("id", "name");
 31+ x.add("id", "11");
 32+ x.add("authority", "ACME");
 33+ x.add("name", "X");
 34+
 35+ DefaultConceptEntityRecord y = new DefaultConceptEntityRecord("id", "name");
 36+ y.add("id", "12");
 37+ y.add("authority", "ACME");
 38+ y.add("name", "Y");
 39+
 40+ DefaultRecord p = new DefaultRecord();
 41+ p.add("foo", "P");
 42+
 43+ DefaultRecord q = new DefaultRecord();
 44+ q.add("foo", "Q");
 45+
 46+ //--------------------------------------
 47+ ArrayList<Association> source = new ArrayList<Association>();
 48+ source.add(new GenericAssociation(a, x, p));
 49+ source.add(new GenericAssociation(a, y, p));
 50+ source.add(new GenericAssociation(a, y, q));
 51+ source.add(new GenericAssociation(b, y, q));
 52+ source.add(new GenericAssociation(a, y, q));
 53+
 54+ ArrayList<MappingCandidates> exp = new ArrayList<MappingCandidates>();
 55+ exp.add(new MappingCandidates(a, new DefaultConceptEntityRecord(new DefaultRecord(x, p), "id", "name"),
 56+ new DefaultConceptEntityRecord(new DefaultRecord(y, p), "id", "name"),
 57+ new DefaultConceptEntityRecord(new DefaultRecord(y, q), "id", "name")));
 58+ exp.add(new MappingCandidates(b, new DefaultConceptEntityRecord(new DefaultRecord(y, q), "id", "name")));
 59+ exp.add(new MappingCandidates(a, new DefaultConceptEntityRecord(new DefaultRecord(y, q), "id", "name")));
 60+
 61+ DataCursor<Association> sourceCursor = new IteratorCursor<Association>(source.iterator());
 62+ DataCursor<MappingCandidates> cursor = new MappingCandidateCursor(sourceCursor);
 63+
 64+ Collection<MappingCandidates> act = slurp(cursor);
 65+ assertEquals(exp, act);
 66+ }
 67+
 68+}
Property changes on: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/MappingCandidateCursorTest.java
___________________________________________________________________
Added: svn:mergeinfo
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/ConceptEntityRecord.java
@@ -1,4 +1,6 @@
22 package de.brightbyte.wikiword.integrator.data;
33
44 public interface ConceptEntityRecord extends Record, ConceptEntity {
 5+ public String getIDField();
 6+ public String getNameField();
57 }
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultForeignEntityRecord.java
@@ -8,50 +8,50 @@
99 public class DefaultForeignEntityRecord extends DefaultRecord implements ForeignEntityRecord{
1010
1111 public static class FromRecord implements Functor<DefaultForeignEntityRecord, Record> {
12 - protected String authorityId;
 12+ protected String authorityField;
1313 protected String idField;
1414 protected String nameField;
1515
16 - public FromRecord(String authorityId, String idField, String nameField) {
17 - if (authorityId==null) throw new NullPointerException();
 16+ public FromRecord(String authorityField, String idField, String nameField) {
 17+ if (authorityField==null) throw new NullPointerException();
1818 if (idField==null) throw new NullPointerException();
1919 if (nameField==null) nameField = idField;
2020 }
2121
2222 public DefaultForeignEntityRecord apply(Record rec) {
23 - return new DefaultForeignEntityRecord(rec, authorityId, idField, nameField);
 23+ return new DefaultForeignEntityRecord(rec, authorityField, idField, nameField);
2424 }
2525
2626 }
2727
28 - protected String authorityId;
 28+ protected String authorityField;
2929 protected String idField;
3030 protected String nameField;
3131
32 - public DefaultForeignEntityRecord(Map<String, Object> data, String authorityId, String idField, String nameField) {
 32+ public DefaultForeignEntityRecord(Map<String, Object> data, String authorityField, String idField, String nameField) {
3333 super(data);
3434
35 - if (authorityId==null) throw new NullPointerException();
 35+ if (authorityField==null) throw new NullPointerException();
3636 if (idField==null) throw new NullPointerException();
3737 if (nameField==null) nameField = idField;
3838
39 - this.authorityId = authorityId;
 39+ this.authorityField = authorityField;
4040 this.idField = idField;
4141 this.nameField = nameField;
4242 }
4343
44 - public DefaultForeignEntityRecord(Record rec, String authorityId, String idField, String nameField) {
45 - this(rec instanceof DefaultRecord ? ((DefaultRecord)rec).data : null, authorityId, idField, nameField);
 44+ public DefaultForeignEntityRecord(Record rec, String authorityField, String idField, String nameField) {
 45+ this(rec instanceof DefaultRecord ? ((DefaultRecord)rec).data : null, authorityField, idField, nameField);
4646 if (!(rec instanceof DefaultRecord)) addAll(data);
4747 }
4848
49 - protected DefaultForeignEntityRecord( String authorityId, String idField, String nameField) {
50 - this((Map<String, Object>)null, authorityId, idField, nameField);
 49+ protected DefaultForeignEntityRecord( String authorityField, String idField, String nameField) {
 50+ this((Map<String, Object>)null, authorityField, idField, nameField);
5151 addAll(data);
5252 }
5353
5454 public String getAuthority() {
55 - return authorityId;
 55+ return authorityField;
5656 }
5757
5858 public String getID() {
@@ -67,17 +67,13 @@
6868 return String.valueOf(v);
6969 }
7070
71 - public boolean add(String key, Object value) {
72 - throw new UnsupportedOperationException("foreign entity is unmodifiable");
73 - }
74 -
7571 @Override
7672 public int hashCode() {
7773 final int PRIME = 31;
7874 int result = super.hashCode();
79 - result = PRIME * result + ((authorityId == null) ? 0 : authorityId.hashCode());
80 - result = PRIME * result + ((idField == null) ? 0 : idField.hashCode());
81 - result = PRIME * result + ((nameField == null) ? 0 : nameField.hashCode());
 75+ result = PRIME * result + getID().hashCode();
 76+ result = PRIME * result + getAuthority().hashCode();
 77+ result = PRIME * result + ((getName() == null) ? 0 : getName().hashCode());
8278 return result;
8379 }
8480
@@ -87,25 +83,32 @@
8884 return true;
8985 if (obj == null)
9086 return false;
91 - if (getClass() != obj.getClass())
 87+ if (!(obj instanceof ForeignEntity))
9288 return false;
93 - final DefaultForeignEntityRecord other = (DefaultForeignEntityRecord) obj;
94 - if (authorityId == null) {
95 - if (other.authorityId != null)
96 - return false;
97 - } else if (!authorityId.equals(other.authorityId))
98 - return false;
99 - if (idField == null) {
100 - if (other.idField != null)
101 - return false;
102 - } else if (!idField.equals(other.idField))
103 - return false;
104 - if (nameField == null) {
105 - if (other.nameField != null)
106 - return false;
107 - } else if (!nameField.equals(other.nameField))
108 - return false;
109 - return super.equals(obj);
 89+
 90+ final ForeignEntity other = (ForeignEntity) obj;
 91+
 92+ if (!getAuthority().equals(other.getAuthority())) return false;
 93+ if (!getID().equals(other.getID())) return false;
 94+
 95+ if (getName()!=null && other.getName()!=null) {
 96+ if (!getName().equals(other.getName())) return false;
 97+ }
 98+
 99+ return true;
110100 }
111101
 102+ public String getAuthorityField() {
 103+ return authorityField;
 104+ }
 105+
 106+ public String getIDField() {
 107+ return idField;
 108+ }
 109+
 110+ public String getNameField() {
 111+ return nameField;
 112+ }
 113+
 114+
112115 }
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/Record.java
@@ -1,11 +1,20 @@
22 package de.brightbyte.wikiword.integrator.data;
33
 4+import java.util.Collection;
 5+import java.util.Collections;
 6+import java.util.List;
 7+import java.util.Set;
 8+
49 import de.brightbyte.abstraction.AbstractAccessor;
 10+import de.brightbyte.data.Aggregator;
 11+import de.brightbyte.data.StrictAggregator;
 12+import de.brightbyte.data.Functors;
513 import de.brightbyte.db.DatabaseUtil;
614
715 public interface Record extends Cloneable {
8 -
 16+
917 public static class Accessor<V> extends AbstractAccessor<Record, V> {
 18+
1019
1120 public Accessor(String property, Class<V> type) {
1221 super(property, type);
@@ -13,9 +22,30 @@
1423
1524 public V getValue(Record obj) {
1625 Object v = obj.get(property);
17 - return (V)DatabaseUtil.as(v, getType());
 26+ Class t = getType();
 27+
 28+ if (Collection.class.isAssignableFrom(t)) {
 29+ if (!(v instanceof Collection)) {
 30+ if (t.isAssignableFrom(Set.class)) v = Collections.singleton(v);
 31+ else if (t.isAssignableFrom(List.class)) v = Collections.singletonList(v);
 32+ else ; //TODO...
 33+ } ; //TODO...
 34+ }
 35+ else {
 36+ if (v instanceof Collection) {
 37+ v = collapseValue((Collection)v);
 38+ }
 39+
 40+ v = DatabaseUtil.as(v, getType());
 41+ }
 42+
 43+ return (V)v;
1844 }
1945
 46+ protected V collapseValue(Collection collection) {
 47+ return (V)Functors.firstElement().apply((Collection<V>)collection);
 48+ }
 49+
2050 public boolean isMutable() {
2151 return true;
2252 }
@@ -25,6 +55,20 @@
2656 }
2757
2858 }
 59+
 60+ public static class AggregatingAccessor<U, V extends U> extends Accessor<V> {
 61+ protected Aggregator<U, V> aggregator;
 62+
 63+ public AggregatingAccessor(String property, Class<V> type, Aggregator<U, V> aggregator) {
 64+ super(property, type);
 65+ this.aggregator = aggregator;
 66+ }
 67+
 68+ protected V collapseValue(Collection collection) {
 69+ if (aggregator!=null) return aggregator.apply(collection);
 70+ else return (V)Functors.firstElement().apply(collection);
 71+ }
 72+ }
2973
3074 public Object set(String key, Object value);
3175 public boolean add(String key, Object value);
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultAssociation.java
@@ -32,7 +32,7 @@
3333 if (foreignIdField==null) throw new NullPointerException();
3434 if (conceptIdField==null) throw new NullPointerException();
3535 if (foreignNameField==null) foreignNameField = foreignIdField;
36 - if (conceptNameField==null) conceptNameField = conceptNameField;
 36+ if (conceptNameField==null) conceptNameField = conceptIdField;
3737
3838 this.data = data;
3939 this.foreignAuthorityField = foreignAuthorityField;
@@ -47,6 +47,15 @@
4848 conceptEntity = new DefaultConceptEntityRecord(this.data, conceptIdField, conceptNameField);
4949 }
5050
 51+ public DefaultAssociation(Association assoc) {
 52+ this(new DefaultRecord(assoc.getForeignEntity(), assoc.getConceptEntity(), assoc.getQualifiers()),
 53+ assoc.getForeignEntity().getAuthorityField(),
 54+ assoc.getForeignEntity().getIDField(),
 55+ assoc.getForeignEntity().getNameField(),
 56+ assoc.getConceptEntity().getIDField(),
 57+ assoc.getConceptEntity().getNameField());
 58+ }
 59+
5160 public ConceptEntityRecord getConceptEntity() {
5261 return conceptEntity;
5362 }
@@ -75,38 +84,65 @@
7685 }
7786 }
7887
79 - public void aggregate(DefaultAssociation add, Map<String, Accumulator<?, ?>> accumulators) {
 88+ public void aggregate(Association other, Map<String, Accumulator<?, ?>> accumulators) {
 89+ if (other instanceof DefaultAssociation) {
8090 for (Map.Entry<String, Accumulator<?, ?>> e: accumulators.entrySet()) {
8191 String field = e.getKey();
82 - Accumulator<Object, Object> accumulator = (Accumulator<Object, Object>)e.getValue(); //XXX: unsafe case
 92+ Accumulator<Object, Object> accumulator = (Accumulator<Object, Object>)e.getValue(); //XXX: unsafe cast
 93+ Object b = ((DefaultAssociation)other).data.get(field);
8394
84 - Object a = data.get(field);
85 - Object b = add.data.get(field);
86 - Object v = null;
87 - Collection c = null;
88 -
89 - if (a==null) v = b;
90 - else if (b==null) v = a;
91 - else {
92 - //deal with multi-value fields
93 - if (a instanceof Collection) {
94 - if (b instanceof Collection) {
95 - ((Collection)a).addAll((Collection)b);
96 - } else {
97 - ((Collection)a).add(b);
98 - }
99 - c = (Collection)a;
100 - } else if (b instanceof Collection) {
101 - c = new ArrayList();
102 - c.addAll((Collection)b);
103 - c.add(a);
 95+ margeValue(field, b, accumulator);
 96+ }
 97+ } else {
 98+ margeValues(other.getForeignEntity(), accumulators);
 99+ margeValues(other.getConceptEntity(), accumulators);
 100+ margeValues(other.getQualifiers(), accumulators);
 101+ }
 102+ }
 103+
 104+ protected void margeValues(Record rec, Map<String, Accumulator<?, ?>> accumulators) {
 105+ for (String field: rec.keys()) {
 106+ if (!accumulators.containsKey(field)) continue;
 107+ Accumulator<Object, Object> accumulator = (Accumulator<Object, Object>)accumulators.get(field); //XXX: unsafe cast
 108+
 109+ Object b = rec.get(field);
 110+ margeValue(field, b, accumulator);
 111+ }
 112+ }
 113+
 114+ protected void margeValue(String field, Object b, Accumulator<Object, Object> accumulator) {
 115+ Object a = data.get(field);
 116+ Object v = null;
 117+ Collection c = null;
 118+
 119+ if (a==null) v = b;
 120+ else if (b==null) v = a;
 121+ else {
 122+ //deal with multi-value fields
 123+ if (a instanceof Collection) {
 124+ if (b instanceof Collection) {
 125+ ((Collection)a).addAll((Collection)b);
104126 } else {
105 - v = accumulator.apply(a, b); //XXX: unsafe type assumption in apply. not sure accumulator matches object type
 127+ ((Collection)a).add(b);
106128 }
 129+ c = (Collection)a;
 130+ } else if (b instanceof Collection) {
 131+ c = new ArrayList();
 132+ c.addAll((Collection)b);
 133+ c.add(a);
 134+ } else if (accumulator == null) {
 135+ c = new ArrayList();
 136+ c.add(a);
 137+ c.add(b);
 138+ } else {
 139+ v = accumulator.apply(a, b); //XXX: unsafe type assumption in apply. not sure accumulator matches object type
107140 }
108 -
109 - if (c!=null) { //if we have a collectiopn, aggregate
110 - if (c.isEmpty()) return;
 141+ }
 142+
 143+ if (c!=null) { //if we have a collectiopn, aggregate
 144+ if (c.isEmpty()) return;
 145+ if (accumulator == null) v = c;
 146+ else {
111147 v = null;
112148
113149 for (Object x: c) {
@@ -115,24 +151,19 @@
116152 v = accumulator.apply(v, x);
117153 }
118154 }
119 - }
120 -
121 - data.set(field, v);
122 - }
 155+ }
 156+ }
 157+
 158+ data.set(field, v);
123159 }
124 -
 160+
125161 @Override
126162 public int hashCode() {
127163 final int PRIME = 31;
128164 int result = 1;
129 - result = PRIME * result + ((conceptEntity == null) ? 0 : conceptEntity.hashCode());
130 - result = PRIME * result + ((conceptIdField == null) ? 0 : conceptIdField.hashCode());
131 - result = PRIME * result + ((conceptNameField == null) ? 0 : conceptNameField.hashCode());
132 - result = PRIME * result + ((data == null) ? 0 : data.hashCode());
133 - result = PRIME * result + ((foreignAuthorityField == null) ? 0 : foreignAuthorityField.hashCode());
134 - result = PRIME * result + ((foreignEntity == null) ? 0 : foreignEntity.hashCode());
135 - result = PRIME * result + ((foreignIdField == null) ? 0 : foreignIdField.hashCode());
136 - result = PRIME * result + ((foreignNameField == null) ? 0 : foreignNameField.hashCode());
 165+ result = PRIME * result + getForeignEntity().hashCode();
 166+ result = PRIME * result + getConceptEntity().hashCode();
 167+ result = PRIME * result + getQualifiers().hashCode();
137168 return result;
138169 }
139170
@@ -142,49 +173,14 @@
143174 return true;
144175 if (obj == null)
145176 return false;
146 - if (getClass() != obj.getClass())
 177+ if (! (obj instanceof Association))
147178 return false;
148 - final DefaultAssociation other = (DefaultAssociation) obj;
149 - if (conceptEntity == null) {
150 - if (other.conceptEntity != null)
151 - return false;
152 - } else if (!conceptEntity.equals(other.conceptEntity))
153 - return false;
154 - if (conceptIdField == null) {
155 - if (other.conceptIdField != null)
156 - return false;
157 - } else if (!conceptIdField.equals(other.conceptIdField))
158 - return false;
159 - if (conceptNameField == null) {
160 - if (other.conceptNameField != null)
161 - return false;
162 - } else if (!conceptNameField.equals(other.conceptNameField))
163 - return false;
164 - if (data == null) {
165 - if (other.data != null)
166 - return false;
167 - } else if (!data.equals(other.data))
168 - return false;
169 - if (foreignAuthorityField == null) {
170 - if (other.foreignAuthorityField != null)
171 - return false;
172 - } else if (!foreignAuthorityField.equals(other.foreignAuthorityField))
173 - return false;
174 - if (foreignEntity == null) {
175 - if (other.foreignEntity != null)
176 - return false;
177 - } else if (!foreignEntity.equals(other.foreignEntity))
178 - return false;
179 - if (foreignIdField == null) {
180 - if (other.foreignIdField != null)
181 - return false;
182 - } else if (!foreignIdField.equals(other.foreignIdField))
183 - return false;
184 - if (foreignNameField == null) {
185 - if (other.foreignNameField != null)
186 - return false;
187 - } else if (!foreignNameField.equals(other.foreignNameField))
188 - return false;
 179+ final Association other = (Association) obj;
 180+
 181+ if (!getForeignEntity().equals(other.getForeignEntity())) return false;
 182+ if (!getConceptEntity().equals(other.getConceptEntity())) return false;
 183+ if (!getQualifiers().equals(other.getQualifiers())) return false;
 184+
189185 return true;
190186 }
191187
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultRecord.java
@@ -12,13 +12,29 @@
1313 private static final long serialVersionUID = 5538610907302985392L;
1414
1515 protected Map<String, Object> data;
 16+
 17+ private boolean unmodifiable;
1618
1719 public DefaultRecord() {
18 - this(null);
 20+ this((Map<String, Object>)null);
1921 }
 22+
 23+ public DefaultRecord(Record... data) {
 24+ this();
 25+
 26+ for (Record r: data) {
 27+ addAll(r);
 28+ }
 29+ }
2030
2131 protected DefaultRecord(Map<String, Object> data) {
22 - if (data==null) data = new HashMap<String, Object>();
 32+ if (data==null) {
 33+ data = new HashMap<String, Object>();
 34+ unmodifiable = false;
 35+ } else {
 36+ unmodifiable = true;
 37+ }
 38+
2339 this.data = data;
2440 }
2541
@@ -39,6 +55,8 @@
4056 }
4157
4258 public boolean add(String key, Object value, boolean allowDupes) {
 59+ if (unmodifiable) throw new UnsupportedOperationException("derived record is unmodifiable");
 60+
4361 Object old = data.get(key);
4462
4563 if (value instanceof Object[]) {
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/ForeignEntityRecord.java
@@ -1,4 +1,7 @@
22 package de.brightbyte.wikiword.integrator.data;
33
44 public interface ForeignEntityRecord extends Record, ForeignEntity {
 5+ public String getAuthorityField();
 6+ public String getIDField();
 7+ public String getNameField();
58 }
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/MappingCandidateCursor.java
@@ -33,7 +33,8 @@
3434 prev = cursor.next();
3535 if (prev==null) break;
3636
37 - if (prev.getForeignEntity().getID().equals( fe.getID())) break;
 37+ if (!prev.getForeignEntity().getAuthority().equals( fe.getAuthority())) break;
 38+ if (!prev.getForeignEntity().getID().equals( fe.getID())) break;
3839
3940 candidates.add(prev.getConceptEntity());
4041 }
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultConceptEntityRecord.java
@@ -62,16 +62,12 @@
6363 return DatabaseUtil.asString(v);
6464 }
6565
66 - public boolean add(String key, Object value) {
67 - throw new UnsupportedOperationException("concept entity is unmodifiable");
68 - }
69 -
7066 @Override
7167 public int hashCode() {
7268 final int PRIME = 31;
7369 int result = super.hashCode();
74 - result = PRIME * result + ((idField == null) ? 0 : idField.hashCode());
75 - result = PRIME * result + ((nameField == null) ? 0 : nameField.hashCode());
 70+ result = PRIME * result + getID();
 71+ result = PRIME * result + ((getName() == null) ? 0 : getName().hashCode());
7672 return result;
7773 }
7874
@@ -81,20 +77,26 @@
8278 return true;
8379 if (obj == null)
8480 return false;
85 - if (getClass() != obj.getClass())
 81+ if (!(obj instanceof ConceptEntity))
8682 return false;
87 - final DefaultConceptEntityRecord other = (DefaultConceptEntityRecord) obj;
88 - if (idField == null) {
89 - if (other.idField != null)
90 - return false;
91 - } else if (!idField.equals(other.idField))
92 - return false;
93 - if (nameField == null) {
94 - if (other.nameField != null)
95 - return false;
96 - } else if (!nameField.equals(other.nameField))
97 - return false;
98 - return super.equals(obj);
 83+
 84+ final ConceptEntity other = (ConceptEntity) obj;
 85+
 86+ if (getID()!=other.getID()) return false;
 87+
 88+ if (getName()!=null && other.getName()!=null) {
 89+ if (!getName().equals(other.getName())) return false;
 90+ }
 91+
 92+ return true;
9993 }
10094
 95+ public String getIDField() {
 96+ return idField;
 97+ }
 98+
 99+ public String getNameField() {
 100+ return nameField;
 101+ }
 102+
101103 }
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/FilteredMappingCandidateCursor.java
@@ -3,6 +3,7 @@
44 import java.util.Collection;
55
66 import de.brightbyte.abstraction.PropertyAccessor;
 7+import de.brightbyte.data.Functors;
78 import de.brightbyte.data.cursor.DataCursor;
89 import de.brightbyte.util.PersistenceException;
910 import de.brightbyte.wikiword.integrator.data.filter.BestMappingCandidateSelector;
@@ -19,11 +20,11 @@
2021 protected MappingCandidateFilter filter;
2122
2223 public FilteredMappingCandidateCursor(DataCursor<MappingCandidates> cursor, String field) {
23 - this(cursor, new Record.Accessor<Integer>(field, Integer.class));
 24+ this(cursor, new Record.AggregatingAccessor<Number, Double>(field, Double.class, Functors.Double.max));
2425 }
2526
2627 public FilteredMappingCandidateCursor(DataCursor<MappingCandidates> cursor, String field, int threshold) {
27 - this(cursor, new Record.Accessor<Integer>(field, Integer.class), threshold);
 28+ this(cursor, new Record.AggregatingAccessor<Number, Double>(field, Double.class, Functors.Double.max), threshold);
2829 }
2930
3031 public FilteredMappingCandidateCursor(DataCursor<MappingCandidates> cursor, PropertyAccessor<Record, ? extends Number> accessor) {
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/FeatureSet.java
@@ -4,7 +4,7 @@
55
66 import de.brightbyte.abstraction.AbstractAccessor;
77 import de.brightbyte.abstraction.PropertyAccessor;
8 -import de.brightbyte.data.Aggregator;
 8+import de.brightbyte.data.StrictAggregator;
99 import de.brightbyte.data.LabeledVector;
1010
1111 public interface FeatureSet {
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/GenericAssociation.java
@@ -40,4 +40,33 @@
4141 throw new Error("CloneNotSupported in clonable object");
4242 }
4343 }
 44+
 45+ @Override
 46+ public int hashCode() {
 47+ final int PRIME = 31;
 48+ int result = 1;
 49+ result = PRIME * result + getForeignEntity().hashCode();
 50+ result = PRIME * result + getConceptEntity().hashCode();
 51+ result = PRIME * result + getQualifiers().hashCode();
 52+ return result;
 53+ }
 54+
 55+ @Override
 56+ public boolean equals(Object obj) {
 57+ if (this == obj)
 58+ return true;
 59+ if (obj == null)
 60+ return false;
 61+ if (! (obj instanceof Association))
 62+ return false;
 63+ final Association other = (Association) obj;
 64+
 65+ if (!getForeignEntity().equals(other.getForeignEntity())) return false;
 66+ if (!getConceptEntity().equals(other.getConceptEntity())) return false;
 67+ if (!getQualifiers().equals(other.getQualifiers())) return false;
 68+
 69+ return true;
 70+ }
 71+
 72+
4473 }
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/AggregatingAssociationCursor.java
@@ -32,7 +32,7 @@
3333 if (prev==null) prev = cursor.next();
3434 if (prev==null) return null;
3535
36 - Association a = prev.clone();
 36+ DefaultAssociation a = new DefaultAssociation(prev);
3737
3838 while (true) {
3939 prev = cursor.next();
@@ -42,7 +42,7 @@
4343 if (!prev.getForeignEntity().getAuthority().equals( a.getForeignEntity().getAuthority())) break;
4444 if (!prev.getForeignEntity().getID().equals( a.getForeignEntity().getID())) break;
4545
46 - ((DefaultAssociation)a).aggregate((DefaultAssociation)prev, accumulators);
 46+ ((DefaultAssociation)a).aggregate(prev, accumulators);
4747 }
4848
4949 return a;

Status & tagging log