Search in sources :

Example 1 with PhraseMatcher

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

the class RuleBase method setAutomataFile.

/**
 * Sets the name of the automata file to use as a source of condition matches.
 * To reload the automata, call this again. This can be done safely at any
 * point by any thread while this rule base is in use.
 *
 * @throws IllegalArgumentException if the file is not found
 */
public void setAutomataFile(String automataFile) {
    if (!new File(automataFile).exists())
        throw new IllegalArgumentException("Automata file '" + automataFile + "' " + "included in " + this + " not found");
    phraseMatcher = new PhraseMatcher(automataFile);
    phraseMatcher.setIgnorePluralForm(true);
    phraseMatcher.setMatchAll(true);
    phraseMatcher.setMatchPhraseItems(true);
    phraseMatcher.setMatchSingleItems(true);
    setPhraseMatcher(phraseMatcher);
    this.automataFileName = automataFile;
}
Also used : File(java.io.File) PhraseMatcher(com.yahoo.prelude.querytransform.PhraseMatcher)

Example 2 with PhraseMatcher

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

the class PhraseMatcherTestCase method testPhraseMatchingCaseInsensitive.

@Test
public void testPhraseMatchingCaseInsensitive() {
    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"));
    final String firstWord = "thIs";
    and.addItem(new WordItem(firstWord));
    final String secondWord = "Is";
    and.addItem(new WordItem(secondWord));
    final String thirdWord = "A";
    and.addItem(new WordItem(thirdWord));
    final String fourthWord = "tEst";
    and.addItem(new WordItem(fourthWord));
    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(firstWord), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem(secondWord), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem(thirdWord), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem(fourthWord), 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 3 with PhraseMatcher

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

the class PhraseMatcherTestCase method testSingleItemMatchingCaseInsensitive.

@Test
public void testSingleItemMatchingCaseInsensitive() {
    PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa");
    matcher.setMatchSingleItems(true);
    final String mixedCase = "aWoRD";
    List<?> matches = matcher.matchPhrases(new WordItem(mixedCase));
    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(mixedCase), 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 4 with PhraseMatcher

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

the class PhraseMatcherTestCase method testPhraseMatchingWithNumber.

@Test
public void testPhraseMatchingWithNumber() {
    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 IntItem("3"));
    and.addItem(new WordItem("tests"));
    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 IntItem("3"), i.next());
    assertEquals(null, i.getReplace());
    assertEquals(new WordItem("tests"), i.next());
    assertEquals(null, i.getReplace());
    assertFalse(i.hasNext());
}
Also used : IntItem(com.yahoo.prelude.query.IntItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseMatcher(com.yahoo.prelude.querytransform.PhraseMatcher) Test(org.junit.Test)

Example 5 with PhraseMatcher

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

the class PhraseMatcherTestCase method testSingleItemMatchingCaseInsensitiveWithPluralIgnore.

@Test
public void testSingleItemMatchingCaseInsensitiveWithPluralIgnore() {
    PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true);
    matcher.setMatchSingleItems(true);
    final String mixedCase = "aWoRDS";
    List<?> matches = matcher.matchPhrases(new WordItem(mixedCase));
    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(mixedCase), 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