Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultFeatureSet.java |
— | — | @@ -18,6 +18,10 @@ |
19 | 19 | this.qualifiers = qualifiers; |
20 | 20 | } |
21 | 21 | |
| 22 | + public String toString() { |
| 23 | + return String.valueOf(value); |
| 24 | + } |
| 25 | + |
22 | 26 | @Override |
23 | 27 | public int hashCode() { |
24 | 28 | final int PRIME = 31; |
— | — | @@ -114,6 +118,31 @@ |
115 | 119 | public Iterable<String> keys() { |
116 | 120 | return data.keySet(); |
117 | 121 | } |
| 122 | + |
| 123 | + @Override |
| 124 | + public int hashCode() { |
| 125 | + final int PRIME = 31; |
| 126 | + int result = 1; |
| 127 | + result = PRIME * result + ((data == null) ? 0 : data.hashCode()); |
| 128 | + return result; |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + public boolean equals(Object obj) { |
| 133 | + if (this == obj) |
| 134 | + return true; |
| 135 | + if (obj == null) |
| 136 | + return false; |
| 137 | + if (getClass() != obj.getClass()) |
| 138 | + return false; |
| 139 | + final DefaultFeatureSet other = (DefaultFeatureSet) obj; |
| 140 | + if (data == null) { |
| 141 | + if (other.data != null) |
| 142 | + return false; |
| 143 | + } else if (!data.equals(other.data)) |
| 144 | + return false; |
| 145 | + return true; |
| 146 | + } |
118 | 147 | |
119 | 148 | |
120 | 149 | } |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/Record.java |
— | — | @@ -1,6 +1,7 @@ |
2 | 2 | package de.brightbyte.wikiword.integrator.data; |
3 | 3 | |
4 | 4 | import de.brightbyte.abstraction.AbstractAccessor; |
| 5 | +import de.brightbyte.db.DatabaseUtil; |
5 | 6 | |
6 | 7 | public interface Record extends Cloneable { |
7 | 8 | |
— | — | @@ -11,7 +12,8 @@ |
12 | 13 | } |
13 | 14 | |
14 | 15 | public V getValue(Record obj) { |
15 | | - return (V)obj.get(property); |
| 16 | + Object v = obj.get(property); |
| 17 | + return (V)DatabaseUtil.as(v, getType()); |
16 | 18 | } |
17 | 19 | |
18 | 20 | public boolean isMutable() { |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultAssociation.java |
— | — | @@ -1,5 +1,7 @@ |
2 | 2 | package de.brightbyte.wikiword.integrator.data; |
3 | 3 | |
| 4 | +import java.util.ArrayList; |
| 5 | +import java.util.Collection; |
4 | 6 | import java.util.Map; |
5 | 7 | |
6 | 8 | import de.brightbyte.data.Accumulator; |
— | — | @@ -58,7 +60,7 @@ |
59 | 61 | } |
60 | 62 | |
61 | 63 | public String toString() { |
62 | | - return foreignEntity + " <-> " + conceptEntity; |
| 64 | + return data.toString(); |
63 | 65 | } |
64 | 66 | |
65 | 67 | public DefaultAssociation clone() { |
— | — | @@ -78,15 +80,113 @@ |
79 | 81 | String field = e.getKey(); |
80 | 82 | Accumulator<Object, Object> accumulator = (Accumulator<Object, Object>)e.getValue(); //XXX: unsafe case |
81 | 83 | |
82 | | - Object a = data.getPrimitive(field); //TODO: aggregate instead?! |
83 | | - Object b = add.data.getPrimitive(field); //TODO: aggregate instead?! |
84 | | - Object v; |
| 84 | + Object a = data.get(field); |
| 85 | + Object b = add.data.get(field); |
| 86 | + Object v = null; |
| 87 | + Collection c = null; |
85 | 88 | |
86 | 89 | if (a==null) v = b; |
87 | 90 | else if (b==null) v = a; |
88 | | - else v = accumulator.apply(a, b); //XXX: unsafe type assumption in apply. not sure accumulator matches object type |
| 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); |
| 104 | + } else { |
| 105 | + v = accumulator.apply(a, b); //XXX: unsafe type assumption in apply. not sure accumulator matches object type |
| 106 | + } |
| 107 | + } |
89 | 108 | |
| 109 | + if (c!=null) { //if we have a collectiopn, aggregate |
| 110 | + if (c.isEmpty()) return; |
| 111 | + v = null; |
| 112 | + |
| 113 | + for (Object x: c) { |
| 114 | + if (v==null) v = x; |
| 115 | + else if (x!=null) { |
| 116 | + v = accumulator.apply(v, x); |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + |
90 | 121 | data.set(field, v); |
91 | 122 | } |
92 | 123 | } |
| 124 | + |
| 125 | + @Override |
| 126 | + public int hashCode() { |
| 127 | + final int PRIME = 31; |
| 128 | + 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()); |
| 137 | + return result; |
| 138 | + } |
| 139 | + |
| 140 | + @Override |
| 141 | + public boolean equals(Object obj) { |
| 142 | + if (this == obj) |
| 143 | + return true; |
| 144 | + if (obj == null) |
| 145 | + return false; |
| 146 | + if (getClass() != obj.getClass()) |
| 147 | + 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; |
| 189 | + return true; |
| 190 | + } |
| 191 | + |
| 192 | + |
93 | 193 | } |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/FeatureAssemblingCursor.java |
— | — | @@ -10,14 +10,22 @@ |
11 | 11 | protected PropertyMapping<R> qualfierMapping = null; |
12 | 12 | protected R prev; |
13 | 13 | |
14 | | - protected PropertyAccessor<R, Object> recordIdAccessor; |
15 | | - protected PropertyAccessor<R, String> propertyNameAccessor; |
16 | | - protected PropertyAccessor<R, Object> propertyValueAccessor; |
| 14 | + protected PropertyAccessor<R, ? extends Object> recordIdAccessor; |
| 15 | + protected PropertyAccessor<R, ? extends String> propertyNameAccessor; |
| 16 | + protected PropertyAccessor<R, ? extends Object> propertyValueAccessor; |
17 | 17 | |
| 18 | + public static FeatureAssemblingCursor<Record> newForRecordCursor(DataCursor<Record> cursor, |
| 19 | + String recordIdField, String PropertyNameField, String propertyValueField) { |
| 20 | + return new FeatureAssemblingCursor<Record>(cursor, |
| 21 | + new Record.Accessor<Integer>(recordIdField, Integer.class), |
| 22 | + new Record.Accessor<String>(PropertyNameField, String.class), |
| 23 | + new Record.Accessor<Object>(propertyValueField, Object.class)); |
| 24 | + } |
| 25 | + |
18 | 26 | public FeatureAssemblingCursor(DataCursor<R> cursor, |
19 | | - PropertyAccessor<R, Object> recordIdAccessor, |
20 | | - PropertyAccessor<R, String> propertyNameAccessor, |
21 | | - PropertyAccessor<R, Object> propertyValueAccessor) { |
| 27 | + PropertyAccessor<R, ? extends Object> recordIdAccessor, |
| 28 | + PropertyAccessor<R, ? extends String> propertyNameAccessor, |
| 29 | + PropertyAccessor<R, ? extends Object> propertyValueAccessor) { |
22 | 30 | if (cursor==null) throw new NullPointerException(); |
23 | 31 | if (recordIdAccessor==null) throw new NullPointerException(); |
24 | 32 | if (propertyNameAccessor==null) throw new NullPointerException(); |
— | — | @@ -54,8 +62,10 @@ |
55 | 63 | f.addFeature(key, value, qualifiers); |
56 | 64 | |
57 | 65 | prev = cursor.next(); |
| 66 | + if (prev==null) break; |
| 67 | + |
58 | 68 | Object id = recordIdAccessor.getValue(prev); |
59 | | - if (prev==null || !currentId.equals(id)) break; |
| 69 | + if (!currentId.equals(id)) break; |
60 | 70 | } |
61 | 71 | |
62 | 72 | return f; |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/AggregatingAssociationCursor.java |
— | — | @@ -38,8 +38,9 @@ |
39 | 39 | prev = cursor.next(); |
40 | 40 | if (prev==null) break; |
41 | 41 | |
42 | | - if (prev.getConceptEntity().getID() == a.getConceptEntity().getID()) break; |
43 | | - if (prev.getForeignEntity().getID().equals( a.getForeignEntity().getID())) break; |
| 42 | + if (prev.getConceptEntity().getID() != a.getConceptEntity().getID()) break; |
| 43 | + if (!prev.getForeignEntity().getAuthority().equals( a.getForeignEntity().getAuthority())) break; |
| 44 | + if (!prev.getForeignEntity().getID().equals( a.getForeignEntity().getID())) break; |
44 | 45 | |
45 | 46 | ((DefaultAssociation)a).aggregate((DefaultAssociation)prev, accumulators); |
46 | 47 | } |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultRecord.java |
— | — | @@ -35,6 +35,10 @@ |
36 | 36 | } |
37 | 37 | |
38 | 38 | public boolean add(String key, Object value) { |
| 39 | + return add(key, value, false); |
| 40 | + } |
| 41 | + |
| 42 | + public boolean add(String key, Object value, boolean allowDupes) { |
39 | 43 | Object old = data.get(key); |
40 | 44 | |
41 | 45 | if (value instanceof Object[]) { |
— | — | @@ -48,12 +52,12 @@ |
49 | 53 | if (old==null) { |
50 | 54 | data.put(key, value); |
51 | 55 | } |
52 | | - else if (old==value || old.equals(value)) { |
| 56 | + else if (!allowDupes && (old==value || old.equals(value))) { |
53 | 57 | return false; |
54 | 58 | } |
55 | 59 | else if (old instanceof Collection) { |
56 | 60 | if (value instanceof Collection) ((Collection<Object>)old).addAll((Collection<Object>)value); |
57 | | - else if (!((Collection<Object>)old).contains(value)) ((Collection<Object>)old).add(value); |
| 61 | + else if (allowDupes || !((Collection<Object>)old).contains(value)) ((Collection<Object>)old).add(value); |
58 | 62 | else return false; |
59 | 63 | } |
60 | 64 | else { |
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/CollapsingAssociationCursorTest.java |
— | — | @@ -1,59 +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 CollapsingAssociationCursorTest 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("name", "A"); |
24 | | - |
25 | | - FeatureSet b = new DefaultFeatureSet("name"); |
26 | | - b.put("name", "B"); |
27 | | - |
28 | | - FeatureSet x = new DefaultFeatureSet("name"); |
29 | | - x.put("name", "X"); |
30 | | - |
31 | | - FeatureSet y = new DefaultFeatureSet("name"); |
32 | | - y.put("name", "Y"); |
33 | | - |
34 | | - FeatureSet p = new DefaultFeatureSet("name"); |
35 | | - p.put("name", "P"); |
36 | | - |
37 | | - FeatureSet q = new DefaultFeatureSet("name"); |
38 | | - q.put("name", "Q"); |
39 | | - |
40 | | - //-------------------------------------- |
41 | | - ArrayList<Association> source = new ArrayList<Association>(); |
42 | | - source.add(new Association(a, x, p)); |
43 | | - source.add(new Association(a, y, p)); |
44 | | - source.add(new Association(a, y, q)); |
45 | | - source.add(new Association(b, y, q)); |
46 | | - source.add(new Association(a, y, q)); |
47 | | - |
48 | | - ArrayList<Association> exp = new ArrayList<Association>(); |
49 | | - exp.add(new Association(a, x, p)); |
50 | | - exp.add(Association.merge(new Association(a, y, p), new Association(a, y, q))); |
51 | | - exp.add(new Association(b, y, q)); |
52 | | - exp.add(new Association(a, y, q)); |
53 | | - |
54 | | - DataCursor<Association> sourceCursor = new IteratorCursor<Association>(source.iterator()); |
55 | | - DataCursor<Association> cursor = new AggregatingAssociationCursor(sourceCursor, "name", "name"); |
56 | | - |
57 | | - assertEquals(exp, slurp(cursor)); |
58 | | - } |
59 | | - |
60 | | -} |
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/AssemblingFeatureSetCursorTest.java |
— | — | @@ -1,65 +0,0 @@ |
2 | | -package de.brightbyte.wikiword.integrator.data; |
3 | | - |
4 | | -import java.util.ArrayList; |
5 | | -import java.util.Arrays; |
6 | | -import java.util.Collection; |
7 | | -import java.util.List; |
8 | | - |
9 | | -import junit.framework.TestCase; |
10 | | -import de.brightbyte.data.cursor.DataCursor; |
11 | | -import de.brightbyte.data.cursor.IteratorCursor; |
12 | | -import de.brightbyte.util.PersistenceException; |
13 | | - |
14 | | -public class AssemblingFeatureSetCursorTest extends TestCase { |
15 | | - |
16 | | - private static <T> Collection<T> slurp(DataCursor<T> cursor) throws PersistenceException { |
17 | | - ArrayList<T> list = new ArrayList<T>(); |
18 | | - T obj; |
19 | | - while ((obj = cursor.next()) != null) list.add(obj); |
20 | | - return list; |
21 | | - } |
22 | | - |
23 | | - public void testNext() throws PersistenceException { |
24 | | - FeatureSet a = new DefaultFeatureSet("name"); |
25 | | - a.put("id", 1); |
26 | | - a.put("property", "name"); |
27 | | - a.put("value", "A"); |
28 | | - a.put("value", "a"); |
29 | | - a.put("xyzzy", "bla"); |
30 | | - |
31 | | - FeatureSet b = new DefaultFeatureSet("name"); |
32 | | - b.put("id", 1); |
33 | | - b.put("property", "foo"); |
34 | | - b.put("value", "X"); |
35 | | - b.put("value", "Y"); |
36 | | - |
37 | | - FeatureSet x = new DefaultFeatureSet("name"); |
38 | | - x.put("id", 2); |
39 | | - x.put("property", "name"); |
40 | | - x.put("property", "alias"); |
41 | | - x.put("value", "Foo"); |
42 | | - |
43 | | - //-------------------------------------- |
44 | | - |
45 | | - FeatureSet one = new DefaultFeatureSet(); |
46 | | - one.put("id", 1); |
47 | | - one.put("name", "A"); |
48 | | - one.put("name", "a"); |
49 | | - one.put("foo", "X"); |
50 | | - one.put("foo", "Y"); |
51 | | - |
52 | | - FeatureSet two = new DefaultFeatureSet(); |
53 | | - two.put("id", 2); |
54 | | - two.put("name", "Foo"); |
55 | | - two.put("alias", "Foo"); |
56 | | - |
57 | | - List<FeatureSet> exp= Arrays.asList(new FeatureSet[] {one, two}); |
58 | | - List<FeatureSet> source= Arrays.asList(new FeatureSet[] {a, b, x}); |
59 | | - |
60 | | - DataCursor<FeatureSet> sourceCursor = new IteratorCursor<FeatureSet>(source.iterator()); |
61 | | - DataCursor<FeatureSet> cursor = new FeatureAssemblingCursor(sourceCursor, "id", "property", "value"); |
62 | | - |
63 | | - assertEquals(exp, slurp(cursor)); |
64 | | - } |
65 | | - |
66 | | -} |
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/AggregatingAssociationCursorTest.java |
— | — | @@ -0,0 +1,73 @@ |
| 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 AggregatingAssociationCursorTest 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 | + Record ar = new DefaultRecord(); |
| 23 | + ar.add("authority", "TEST"); |
| 24 | + ar.add("id", 11); |
| 25 | + ar.add("name", "A"); |
| 26 | + ForeignEntityRecord a = new DefaultForeignEntityRecord(ar, "authority", "id", "name"); |
| 27 | + |
| 28 | + Record br = new DefaultRecord(); |
| 29 | + br.add("authority", "TEST"); |
| 30 | + br.add("id", 12); |
| 31 | + br.add("name", "B"); |
| 32 | + ForeignEntityRecord b = new DefaultForeignEntityRecord(br, "authority", "id", "name"); |
| 33 | + |
| 34 | + Record xr = new DefaultRecord(); |
| 35 | + xr.add("concept", 22); |
| 36 | + xr.add("label", "X"); |
| 37 | + ConceptEntityRecord x = new DefaultConceptEntityRecord(xr, "concept", "label"); |
| 38 | + |
| 39 | + Record yr = new DefaultRecord(); |
| 40 | + yr.add("concept", 23); |
| 41 | + yr.add("label", "Y"); |
| 42 | + ConceptEntityRecord y = new DefaultConceptEntityRecord(yr, "concept", "label"); |
| 43 | + |
| 44 | + Record p = new DefaultRecord(); |
| 45 | + p.add("foo", "P"); |
| 46 | + |
| 47 | + Record q = new DefaultRecord(); |
| 48 | + q.add("foo", "Q"); |
| 49 | + |
| 50 | + Record pq = new DefaultRecord(); |
| 51 | + pq.addAll(p); |
| 52 | + pq.addAll(q); |
| 53 | + |
| 54 | + //-------------------------------------- |
| 55 | + ArrayList<Association> source = new ArrayList<Association>(); |
| 56 | + source.add(new GenericAssociation(a, x, p)); |
| 57 | + source.add(new GenericAssociation(a, y, p)); |
| 58 | + source.add(new GenericAssociation(a, y, q)); |
| 59 | + source.add(new GenericAssociation(b, y, q)); |
| 60 | + source.add(new GenericAssociation(a, y, q)); |
| 61 | + |
| 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)); |
| 67 | + |
| 68 | + DataCursor<Association> sourceCursor = new IteratorCursor<Association>(source.iterator()); |
| 69 | + DataCursor<Association> cursor = new AggregatingAssociationCursor(sourceCursor); |
| 70 | + |
| 71 | + assertEquals(exp, slurp(cursor)); |
| 72 | + } |
| 73 | + |
| 74 | +} |
Property changes on: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/AggregatingAssociationCursorTest.java |
___________________________________________________________________ |
Added: svn:mergeinfo |
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/AssociationTest.java |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | |
13 | 13 | public void testAggregate() { |
14 | 14 | Map<String, Accumulator<?, ?>> accumulators = new HashMap<String, Accumulator<?, ?>>(); |
15 | | - accumulators.put("terms", Functors.append2()); |
| 15 | + accumulators.put("terms", Functors.concat2("|")); |
16 | 16 | accumulators.put("weight", Functors.Integer.sum2); |
17 | 17 | accumulators.put("score", Functors.Double.max2); |
18 | 18 | |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | ar.add("label", "five"); |
25 | 25 | |
26 | 26 | ar.add("terms", "A"); |
27 | | - ar.add("terms", "A"); |
| 27 | + ar.add("terms", "A", true); |
28 | 28 | ar.add("terms", "a"); |
29 | 29 | |
30 | 30 | ar.add("weight", 2); |
— | — | @@ -43,8 +43,8 @@ |
44 | 44 | |
45 | 45 | cr.add("terms", "C"); |
46 | 46 | |
47 | | - br.add("weight", 1); |
48 | | - br.add("score", 0.9); |
| 47 | + cr.add("weight", 1); |
| 48 | + cr.add("score", 0.9); |
49 | 49 | |
50 | 50 | DefaultAssociation c = new DefaultAssociation(cr, "authority", "id", "name", "concept", "label"); |
51 | 51 | |
— | — | @@ -57,13 +57,9 @@ |
58 | 58 | abr.add("concept", 5); |
59 | 59 | abr.add("label", "five"); |
60 | 60 | |
61 | | - abr.add("terms", "A"); |
62 | | - abr.add("terms", "A"); |
63 | | - abr.add("terms", "a"); |
64 | | - |
65 | | - abr.add("terms", "B"); |
| 61 | + abr.add("terms", "A|A|a|B"); |
66 | 62 | |
67 | | - abr.add("weight", 8); |
| 63 | + abr.add("weight", 5); |
68 | 64 | abr.add("score", 2.3); |
69 | 65 | |
70 | 66 | DefaultAssociation ab = new DefaultAssociation(abr, "authority", "id", "name", "concept", "label"); |
— | — | @@ -80,16 +76,10 @@ |
81 | 77 | abcr.add("concept", 5); |
82 | 78 | abcr.add("label", "five"); |
83 | 79 | |
84 | | - abcr.add("terms", "A"); |
85 | | - abcr.add("terms", "A"); |
86 | | - abcr.add("terms", "a"); |
87 | | - |
88 | | - abcr.add("terms", "B"); |
89 | | - |
90 | | - abcr.add("terms", "C"); |
| 80 | + abcr.add("terms", "A|A|a|B|C"); |
91 | 81 | |
92 | | - abr.add("weight", 9); |
93 | | - abr.add("score", 2.3); |
| 82 | + abcr.add("weight", 6); |
| 83 | + abcr.add("score", 2.3); |
94 | 84 | |
95 | 85 | DefaultAssociation abc = new DefaultAssociation(abcr, "authority", "id", "name", "concept", "label"); |
96 | 86 | |
Index: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureAssemblingCursorTest.java |
— | — | @@ -0,0 +1,70 @@ |
| 2 | +package de.brightbyte.wikiword.integrator.data; |
| 3 | + |
| 4 | +import java.util.ArrayList; |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.Collection; |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +import junit.framework.TestCase; |
| 10 | +import de.brightbyte.data.cursor.DataCursor; |
| 11 | +import de.brightbyte.data.cursor.IteratorCursor; |
| 12 | +import de.brightbyte.util.PersistenceException; |
| 13 | + |
| 14 | +public class FeatureAssemblingCursorTest extends TestCase { |
| 15 | + |
| 16 | + private static <T> Collection<T> slurp(DataCursor<T> cursor) throws PersistenceException { |
| 17 | + ArrayList<T> list = new ArrayList<T>(); |
| 18 | + T obj; |
| 19 | + while ((obj = cursor.next()) != null) list.add(obj); |
| 20 | + return list; |
| 21 | + } |
| 22 | + |
| 23 | + public void testNext() throws PersistenceException { |
| 24 | + DefaultRecord a = new DefaultRecord(); |
| 25 | + a.add("id", 1); |
| 26 | + a.add("property", "name"); |
| 27 | + a.add("value", "A"); |
| 28 | + a.add("value", "a"); |
| 29 | + a.add("xyzzy", "bla"); |
| 30 | + |
| 31 | + DefaultRecord b = new DefaultRecord(); |
| 32 | + b.add("id", 1); |
| 33 | + b.add("property", "foo"); |
| 34 | + b.add("value", "X"); |
| 35 | + b.add("value", "Y"); |
| 36 | + |
| 37 | + DefaultRecord x = new DefaultRecord(); |
| 38 | + x.add("id", 2); |
| 39 | + x.add("property", "name"); |
| 40 | + x.add("value", "Foo"); |
| 41 | + |
| 42 | + DefaultRecord y = new DefaultRecord(); |
| 43 | + y.add("id", 2); |
| 44 | + y.add("property", "alias"); |
| 45 | + y.add("value", "Foo"); |
| 46 | + |
| 47 | + //-------------------------------------- |
| 48 | + |
| 49 | + DefaultFeatureSet one = new DefaultFeatureSet(); |
| 50 | + one.addFeature("id", 1, null); |
| 51 | + one.addFeature("name", "A", null); |
| 52 | + one.addFeature("name", "a", null); |
| 53 | + one.addFeature("foo", "X", null); |
| 54 | + one.addFeature("foo", "Y", null); |
| 55 | + |
| 56 | + DefaultFeatureSet two = new DefaultFeatureSet(); |
| 57 | + two.addFeature("id", 2, null); |
| 58 | + two.addFeature("name", "Foo", null); |
| 59 | + two.addFeature("alias", "Foo", null); |
| 60 | + |
| 61 | + List<FeatureSet> exp= Arrays.asList(new FeatureSet[] {one, two}); |
| 62 | + List<Record> source= Arrays.asList(new Record[] {a, b, x, y}); |
| 63 | + |
| 64 | + DataCursor<Record> sourceCursor = new IteratorCursor<Record>(source.iterator()); |
| 65 | + DataCursor<FeatureSet> cursor = FeatureAssemblingCursor.newForRecordCursor(sourceCursor, "id", "property", "value"); |
| 66 | + |
| 67 | + Collection<FeatureSet> act = slurp(cursor); |
| 68 | + assertEquals(exp, act); |
| 69 | + } |
| 70 | + |
| 71 | +} |
Property changes on: trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureAssemblingCursorTest.java |
___________________________________________________________________ |
Added: svn:mergeinfo |