forked from bst-mug/trec-2017-precision-medicine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This decorator can replace static (not topic-dependent) variables into templates. This allow boost keywords experiments such as bst-mug#81.
- Loading branch information
Michel Oleynik
committed
Jul 18, 2017
1 parent
b48f340
commit fabed06
Showing
4 changed files
with
88 additions
and
17 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/main/java/at/medunigraz/imi/bst/trec/query/MapQueryDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package at.medunigraz.imi.bst.trec.query; | ||
|
||
import java.util.Map; | ||
|
||
public abstract class MapQueryDecorator extends QueryDecorator { | ||
|
||
public MapQueryDecorator(Query decoratedQuery) { | ||
super(decoratedQuery); | ||
} | ||
|
||
protected void map(Map<String, String> keymap) { | ||
String jsonQuery = getJSONQuery(); | ||
|
||
for (Map.Entry<String, String> entry : keymap.entrySet()) { | ||
String search = String.format("{{%s}}", entry.getKey()); | ||
jsonQuery = jsonQuery.replace(search, entry.getValue()); | ||
} | ||
|
||
setJSONQuery(jsonQuery); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/at/medunigraz/imi/bst/trec/query/StaticMapQueryDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package at.medunigraz.imi.bst.trec.query; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import at.medunigraz.imi.bst.trec.model.Result; | ||
import at.medunigraz.imi.bst.trec.model.Topic; | ||
|
||
public class StaticMapQueryDecorator extends MapQueryDecorator { | ||
|
||
public StaticMapQueryDecorator(Map<String, String> keymap, Query decoratedQuery) { | ||
super(decoratedQuery); | ||
map(keymap); | ||
} | ||
|
||
@Override | ||
public List<Result> query(Topic topic) { | ||
return decoratedQuery.query(topic); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/test/java/at/medunigraz/imi/bst/trec/query/StaticMapQueryDecoratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package at.medunigraz.imi.bst.trec.query; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.File; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
|
||
import at.medunigraz.imi.bst.trec.model.Topic; | ||
|
||
public class StaticMapQueryDecoratorTest extends QueryDecoratorTest { | ||
|
||
private static final String DISEASE = "thyroid"; | ||
|
||
private final File template = new File(getClass().getResource("/templates/match-title.json").getFile()); | ||
|
||
private static Map<String, String> keymap = new HashMap<>(); | ||
|
||
static { | ||
keymap.put("disease", DISEASE); | ||
} | ||
|
||
public StaticMapQueryDecoratorTest() { | ||
|
||
this.decoratedQuery = new StaticMapQueryDecorator(keymap, | ||
new TemplateQueryDecorator(template, new ElasticSearchQuery("trec"))); | ||
this.topic = new Topic(); | ||
} | ||
|
||
@Test | ||
public void testGetJSONQuery() { | ||
Query decoratedQuery = new StaticMapQueryDecorator(keymap, | ||
new TemplateQueryDecorator(template, new DummyElasticSearchQuery())); | ||
decoratedQuery.query(topic); | ||
|
||
String actual = decoratedQuery.getJSONQuery(); | ||
String expected = String.format("{\"match\":{\"title\":\"%s\"}}", DISEASE); | ||
assertEquals(expected, actual); | ||
} | ||
|
||
} |