Skip to content

Commit

Permalink
Support top-level type restriction in OpenRefine reconciliation
Browse files Browse the repository at this point in the history
See #65
  • Loading branch information
fsteeg committed Jun 27, 2018
1 parent 57c6125 commit 49d1b03
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/controllers/Reconcile.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableMap;

import models.GndOntology;
import modules.IndexComponent;
import play.Logger;
import play.libs.Json;
Expand All @@ -39,7 +41,8 @@ public class Reconcile extends Controller {
@Inject
IndexComponent index;

private static final JsonNode TYPES = Json.toJson(Arrays.asList("lobid-gnd"));
private static final JsonNode TYPES = Json.toJson(HomeController.CONFIG.getStringList("topLevelTypes").stream()
.map(t -> ImmutableMap.of("id", t, "name", GndOntology.label(t))));

/**
* @param callback
Expand Down Expand Up @@ -95,8 +98,9 @@ private List<JsonNode> mapToResults(String mainQuery, SearchHits searchHits) {
private SearchResponse executeQuery(Entry<String, JsonNode> entry, String queryString) {
JsonNode limitNode = entry.getValue().get("limit");
int limit = limitNode == null ? -1 : limitNode.asInt();
SearchResponse response = index.query(queryString, "", 0, limit);
return response;
JsonNode typeNode = entry.getValue().get("type");
String filter = typeNode == null ? "" : "type:" + typeNode.asText();
return index.query(queryString, filter, 0, limit);
}

private String buildQueryString(Entry<String, JsonNode> entry) {
Expand Down
2 changes: 1 addition & 1 deletion app/modules/IndexComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
public interface IndexComponent {
Client client();

SearchResponse query(String q, String type, int from, int size);
SearchResponse query(String q, String filter, int from, int size);

public default SearchResponse query(String q) {
return query(q, "", 0, 10);
Expand Down
14 changes: 14 additions & 0 deletions test/controllers/ReconcileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static play.test.Helpers.GET;
Expand Down Expand Up @@ -66,4 +67,17 @@ public void reconcileRequest() {
});
}

@Test
public void reconcileRequestWithType() {
Application application = fakeApplication();
running(application, () -> {
Result result = route(application, fakeRequest(POST, "/gnd/reconcile").bodyForm(
ImmutableMap.of("queries", "{\"q99\":{\"query\":\"Twain, Mark\", \"type\":\"CorporateBody\"}}")));
String content = contentAsString(result);
Logger.debug(Json.prettyPrint(Json.parse(content)));
assertThat(content, containsString("q99"));
assertFalse(Json.parse(content).findValue("result").elements().hasNext());
});
}

}

0 comments on commit 49d1b03

Please sign in to comment.