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 @@ |
56 | 56 | source.add(new GenericAssociation(a, x, p)); |
57 | 57 | source.add(new GenericAssociation(a, y, p)); |
58 | 58 | 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")); |
60 | 60 | source.add(new GenericAssociation(a, y, q)); |
61 | 61 | |
62 | 62 | 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))); |
67 | 67 | |
68 | 68 | 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! |
70 | 71 | |
71 | | - assertEquals(exp, slurp(cursor)); |
| 72 | + Collection<Association> act = slurp(cursor); |
| 73 | + assertEquals(exp, act); |
72 | 74 | } |
73 | 75 | |
74 | 76 | } |
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureAssemblingCursorTest.java |
— | — | @@ -24,14 +24,18 @@ |
25 | 25 | a.add("id", 1); |
26 | 26 | a.add("property", "name"); |
27 | 27 | a.add("value", "A"); |
28 | | - a.add("value", "a"); |
29 | 28 | a.add("xyzzy", "bla"); |
30 | 29 | |
| 30 | + DefaultRecord a2 = new DefaultRecord(); |
| 31 | + a2.add("id", 1); |
| 32 | + a2.add("property", "name"); |
| 33 | + a2.add("value", "a"); |
| 34 | + |
31 | 35 | DefaultRecord b = new DefaultRecord(); |
32 | 36 | b.add("id", 1); |
33 | 37 | b.add("property", "foo"); |
34 | 38 | b.add("value", "X"); |
35 | | - b.add("value", "Y"); |
| 39 | + //b.add("value", "Y"); //NOTE: multi-value records are not supported in this context! |
36 | 40 | |
37 | 41 | DefaultRecord x = new DefaultRecord(); |
38 | 42 | x.add("id", 2); |
— | — | @@ -50,7 +54,7 @@ |
51 | 55 | one.addFeature("name", "A", null); |
52 | 56 | one.addFeature("name", "a", null); |
53 | 57 | one.addFeature("foo", "X", null); |
54 | | - one.addFeature("foo", "Y", null); |
| 58 | + //one.addFeature("foo", "Y", null); |
55 | 59 | |
56 | 60 | DefaultFeatureSet two = new DefaultFeatureSet(); |
57 | 61 | two.addFeature("id", 2, null); |
— | — | @@ -58,7 +62,7 @@ |
59 | 63 | two.addFeature("alias", "Foo", null); |
60 | 64 | |
61 | 65 | 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}); |
63 | 67 | |
64 | 68 | DataCursor<Record> sourceCursor = new IteratorCursor<Record>(source.iterator()); |
65 | 69 | 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 @@ |
19 | 19 | } |
20 | 20 | |
21 | 21 | 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"); |
24 | 25 | |
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"); |
27 | 29 | |
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); |
32 | 34 | |
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); |
37 | 39 | |
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); |
42 | 44 | |
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); |
46 | 48 | |
47 | 49 | //-------------------------------------- |
48 | 50 | ArrayList<MappingCandidates> source = new ArrayList<MappingCandidates>(); |
— | — | @@ -49,8 +51,8 @@ |
50 | 52 | source.add(new MappingCandidates(b, p, q)); |
51 | 53 | |
52 | 54 | 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)); |
55 | 57 | |
56 | 58 | DataCursor<MappingCandidates> sourceCursor = new IteratorCursor<MappingCandidates>(source.iterator()); |
57 | 59 | 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 @@ |
2 | 2 | package de.brightbyte.wikiword.integrator.data; |
3 | 3 | |
4 | 4 | public interface ConceptEntityRecord extends Record, ConceptEntity { |
| 5 | + public String getIDField(); |
| 6 | + public String getNameField(); |
5 | 7 | } |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultForeignEntityRecord.java |
— | — | @@ -8,50 +8,50 @@ |
9 | 9 | public class DefaultForeignEntityRecord extends DefaultRecord implements ForeignEntityRecord{ |
10 | 10 | |
11 | 11 | public static class FromRecord implements Functor<DefaultForeignEntityRecord, Record> { |
12 | | - protected String authorityId; |
| 12 | + protected String authorityField; |
13 | 13 | protected String idField; |
14 | 14 | protected String nameField; |
15 | 15 | |
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(); |
18 | 18 | if (idField==null) throw new NullPointerException(); |
19 | 19 | if (nameField==null) nameField = idField; |
20 | 20 | } |
21 | 21 | |
22 | 22 | public DefaultForeignEntityRecord apply(Record rec) { |
23 | | - return new DefaultForeignEntityRecord(rec, authorityId, idField, nameField); |
| 23 | + return new DefaultForeignEntityRecord(rec, authorityField, idField, nameField); |
24 | 24 | } |
25 | 25 | |
26 | 26 | } |
27 | 27 | |
28 | | - protected String authorityId; |
| 28 | + protected String authorityField; |
29 | 29 | protected String idField; |
30 | 30 | protected String nameField; |
31 | 31 | |
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) { |
33 | 33 | super(data); |
34 | 34 | |
35 | | - if (authorityId==null) throw new NullPointerException(); |
| 35 | + if (authorityField==null) throw new NullPointerException(); |
36 | 36 | if (idField==null) throw new NullPointerException(); |
37 | 37 | if (nameField==null) nameField = idField; |
38 | 38 | |
39 | | - this.authorityId = authorityId; |
| 39 | + this.authorityField = authorityField; |
40 | 40 | this.idField = idField; |
41 | 41 | this.nameField = nameField; |
42 | 42 | } |
43 | 43 | |
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); |
46 | 46 | if (!(rec instanceof DefaultRecord)) addAll(data); |
47 | 47 | } |
48 | 48 | |
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); |
51 | 51 | addAll(data); |
52 | 52 | } |
53 | 53 | |
54 | 54 | public String getAuthority() { |
55 | | - return authorityId; |
| 55 | + return authorityField; |
56 | 56 | } |
57 | 57 | |
58 | 58 | public String getID() { |
— | — | @@ -67,17 +67,13 @@ |
68 | 68 | return String.valueOf(v); |
69 | 69 | } |
70 | 70 | |
71 | | - public boolean add(String key, Object value) { |
72 | | - throw new UnsupportedOperationException("foreign entity is unmodifiable"); |
73 | | - } |
74 | | - |
75 | 71 | @Override |
76 | 72 | public int hashCode() { |
77 | 73 | final int PRIME = 31; |
78 | 74 | 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()); |
82 | 78 | return result; |
83 | 79 | } |
84 | 80 | |
— | — | @@ -87,25 +83,32 @@ |
88 | 84 | return true; |
89 | 85 | if (obj == null) |
90 | 86 | return false; |
91 | | - if (getClass() != obj.getClass()) |
| 87 | + if (!(obj instanceof ForeignEntity)) |
92 | 88 | 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; |
110 | 100 | } |
111 | 101 | |
| 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 | + |
112 | 115 | } |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/Record.java |
— | — | @@ -1,11 +1,20 @@ |
2 | 2 | package de.brightbyte.wikiword.integrator.data; |
3 | 3 | |
| 4 | +import java.util.Collection; |
| 5 | +import java.util.Collections; |
| 6 | +import java.util.List; |
| 7 | +import java.util.Set; |
| 8 | + |
4 | 9 | import de.brightbyte.abstraction.AbstractAccessor; |
| 10 | +import de.brightbyte.data.Aggregator; |
| 11 | +import de.brightbyte.data.StrictAggregator; |
| 12 | +import de.brightbyte.data.Functors; |
5 | 13 | import de.brightbyte.db.DatabaseUtil; |
6 | 14 | |
7 | 15 | public interface Record extends Cloneable { |
8 | | - |
| 16 | + |
9 | 17 | public static class Accessor<V> extends AbstractAccessor<Record, V> { |
| 18 | + |
10 | 19 | |
11 | 20 | public Accessor(String property, Class<V> type) { |
12 | 21 | super(property, type); |
— | — | @@ -13,9 +22,30 @@ |
14 | 23 | |
15 | 24 | public V getValue(Record obj) { |
16 | 25 | 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; |
18 | 44 | } |
19 | 45 | |
| 46 | + protected V collapseValue(Collection collection) { |
| 47 | + return (V)Functors.firstElement().apply((Collection<V>)collection); |
| 48 | + } |
| 49 | + |
20 | 50 | public boolean isMutable() { |
21 | 51 | return true; |
22 | 52 | } |
— | — | @@ -25,6 +55,20 @@ |
26 | 56 | } |
27 | 57 | |
28 | 58 | } |
| 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 | + } |
29 | 73 | |
30 | 74 | public Object set(String key, Object value); |
31 | 75 | 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 @@ |
33 | 33 | if (foreignIdField==null) throw new NullPointerException(); |
34 | 34 | if (conceptIdField==null) throw new NullPointerException(); |
35 | 35 | if (foreignNameField==null) foreignNameField = foreignIdField; |
36 | | - if (conceptNameField==null) conceptNameField = conceptNameField; |
| 36 | + if (conceptNameField==null) conceptNameField = conceptIdField; |
37 | 37 | |
38 | 38 | this.data = data; |
39 | 39 | this.foreignAuthorityField = foreignAuthorityField; |
— | — | @@ -47,6 +47,15 @@ |
48 | 48 | conceptEntity = new DefaultConceptEntityRecord(this.data, conceptIdField, conceptNameField); |
49 | 49 | } |
50 | 50 | |
| 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 | + |
51 | 60 | public ConceptEntityRecord getConceptEntity() { |
52 | 61 | return conceptEntity; |
53 | 62 | } |
— | — | @@ -75,38 +84,65 @@ |
76 | 85 | } |
77 | 86 | } |
78 | 87 | |
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) { |
80 | 90 | for (Map.Entry<String, Accumulator<?, ?>> e: accumulators.entrySet()) { |
81 | 91 | 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); |
83 | 94 | |
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); |
104 | 126 | } else { |
105 | | - v = accumulator.apply(a, b); //XXX: unsafe type assumption in apply. not sure accumulator matches object type |
| 127 | + ((Collection)a).add(b); |
106 | 128 | } |
| 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 |
107 | 140 | } |
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 { |
111 | 147 | v = null; |
112 | 148 | |
113 | 149 | for (Object x: c) { |
— | — | @@ -115,24 +151,19 @@ |
116 | 152 | v = accumulator.apply(v, x); |
117 | 153 | } |
118 | 154 | } |
119 | | - } |
120 | | - |
121 | | - data.set(field, v); |
122 | | - } |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + data.set(field, v); |
123 | 159 | } |
124 | | - |
| 160 | + |
125 | 161 | @Override |
126 | 162 | public int hashCode() { |
127 | 163 | final int PRIME = 31; |
128 | 164 | 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(); |
137 | 168 | return result; |
138 | 169 | } |
139 | 170 | |
— | — | @@ -142,49 +173,14 @@ |
143 | 174 | return true; |
144 | 175 | if (obj == null) |
145 | 176 | return false; |
146 | | - if (getClass() != obj.getClass()) |
| 177 | + if (! (obj instanceof Association)) |
147 | 178 | 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 | + |
189 | 185 | return true; |
190 | 186 | } |
191 | 187 | |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultRecord.java |
— | — | @@ -12,13 +12,29 @@ |
13 | 13 | private static final long serialVersionUID = 5538610907302985392L; |
14 | 14 | |
15 | 15 | protected Map<String, Object> data; |
| 16 | + |
| 17 | + private boolean unmodifiable; |
16 | 18 | |
17 | 19 | public DefaultRecord() { |
18 | | - this(null); |
| 20 | + this((Map<String, Object>)null); |
19 | 21 | } |
| 22 | + |
| 23 | + public DefaultRecord(Record... data) { |
| 24 | + this(); |
| 25 | + |
| 26 | + for (Record r: data) { |
| 27 | + addAll(r); |
| 28 | + } |
| 29 | + } |
20 | 30 | |
21 | 31 | 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 | + |
23 | 39 | this.data = data; |
24 | 40 | } |
25 | 41 | |
— | — | @@ -39,6 +55,8 @@ |
40 | 56 | } |
41 | 57 | |
42 | 58 | public boolean add(String key, Object value, boolean allowDupes) { |
| 59 | + if (unmodifiable) throw new UnsupportedOperationException("derived record is unmodifiable"); |
| 60 | + |
43 | 61 | Object old = data.get(key); |
44 | 62 | |
45 | 63 | if (value instanceof Object[]) { |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/ForeignEntityRecord.java |
— | — | @@ -1,4 +1,7 @@ |
2 | 2 | package de.brightbyte.wikiword.integrator.data; |
3 | 3 | |
4 | 4 | public interface ForeignEntityRecord extends Record, ForeignEntity { |
| 5 | + public String getAuthorityField(); |
| 6 | + public String getIDField(); |
| 7 | + public String getNameField(); |
5 | 8 | } |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/MappingCandidateCursor.java |
— | — | @@ -33,7 +33,8 @@ |
34 | 34 | prev = cursor.next(); |
35 | 35 | if (prev==null) break; |
36 | 36 | |
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; |
38 | 39 | |
39 | 40 | candidates.add(prev.getConceptEntity()); |
40 | 41 | } |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultConceptEntityRecord.java |
— | — | @@ -62,16 +62,12 @@ |
63 | 63 | return DatabaseUtil.asString(v); |
64 | 64 | } |
65 | 65 | |
66 | | - public boolean add(String key, Object value) { |
67 | | - throw new UnsupportedOperationException("concept entity is unmodifiable"); |
68 | | - } |
69 | | - |
70 | 66 | @Override |
71 | 67 | public int hashCode() { |
72 | 68 | final int PRIME = 31; |
73 | 69 | 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()); |
76 | 72 | return result; |
77 | 73 | } |
78 | 74 | |
— | — | @@ -81,20 +77,26 @@ |
82 | 78 | return true; |
83 | 79 | if (obj == null) |
84 | 80 | return false; |
85 | | - if (getClass() != obj.getClass()) |
| 81 | + if (!(obj instanceof ConceptEntity)) |
86 | 82 | 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; |
99 | 93 | } |
100 | 94 | |
| 95 | + public String getIDField() { |
| 96 | + return idField; |
| 97 | + } |
| 98 | + |
| 99 | + public String getNameField() { |
| 100 | + return nameField; |
| 101 | + } |
| 102 | + |
101 | 103 | } |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/FilteredMappingCandidateCursor.java |
— | — | @@ -3,6 +3,7 @@ |
4 | 4 | import java.util.Collection; |
5 | 5 | |
6 | 6 | import de.brightbyte.abstraction.PropertyAccessor; |
| 7 | +import de.brightbyte.data.Functors; |
7 | 8 | import de.brightbyte.data.cursor.DataCursor; |
8 | 9 | import de.brightbyte.util.PersistenceException; |
9 | 10 | import de.brightbyte.wikiword.integrator.data.filter.BestMappingCandidateSelector; |
— | — | @@ -19,11 +20,11 @@ |
20 | 21 | protected MappingCandidateFilter filter; |
21 | 22 | |
22 | 23 | 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)); |
24 | 25 | } |
25 | 26 | |
26 | 27 | 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); |
28 | 29 | } |
29 | 30 | |
30 | 31 | 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 @@ |
5 | 5 | |
6 | 6 | import de.brightbyte.abstraction.AbstractAccessor; |
7 | 7 | import de.brightbyte.abstraction.PropertyAccessor; |
8 | | -import de.brightbyte.data.Aggregator; |
| 8 | +import de.brightbyte.data.StrictAggregator; |
9 | 9 | import de.brightbyte.data.LabeledVector; |
10 | 10 | |
11 | 11 | public interface FeatureSet { |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/GenericAssociation.java |
— | — | @@ -40,4 +40,33 @@ |
41 | 41 | throw new Error("CloneNotSupported in clonable object"); |
42 | 42 | } |
43 | 43 | } |
| 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 | + |
44 | 73 | } |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/AggregatingAssociationCursor.java |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | if (prev==null) prev = cursor.next(); |
34 | 34 | if (prev==null) return null; |
35 | 35 | |
36 | | - Association a = prev.clone(); |
| 36 | + DefaultAssociation a = new DefaultAssociation(prev); |
37 | 37 | |
38 | 38 | while (true) { |
39 | 39 | prev = cursor.next(); |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | if (!prev.getForeignEntity().getAuthority().equals( a.getForeignEntity().getAuthority())) break; |
44 | 44 | if (!prev.getForeignEntity().getID().equals( a.getForeignEntity().getID())) break; |
45 | 45 | |
46 | | - ((DefaultAssociation)a).aggregate((DefaultAssociation)prev, accumulators); |
| 46 | + ((DefaultAssociation)a).aggregate(prev, accumulators); |
47 | 47 | } |
48 | 48 | |
49 | 49 | return a; |