use of com.yahoo.prelude.query.PhraseSegmentItem in project vespa by vespa-engine.
the class CJKSearcher method hasOverlappingTokens.
/*
* We have overlapping tokens (see
* com.yahoo.prelude.querytransform.test.CJKSearcherTestCase
* .testCjkQueryWithOverlappingTokens and ParseTestCase for an explanation)
* if the sum of length of tokens is greater than the lenght of the original
* word
*/
private boolean hasOverlappingTokens(PhraseSegmentItem segments) {
int segmentsLength = 0;
for (Iterator<Item> i = segments.getItemIterator(); i.hasNext(); ) {
WordItem segment = (WordItem) i.next();
segmentsLength += segment.getWord().length();
}
return segmentsLength > segments.getRawWord().length();
}
use of com.yahoo.prelude.query.PhraseSegmentItem in project vespa by vespa-engine.
the class ParseTestCase method testFakeCJKSegmenting.
@Test
public void testFakeCJKSegmenting() {
// "first" "second" and "third" are segments in the test language
Item item = tester.parseQuery("name:firstsecondthird", null, Language.CHINESE_SIMPLIFIED, Query.Type.ANY, TestLinguistics.INSTANCE);
assertTrue(item instanceof PhraseSegmentItem);
PhraseSegmentItem phrase = (PhraseSegmentItem) item;
assertEquals(3, phrase.getItemCount());
assertEquals("name:first", phrase.getItem(0).toString());
assertEquals("name:second", phrase.getItem(1).toString());
assertEquals("name:third", phrase.getItem(2).toString());
assertEquals("name", ((WordItem) phrase.getItem(0)).getIndexName());
assertEquals("name", ((WordItem) phrase.getItem(1)).getIndexName());
assertEquals("name", ((WordItem) phrase.getItem(2)).getIndexName());
}
use of com.yahoo.prelude.query.PhraseSegmentItem in project vespa by vespa-engine.
the class PhraseItemTestCase method testAddItem.
@Test
public void testAddItem() {
PhraseItem p = new PhraseItem();
PhraseSegmentItem pp = new PhraseSegmentItem("", false, false);
PhraseItem ppp = new PhraseItem();
pp.addItem(new WordItem("b"));
pp.addItem(new WordItem("c"));
ppp.addItem(new WordItem("e"));
ppp.addItem(new WordItem("f"));
p.addItem(new WordItem("a"));
p.addItem(pp);
p.addItem(new WordItem("d"));
p.addItem(ppp);
assertEquals("\"a 'b c' d e f\"", p.toString());
}
use of com.yahoo.prelude.query.PhraseSegmentItem in project vespa by vespa-engine.
the class PhraseItemTestCase method testSetItem.
@Test
public void testSetItem() {
PhraseItem backup = new PhraseItem();
PhraseSegmentItem segment = new PhraseSegmentItem("", false, false);
PhraseItem innerPhrase = new PhraseItem();
WordItem testWord = new WordItem("z");
PhraseItem p;
segment.addItem(new WordItem("p"));
segment.addItem(new WordItem("q"));
innerPhrase.addItem(new WordItem("x"));
innerPhrase.addItem(new WordItem("y"));
backup.addItem(new WordItem("a"));
backup.addItem(new WordItem("b"));
backup.addItem(new WordItem("c"));
p = (PhraseItem) backup.clone();
p.setItem(0, segment);
assertEquals("\"'p q' b c\"", p.toString());
p = (PhraseItem) backup.clone();
p.setItem(1, segment);
assertEquals("\"a 'p q' c\"", p.toString());
p = (PhraseItem) backup.clone();
p.setItem(2, segment);
assertEquals("\"a b 'p q'\"", p.toString());
p = (PhraseItem) backup.clone();
p.setItem(0, innerPhrase);
assertEquals("\"x y b c\"", p.toString());
p = (PhraseItem) backup.clone();
p.setItem(1, innerPhrase);
assertEquals("\"a x y c\"", p.toString());
p = (PhraseItem) backup.clone();
p.setItem(2, innerPhrase);
assertEquals("\"a b x y\"", p.toString());
p = (PhraseItem) backup.clone();
p.setItem(0, testWord);
assertEquals("\"z b c\"", p.toString());
p = (PhraseItem) backup.clone();
p.setItem(1, testWord);
assertEquals("\"a z c\"", p.toString());
p = (PhraseItem) backup.clone();
p.setItem(2, testWord);
assertEquals("\"a b z\"", p.toString());
}
use of com.yahoo.prelude.query.PhraseSegmentItem in project vespa by vespa-engine.
the class ParseTestCase method testFakeCJKSegmentingOfPhrase.
@Test
public void testFakeCJKSegmentingOfPhrase() {
// "first" "second" and "third" are segments in the test language
Item item = tester.parseQuery("name:\"firstsecondthird\"", null, Language.CHINESE_SIMPLIFIED, Query.Type.ANY, TestLinguistics.INSTANCE);
assertTrue(item instanceof PhraseSegmentItem);
PhraseSegmentItem phrase = (PhraseSegmentItem) item;
assertEquals(3, phrase.getItemCount());
assertEquals("name:first", phrase.getItem(0).toString());
assertEquals("name:second", phrase.getItem(1).toString());
assertEquals("name:third", phrase.getItem(2).toString());
assertEquals("name", ((WordItem) phrase.getItem(0)).getIndexName());
assertEquals("name", ((WordItem) phrase.getItem(1)).getIndexName());
assertEquals("name", ((WordItem) phrase.getItem(2)).getIndexName());
}
Aggregations