Search in sources :

Example 1 with PhraseSegmentItem

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();
}
Also used : AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) WordItem(com.yahoo.prelude.query.WordItem)

Example 2 with PhraseSegmentItem

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());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) Test(org.junit.Test)

Example 3 with PhraseSegmentItem

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());
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 4 with PhraseSegmentItem

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());
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 5 with PhraseSegmentItem

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());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) Test(org.junit.Test)

Aggregations

PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)14 WordItem (com.yahoo.prelude.query.WordItem)14 Test (org.junit.Test)10 PhraseItem (com.yahoo.prelude.query.PhraseItem)9 AndItem (com.yahoo.prelude.query.AndItem)5 CompositeItem (com.yahoo.prelude.query.CompositeItem)4 Item (com.yahoo.prelude.query.Item)4 AndSegmentItem (com.yahoo.prelude.query.AndSegmentItem)3 OrItem (com.yahoo.prelude.query.OrItem)3 SegmentItem (com.yahoo.prelude.query.SegmentItem)3 Query (com.yahoo.search.Query)3 IntItem (com.yahoo.prelude.query.IntItem)2 NotItem (com.yahoo.prelude.query.NotItem)2 PrefixItem (com.yahoo.prelude.query.PrefixItem)2 RankItem (com.yahoo.prelude.query.RankItem)2 Substring (com.yahoo.prelude.query.Substring)2 SubstringItem (com.yahoo.prelude.query.SubstringItem)2 SuffixItem (com.yahoo.prelude.query.SuffixItem)2 TaggableItem (com.yahoo.prelude.query.TaggableItem)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)2