Skip to content
Permalink
Browse files

Support top-level type restriction in OpenRefine reconciliation

See #65
  • Loading branch information...
fsteeg committed Jun 27, 2018
1 parent 57c6125 commit 49d1b033d715a31d2a3a917c370c4c3935cf7bbc
Showing with 22 additions and 4 deletions.
  1. +7 −3 app/controllers/Reconcile.java
  2. +1 −1 app/modules/IndexComponent.java
  3. +14 −0 test/controllers/ReconcileTest.java
@@ -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;
@@ -39,7 +41,8 @@
@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
@@ -95,8 +98,9 @@ public Result reconcile() {
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) {
@@ -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);
@@ -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;
@@ -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.
You can’t perform that action at this time.