1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.semantics.test;
import com.yahoo.search.Query;
import com.yahoo.prelude.semantics.RuleBase;
/**
* Tests rule bases using automatas for matching
*
* @author bratseth
*/
public class AutomataTestCase extends RuleBaseAbstractTestCase {
private final String root="src/test/java/com/yahoo/prelude/semantics/test/rulebases/";
public AutomataTestCase(String name) {
super(name,"automatarules.sr","semantics.fsa");
}
public void testAutomataRuleBase() throws Exception {
RuleBase ruleBase=searcher.getDefaultRuleBase();
assertEquals(RuleBase.class,ruleBase.getClass());
assertTrue(ruleBase.getSource().endsWith(root + "automatarules.sr"));
assertEquals(root + "semantics.fsa",ruleBase.getAutomataFile());
Query query=new Query("?query=sony+digital+camera");
ruleBase.analyze(query,0);
assertEquals("RANK (AND sony digital camera) dsp1:sony dsp5:digicamera", query.getModel().getQueryTree().getRoot().toString());
query=new Query("?query=sony+digital+camera&rules.reload");
ruleBase=searcher.getDefaultRuleBase();
assertTrue(ruleBase.getSource().endsWith(root + "automatarules.sr"));
assertEquals(root + "semantics.fsa",ruleBase.getAutomataFile());
ruleBase.analyze(query,0);
assertEquals("RANK (AND sony digital camera) dsp1:sony dsp5:digicamera", query.getModel().getQueryTree().getRoot().toString());
}
public void testAutomataSingleQuery() throws Exception {
assertSemantics("RANK sony dsp1:sony","sony");
}
public void testAutomataFilterIsIgnored() throws Exception {
assertSemantics("RANK sony |something dsp1:sony","sony&filter=something");
assertSemantics("RANK something |sony","something&filter=sony");
}
public void testAutomataPluralMatches() throws Exception {
assertSemantics("RANK sonys dsp1:sony","sonys");
assertSemantics("RANK (AND car cleaner) dsp1:\"car cleaners\" dsp5:\"car cleaners\"","car cleaner");
assertSemantics("RANK (AND sony digitals cameras) dsp1:sony dsp5:digicamera","sony digitals cameras");
}
public void testMatchingMultipleAutomataConditionsSingleWord() {
assertSemantics("RANK carpenter dsp1:carpenter dsp5:carpenter","carpenter");
}
public void testMatchingMultipleAutomataConditionsPhrase() {
assertSemantics("RANK (AND car cleaners) dsp1:\"car cleaners\" dsp5:\"car cleaners\"","car cleaners");
}
public void tstReplaceOnNoMatch() { // TODO: Make this work again
assertSemantics("nomatch:sonny","sonny&donomatch");
assertSemantics("RANK sony dsp1:sony","sony&donomatch");
assertSemantics("RANK sonys dsp1:sony","sonys&donomatch");
assertSemantics("AND nomatch:sonny nomatch:boy","sonny boy&donomatch");
assertSemantics("RANK (AND sony nomatch:boy) dsp1:sony","sony boy&donomatch");
}
}
|