Search in sources :

Example 11 with PhraseMatcher

use of com.yahoo.prelude.querytransform.PhraseMatcher in project vespa by vespa-engine.

the class PhraseMatcherTestCase method testPhraseMatching.

@Test
public void testPhraseMatching() {
    PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true);
    AndItem and = new AndItem();
    and.addItem(new WordItem("noisebefore"));
    and.addItem(new WordItem("this"));
    and.addItem(new WordItem("is"));
    and.addItem(new WordItem("a"));
    and.addItem(new WordItem("test"));
    and.addItem(new WordItem("noiseafter"));
    List<?> matches = matcher.matchPhrases(and);
    assertNotNull(matches);
    assertEquals(1, matches.size());
    PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0);
    assertEquals(4, match.getLength());
    assertEquals("", match.getData());
    assertEquals(and, match.getOwner());
    assertEquals(1, match.getStartIndex());
    PhraseMatcher.Phrase.MatchIterator i = match.itemIterator();
    assertEquals(new WordItem("this"), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem("is"), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem("a"), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem("test"), i.next());
    assertEquals(null, i.getReplace());
    assertFalse(i.hasNext());
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseMatcher(com.yahoo.prelude.querytransform.PhraseMatcher) Test(org.junit.Test)

Example 12 with PhraseMatcher

use of com.yahoo.prelude.querytransform.PhraseMatcher in project vespa by vespa-engine.

the class PhraseMatcherTestCase method testSingleItemMatching.

@Test
public void testSingleItemMatching() {
    PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa");
    matcher.setMatchSingleItems(true);
    List<?> matches = matcher.matchPhrases(new WordItem("aword"));
    assertNotNull(matches);
    assertEquals(1, matches.size());
    PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0);
    assertEquals(1, match.getLength());
    assertEquals("", match.getData());
    assertEquals(null, match.getOwner());
    assertEquals(0, match.getStartIndex());
    PhraseMatcher.Phrase.MatchIterator i = match.itemIterator();
    assertEquals(new WordItem("aword"), i.next());
    assertNull(i.getReplace());
    assertFalse(i.hasNext());
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) PhraseMatcher(com.yahoo.prelude.querytransform.PhraseMatcher) Test(org.junit.Test)

Example 13 with PhraseMatcher

use of com.yahoo.prelude.querytransform.PhraseMatcher in project vespa by vespa-engine.

the class PhraseMatcherTestCase method testSingleItemMatchingWithPluralIgnore.

@Test
public void testSingleItemMatchingWithPluralIgnore() {
    PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true);
    matcher.setMatchSingleItems(true);
    List<?> matches = matcher.matchPhrases(new WordItem("awords"));
    assertNotNull(matches);
    assertEquals(1, matches.size());
    PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0);
    assertEquals(1, match.getLength());
    assertEquals("", match.getData());
    assertEquals(null, match.getOwner());
    assertEquals(0, match.getStartIndex());
    PhraseMatcher.Phrase.MatchIterator i = match.itemIterator();
    assertEquals(new WordItem("awords"), i.next());
    assertEquals("aword", i.getReplace());
    assertFalse(i.hasNext());
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) PhraseMatcher(com.yahoo.prelude.querytransform.PhraseMatcher) Test(org.junit.Test)

Aggregations

PhraseMatcher (com.yahoo.prelude.querytransform.PhraseMatcher)13 WordItem (com.yahoo.prelude.query.WordItem)9 Test (org.junit.Test)9 AndItem (com.yahoo.prelude.query.AndItem)5 Phrase (com.yahoo.prelude.querytransform.PhraseMatcher.Phrase)2 FSA (com.yahoo.fsa.FSA)1 IntItem (com.yahoo.prelude.query.IntItem)1 File (java.io.File)1