use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class MessageMapTest method test2.
@Test
public void test2() throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo();
Message array = NavajoFactory.getInstance().createMessage(n, "Array");
n.addMessage(array);
array.setType(Message.MSG_TYPE_ARRAY);
for (int i = 0; i < 10; i++) {
Message c = NavajoFactory.getInstance().createMessage(n, "Array");
array.addElement(c);
if (i % 2 == 0) {
Property p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
Property p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Laptop", 0, "", "out");
Property p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, (i * 10) + "", 0, "", "out");
String d3 = "2012-01-" + ((i + 1) < 10 ? "0" + (i + 1) : i);
Property p3 = NavajoFactory.getInstance().createProperty(n, "Date", Property.DATE_PROPERTY, d3, 0, "", "out");
Property p4 = NavajoFactory.getInstance().createProperty(n, "Gender", "1", "Geslacht", "");
p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Man", "Man", false));
p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Vrouw", "Vrouw", true));
c.addProperty(p1);
c.addProperty(p1a);
c.addProperty(p2);
c.addProperty(p3);
c.addProperty(p4);
} else {
Property p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
Property p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Desktop", 0, "", "out");
Property p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, (i * 20) + "", 0, "", "out");
String d3 = "2012-01-" + ((i + 1) < 10 ? "0" + (i + 1) : (i + 1));
Property p3 = NavajoFactory.getInstance().createProperty(n, "Date", Property.DATE_PROPERTY, d3, 0, "", "out");
Property p4 = NavajoFactory.getInstance().createProperty(n, "Gender", "1", "Geslacht", "");
p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Man", "Man", false));
p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Vrouw", "Vrouw", true));
c.addProperty(p1);
c.addProperty(p1a);
c.addProperty(p2);
c.addProperty(p3);
c.addProperty(p4);
}
}
n.write(System.err);
Access a = new Access();
a.setOutputDoc(n);
MessageMap mm = new MessageMap();
mm.load(a);
// mm.setGroupBy("Product,Sub");
mm.setJoinMessage1("Array");
mm.setJoinType("outer");
// mm.setRemoveSource(true);
Message resultMessage = NavajoFactory.getInstance().createMessage(n, "ResultingMessage");
resultMessage.setType("array");
n.addMessage(resultMessage);
a.setCurrentOutMessage(resultMessage);
ResultMessage[] result = mm.getResultMessage();
a.setCurrentOutMessage(null);
mm.store();
assertEquals("Vrouw", result[0].getProperty("Gender"));
// n.write(System.err);
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class MessageMapTest method test.
@Test
public void test() throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo();
Message array = NavajoFactory.getInstance().createMessage(n, "Array");
n.addMessage(array);
array.setType(Message.MSG_TYPE_ARRAY);
for (int i = 0; i < 10; i++) {
Message c = NavajoFactory.getInstance().createMessage(n, "Array");
array.addElement(c);
if (i % 2 == 0) {
Property p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
Property p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Laptop", 0, "", "out");
Property p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, (i * 10) + "", 0, "", "out");
String d3 = "2012-01-" + ((i + 1) < 10 ? "0" + (i + 1) : i);
Property p3 = NavajoFactory.getInstance().createProperty(n, "Date", Property.DATE_PROPERTY, d3, 0, "", "out");
Property p4 = NavajoFactory.getInstance().createProperty(n, "Gender", "1", "Geslacht", "");
p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Man", "Man", false));
p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Vrouw", "Vrouw", true));
c.addProperty(p1);
c.addProperty(p1a);
c.addProperty(p2);
c.addProperty(p3);
c.addProperty(p4);
if (i % 4 == 0) {
Property p5 = NavajoFactory.getInstance().createProperty(n, "City", Property.STRING_PROPERTY, "Amsterdam", 0, "", "out");
c.addProperty(p5);
} else {
Property p5 = NavajoFactory.getInstance().createProperty(n, "City", Property.STRING_PROPERTY, "Leiden", 0, "", "out");
c.addProperty(p5);
}
} else {
Property p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
Property p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Desktop", 0, "", "out");
Property p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, (i * 20) + "", 0, "", "out");
String d3 = "2012-01-" + ((i + 1) < 10 ? "0" + (i + 1) : (i + 1));
Property p3 = NavajoFactory.getInstance().createProperty(n, "Date", Property.DATE_PROPERTY, d3, 0, "", "out");
Property p4 = NavajoFactory.getInstance().createProperty(n, "Gender", "1", "Geslacht", "");
p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Man", "Man", true));
p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Vrouw", "Vrouw", true));
c.addProperty(p1);
c.addProperty(p1a);
c.addProperty(p2);
c.addProperty(p3);
c.addProperty(p4);
if (i % 4 == 1) {
Property p5 = NavajoFactory.getInstance().createProperty(n, "City", Property.STRING_PROPERTY, "Leiden", 0, "", "out");
c.addProperty(p5);
} else {
// Undo the double selected for the 4x + 3 rows
p4.setSelected("Man");
Property p5 = NavajoFactory.getInstance().createProperty(n, "City", Property.STRING_PROPERTY, "Hoorn", 0, "", "out");
c.addProperty(p5);
}
}
}
n.write(System.err);
Access a = new Access();
a.setOutputDoc(n);
MessageMap mm = new MessageMap();
mm.load(a);
mm.setGroupBy("Product,Sub");
mm.setJoinMessage1("Array");
mm.setJoinType("outer");
// mm.setRemoveSource(true);
Message resultMessage = NavajoFactory.getInstance().createMessage(n, "ResultingMessage");
resultMessage.setType("array");
n.addMessage(resultMessage);
a.setCurrentOutMessage(resultMessage);
ResultMessage[] result = mm.getResultMessage();
// for (int i = 0; i < result.length; i++) {
// result[i].load(a);
// result[i].getMsg().write(System.err);
// System.err.println("Count: " + result[i].getCount("Age"));
// System.err.println("Sum: " + result[i].getSum("Age"));
// System.err.println("Average: " + result[i].getAvg("Age"));
// result[i].store();
// }
a.setCurrentOutMessage(null);
mm.store();
assertEquals(2, result.length);
assertEquals(5, result[0].getCount("Age"));
assertEquals(200.0, result[0].getSum("Age"), 1);
assertEquals(500.0, result[1].getSum("Age"), 1);
assertEquals(40.0, result[0].getAvg("Age"), 1);
assertEquals(100.0, result[1].getAvg("Age"), 1);
assertEquals(80.0, result[0].getMax("Age"));
assertEquals(0.0, result[0].getMin("Age"));
assertEquals(180.0, result[1].getMax("Age"));
assertEquals(20.0, result[1].getMin("Age"));
assertEquals(new SimpleDateFormat("yyyy-MM-dd").parseObject("2012-01-01"), result[0].getMin("Date"));
assertEquals(new SimpleDateFormat("yyyy-MM-dd").parseObject("2012-01-02"), result[1].getMin("Date"));
assertEquals(new SimpleDateFormat("yyyy-MM-dd").parseObject("2012-01-09"), result[0].getMax("Date"));
assertEquals(new SimpleDateFormat("yyyy-MM-dd").parseObject("2012-01-10"), result[1].getMax("Date"));
assertEquals("Amsterdam", result[0].getAny("City"));
assertEquals("Leiden", result[1].getAny("City"));
assertEquals("Amsterdam;Leiden;Amsterdam;Leiden;Amsterdam", result[0].getConcatenated("City"));
assertEquals("Leiden;Hoorn;Leiden;Hoorn;Leiden", result[1].getConcatenated("City"));
assertEquals("Vrouw", result[0].getAny("Gender").toString());
assertEquals("Man,Vrouw", result[1].getAny("Gender").toString());
assertEquals("Vrouw;Vrouw;Vrouw;Vrouw;Vrouw", result[0].getConcatenated("Gender"));
assertEquals("Man;Vrouw;Man;Man;Vrouw;Man;Man;Vrouw", result[1].getConcatenated("Gender"));
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class TestNavajoMap method testSendThroughSetTrue.
@Test
public void testSendThroughSetTrue() throws MappableException, UserException {
Navajo inDoc = NavajoFactory.getInstance().createNavajo();
Property property = NavajoFactory.getInstance().createProperty(inDoc, "Meaning", INTEGER_PROPERTY, "42", 0, "", "out");
Message message = NavajoFactory.getInstance().createMessage(inDoc, "SendThrough");
message.addProperty(property);
inDoc.addMessage(message);
Message global = NavajoFactory.getInstance().createMessage(inDoc, "Global");
global.setScope(Message.MSG_SCOPE_GLOBAL);
inDoc.addMessage(global);
Message local = NavajoFactory.getInstance().createMessage(inDoc, "Local");
local.setScope(Message.MSG_SCOPE_LOCAL);
inDoc.addMessage(local);
// Initialize the navajomap.
DispatcherFactory.createDispatcher(new Dispatcher());
Access access = new Access();
access.setInDoc(inDoc);
access.setOutputDoc(outDoc);
map.load(access);
map.setSendThrough(true);
map.prepareOutDoc();
assertTrue(map.getSendThrough());
assertEquals("42", map.outDoc.getMessage("SendThrough").getProperty("Meaning").getValue());
assertEquals(Message.MSG_SCOPE_GLOBAL, map.outDoc.getMessage("Global").getScope());
assertNull(map.outDoc.getMessage("Local"));
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class PropertyAggregateTest method test1.
@Test
public void test1() {
Navajo n = NavajoFactory.getInstance().createNavajo();
Property p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
Property p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, "200", 0, "", "out");
Property p3 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "Book", 0, "", "out");
Property p4 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, "5", 0, "", "out");
Property p5 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
Property p6 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, "100", 0, "", "out");
Property p7 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "Book", 0, "", "out");
Property p8 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, "20", 0, "", "out");
Property p9 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
Property p10 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, "300", 0, "", "out");
PropertyAggregate pa = new PropertyAggregate();
addSinglePropertyGroup(pa, p2, p1);
addSinglePropertyGroup(pa, p4, p3);
addSinglePropertyGroup(pa, p6, p5);
addSinglePropertyGroup(pa, p8, p7);
addSinglePropertyGroup(pa, p10, p9);
Map<String, Object> groupDef = new TreeMap<String, Object>();
groupDef.put("Product", "PC");
Aggregate ag = pa.getAggregate(groupDef);
Assert.assertEquals(3, ag.getCount());
Assert.assertEquals(200.0, ag.getAvg(), 0.0);
Assert.assertEquals(600, (int) ag.getSum());
groupDef.clear();
groupDef.put("Product", "Book");
ag = pa.getAggregate(groupDef);
Assert.assertEquals(2, ag.getCount());
Assert.assertEquals(12.5, ag.getAvg(), 0.0);
Assert.assertEquals(25, (int) ag.getSum());
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class PropertyAggregateTest method test2.
@Test
public void test2() {
Navajo n = NavajoFactory.getInstance().createNavajo();
Property p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
Property p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Laptop", 0, "", "out");
Property p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, "200", 0, "", "out");
Property p3 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "Book", 0, "", "out");
Property p3a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Novel", 0, "", "out");
Property p4 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, "5", 0, "", "out");
Property p5 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
Property p5a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Desktop", 0, "", "out");
Property p6 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, "100", 0, "", "out");
Property p7 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "Book", 0, "", "out");
Property p7a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Novel", 0, "", "out");
Property p8 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, "20", 0, "", "out");
Property p9 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
Property p9a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Desktop", 0, "", "out");
Property p10 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, "300", 0, "", "out");
PropertyAggregate pa = new PropertyAggregate();
List<Property> group = new ArrayList<Property>();
// 1
group.add(p1);
group.add(p1a);
addProperty(pa, p2, group);
// 2
group.add(p3);
group.add(p3a);
addProperty(pa, p4, group);
// 3
group.add(p5);
group.add(p5a);
addProperty(pa, p6, group);
// 3
group.add(p7);
group.add(p7a);
addProperty(pa, p8, group);
// 3
group.add(p9);
group.add(p9a);
addProperty(pa, p10, group);
Map<String, Object> groupDef = new TreeMap<String, Object>();
groupDef.put("Sub", "Desktop");
groupDef.put("Product", "PC");
Aggregate ag = pa.getAggregate(groupDef);
Assert.assertEquals(2, ag.getCount());
Assert.assertEquals(200.0, ag.getAvg(), 0.0);
Assert.assertEquals(400, (int) ag.getSum());
groupDef.clear();
groupDef.put("Sub", "Novel");
groupDef.put("Product", "Book");
ag = pa.getAggregate(groupDef);
Assert.assertEquals(2, ag.getCount());
Assert.assertEquals(12.5, ag.getAvg(), 0.0);
Assert.assertEquals(25, (int) ag.getSum());
}
Aggregations