use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class SegmentItemTestCase method test.
@Test
public final void test() {
PhraseSegmentItem item = new PhraseSegmentItem("a b c", false, true);
item.addItem(new WordItem("a"));
item.addItem(new WordItem("b"));
item.addItem(new WordItem("c"));
assertEquals(100, item.getItem(0).getWeight());
item.setWeight(150);
assertEquals(150, item.getItem(0).getWeight());
assertEquals(item.getItem(0).getWeight(), item.getItem(1).getWeight());
assertEquals(item.getItem(0).getWeight(), item.getItem(2).getWeight());
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class SerializeItemTestCase method serialize_near_item.
@Test
public void serialize_near_item() throws ParseException {
int distance = 23;
NearItem nearItem = new NearItem(distance);
{
nearItem.addItem(new WordItem("first"));
nearItem.addItem(new WordItem("second"));
}
NearItem deSerialized = serializeThenParse(nearItem);
assertThat(deSerialized.getDistance(), is(distance));
assertThat(deSerialized.getItemCount(), is(2));
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class SerializeItemTestCase method serialize_not_item.
@Test
public void serialize_not_item() throws ParseException {
NotItem notItem = new NotItem();
{
notItem.addItem(new WordItem("first"));
notItem.addItem(new WordItem("second"));
}
serializeThenParse(notItem);
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class SerializeItemTestCase method serialize_connectivity.
@Test
public void serialize_connectivity() throws ParseException {
OrItem orItem = new OrItem();
{
WordItem first = new WordItem("first");
WordItem second = new WordItem("second");
first.setConnectivity(second, 3.14);
orItem.addItem(first);
orItem.addItem(second);
}
OrItem deSerialized = serializeThenParse(orItem);
WordItem first = (WordItem) deSerialized.getItem(0);
Item second = deSerialized.getItem(1);
assertThat(first.getConnectedItem(), is(second));
assertThat(first.getConnectivity(), is(3.14));
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class QueryTestCase method testCloneWithConnectivity.
@Test
public void testCloneWithConnectivity() {
List<String> l = new ArrayList();
l.add("a");
l.add("b");
l.add("c");
l.add("a");
printIt(l.stream().filter(i -> isA(i)).collect(Collectors.toList()));
printIt(l.stream().filter(i -> !isA(i)).collect(Collectors.toList()));
Query q = new Query();
WordItem a = new WordItem("a");
WordItem b = new WordItem("b");
WordItem c = new WordItem("c");
WordItem d = new WordItem("d");
WordItem e = new WordItem("e");
WordItem f = new WordItem("f");
WordItem g = new WordItem("g");
OrItem or = new OrItem();
or.addItem(c);
or.addItem(d);
AndItem and1 = new AndItem();
and1.addItem(a);
and1.addItem(b);
and1.addItem(or);
and1.addItem(e);
AndItem and2 = new AndItem();
and2.addItem(f);
and2.addItem(g);
RankItem rank = new RankItem();
rank.addItem(and1);
rank.addItem(and2);
a.setConnectivity(b, 0.1);
b.setConnectivity(c, 0.2);
c.setConnectivity(d, 0.3);
d.setConnectivity(e, 0.4);
e.setConnectivity(f, 0.5);
f.setConnectivity(g, 0.6);
q.getModel().getQueryTree().setRoot(rank);
Query qClone = q.clone();
assertEquals(q, qClone);
RankItem rankClone = (RankItem) qClone.getModel().getQueryTree().getRoot();
AndItem and1Clone = (AndItem) rankClone.getItem(0);
AndItem and2Clone = (AndItem) rankClone.getItem(1);
OrItem orClone = (OrItem) and1Clone.getItem(2);
WordItem aClone = (WordItem) and1Clone.getItem(0);
WordItem bClone = (WordItem) and1Clone.getItem(1);
WordItem cClone = (WordItem) orClone.getItem(0);
WordItem dClone = (WordItem) orClone.getItem(1);
WordItem eClone = (WordItem) and1Clone.getItem(3);
WordItem fClone = (WordItem) and2Clone.getItem(0);
WordItem gClone = (WordItem) and2Clone.getItem(1);
assertTrue(rankClone != rank);
assertTrue(and1Clone != and1);
assertTrue(and2Clone != and2);
assertTrue(orClone != or);
assertTrue(aClone != a);
assertTrue(bClone != b);
assertTrue(cClone != c);
assertTrue(dClone != d);
assertTrue(eClone != e);
assertTrue(fClone != f);
assertTrue(gClone != g);
assertTrue(aClone.getConnectedItem() == bClone);
assertTrue(bClone.getConnectedItem() == cClone);
assertTrue(cClone.getConnectedItem() == dClone);
assertTrue(dClone.getConnectedItem() == eClone);
assertTrue(eClone.getConnectedItem() == fClone);
assertTrue(fClone.getConnectedItem() == gClone);
double delta = 0.0000001;
assertEquals(0.1, aClone.getConnectivity(), delta);
assertEquals(0.2, bClone.getConnectivity(), delta);
assertEquals(0.3, cClone.getConnectivity(), delta);
assertEquals(0.4, dClone.getConnectivity(), delta);
assertEquals(0.5, eClone.getConnectivity(), delta);
assertEquals(0.6, fClone.getConnectivity(), delta);
}
Aggregations