r53569 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53568‎ | r53569 | r53570 >
Date:22:07, 20 July 2009
Author:daniel
Status:deferred
Tags:
Comment:
test cases for data model test cases, DOES NOT COMPILE
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/DefaultAssociation.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultFeatureSet.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/FeatureAssemblingCursor.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/data/AggregatingAssociationCursorTest.java+(from+/trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/CollapsingAssociationCursorTest.jav (added) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/AssemblingFeatureSetCursorTest.java (deleted) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/AssociationTest.java (modified) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/CollapsingAssociationCursorTest.java (deleted) (history)
  • /trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/FeatureAssemblingCursorTest.java+(from+/trunk/WikiWord/WikiWordIntegrator/src/test/java/de/brightbyte/wikiword/integrator/data/AssemblingFeatureSetCursorTest.java:5355 (added) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultFeatureSet.java
@@ -18,6 +18,10 @@
1919 this.qualifiers = qualifiers;
2020 }
2121
 22+ public String toString() {
 23+ return String.valueOf(value);
 24+ }
 25+
2226 @Override
2327 public int hashCode() {
2428 final int PRIME = 31;
@@ -114,6 +118,31 @@
115119 public Iterable<String> keys() {
116120 return data.keySet();
117121 }
 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+ }
118147
119148
120149 }
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/Record.java
@@ -1,6 +1,7 @@
22 package de.brightbyte.wikiword.integrator.data;
33
44 import de.brightbyte.abstraction.AbstractAccessor;
 5+import de.brightbyte.db.DatabaseUtil;
56
67 public interface Record extends Cloneable {
78
@@ -11,7 +12,8 @@
1213 }
1314
1415 public V getValue(Record obj) {
15 - return (V)obj.get(property);
 16+ Object v = obj.get(property);
 17+ return (V)DatabaseUtil.as(v, getType());
1618 }
1719
1820 public boolean isMutable() {
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultAssociation.java
@@ -1,5 +1,7 @@
22 package de.brightbyte.wikiword.integrator.data;
33
 4+import java.util.ArrayList;
 5+import java.util.Collection;
46 import java.util.Map;
57
68 import de.brightbyte.data.Accumulator;
@@ -58,7 +60,7 @@
5961 }
6062
6163 public String toString() {
62 - return foreignEntity + " <-> " + conceptEntity;
 64+ return data.toString();
6365 }
6466
6567 public DefaultAssociation clone() {
@@ -78,15 +80,113 @@
7981 String field = e.getKey();
8082 Accumulator<Object, Object> accumulator = (Accumulator<Object, Object>)e.getValue(); //XXX: unsafe case
8183
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;
8588
8689 if (a==null) v = b;
8790 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+ }
89108
 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+
90121 data.set(field, v);
91122 }
92123 }
 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+
93193 }
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/FeatureAssemblingCursor.java
@@ -10,14 +10,22 @@
1111 protected PropertyMapping<R> qualfierMapping = null;
1212 protected R prev;
1313
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;
1717
 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+
1826 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) {
2230 if (cursor==null) throw new NullPointerException();
2331 if (recordIdAccessor==null) throw new NullPointerException();
2432 if (propertyNameAccessor==null) throw new NullPointerException();
@@ -54,8 +62,10 @@
5563 f.addFeature(key, value, qualifiers);
5664
5765 prev = cursor.next();
 66+ if (prev==null) break;
 67+
5868 Object id = recordIdAccessor.getValue(prev);
59 - if (prev==null || !currentId.equals(id)) break;
 69+ if (!currentId.equals(id)) break;
6070 }
6171
6272 return f;
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/AggregatingAssociationCursor.java
@@ -38,8 +38,9 @@
3939 prev = cursor.next();
4040 if (prev==null) break;
4141
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;
4445
4546 ((DefaultAssociation)a).aggregate((DefaultAssociation)prev, accumulators);
4647 }
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/data/DefaultRecord.java
@@ -35,6 +35,10 @@
3636 }
3737
3838 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) {
3943 Object old = data.get(key);
4044
4145 if (value instanceof Object[]) {
@@ -48,12 +52,12 @@
4953 if (old==null) {
5054 data.put(key, value);
5155 }
52 - else if (old==value || old.equals(value)) {
 56+ else if (!allowDupes && (old==value || old.equals(value))) {
5357 return false;
5458 }
5559 else if (old instanceof Collection) {
5660 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);
5862 else return false;
5963 }
6064 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 @@
1212
1313 public void testAggregate() {
1414 Map<String, Accumulator<?, ?>> accumulators = new HashMap<String, Accumulator<?, ?>>();
15 - accumulators.put("terms", Functors.append2());
 15+ accumulators.put("terms", Functors.concat2("|"));
1616 accumulators.put("weight", Functors.Integer.sum2);
1717 accumulators.put("score", Functors.Double.max2);
1818
@@ -23,7 +23,7 @@
2424 ar.add("label", "five");
2525
2626 ar.add("terms", "A");
27 - ar.add("terms", "A");
 27+ ar.add("terms", "A", true);
2828 ar.add("terms", "a");
2929
3030 ar.add("weight", 2);
@@ -43,8 +43,8 @@
4444
4545 cr.add("terms", "C");
4646
47 - br.add("weight", 1);
48 - br.add("score", 0.9);
 47+ cr.add("weight", 1);
 48+ cr.add("score", 0.9);
4949
5050 DefaultAssociation c = new DefaultAssociation(cr, "authority", "id", "name", "concept", "label");
5151
@@ -57,13 +57,9 @@
5858 abr.add("concept", 5);
5959 abr.add("label", "five");
6060
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");
6662
67 - abr.add("weight", 8);
 63+ abr.add("weight", 5);
6864 abr.add("score", 2.3);
6965
7066 DefaultAssociation ab = new DefaultAssociation(abr, "authority", "id", "name", "concept", "label");
@@ -80,16 +76,10 @@
8177 abcr.add("concept", 5);
8278 abcr.add("label", "five");
8379
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");
9181
92 - abr.add("weight", 9);
93 - abr.add("score", 2.3);
 82+ abcr.add("weight", 6);
 83+ abcr.add("score", 2.3);
9484
9585 DefaultAssociation abc = new DefaultAssociation(abcr, "authority", "id", "name", "concept", "label");
9686
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

Status & tagging log