use of com.google.refine.process.Process in project OpenRefine by OpenRefine.
the class SplitMultiValuedCellsTests method testSplitMultiValuedCellsTextSeparator.
/**
* Test to demonstrate the intended behaviour of the function, for issue #1268
* https://github.com/OpenRefine/OpenRefine/issues/1268
*/
@Test
public void testSplitMultiValuedCellsTextSeparator() throws Exception {
AbstractOperation op = new MultiValuedCellSplitOperation("Value", "Key", ":", false);
Process process = op.createProcess(project, new Properties());
process.performImmediate();
int keyCol = project.columnModel.getColumnByName("Key").getCellIndex();
int valueCol = project.columnModel.getColumnByName("Value").getCellIndex();
Assert.assertEquals(project.rows.get(0).getCellValue(keyCol), "Record_1");
Assert.assertEquals(project.rows.get(0).getCellValue(valueCol), "one");
Assert.assertEquals(project.rows.get(1).getCellValue(keyCol), null);
Assert.assertEquals(project.rows.get(1).getCellValue(valueCol), "two;three four;fiveSix SevèËight;niné91011twelve thirteen 14Àifteen");
}
use of com.google.refine.process.Process in project OpenRefine by OpenRefine.
the class ColumnAdditionByFetchingURLsOperationTests method runAndWait.
private void runAndWait(EngineDependentOperation op, int timeout) throws Exception {
ProcessManager pm = project.getProcessManager();
Process process = op.createProcess(project, options);
runAndWait(pm, process, timeout);
}
use of com.google.refine.process.Process in project OpenRefine by OpenRefine.
the class StandardReconConfigTests method reconTest.
@Test
public void reconTest() throws Exception {
Project project = createCSVProject("title,director\n" + "mulholland drive,david lynch");
String reconResponse = "{\n" + "q0: {\n" + " result: [\n" + " {\n" + " P57: {\n" + "score: 100,\n" + "weighted: 40\n" + "},\n" + "all_labels: {\n" + "score: 59,\n" + "weighted: 59\n" + "},\n" + "score: 70.71428571428572,\n" + "id: \"Q3989262\",\n" + "name: \"The Short Films of David Lynch\",\n" + "type: [\n" + "{\n" + "id: \"Q24862\",\n" + "name: \"short film\"\n" + "},\n" + "{\n" + "id: \"Q202866\",\n" + "name: \"animated film\"\n" + "}\n" + "],\n" + "match: false\n" + "},\n" + "{\n" + "P57: {\n" + "score: 100,\n" + "weighted: 40\n" + "},\n" + "all_labels: {\n" + "score: 44,\n" + "weighted: 44\n" + "},\n" + "score: 60.00000000000001,\n" + "id: \"Q83365219\",\n" + "name: \"What Did Jack Do?\",\n" + "type: [\n" + "{\n" + "id: \"Q24862\",\n" + "name: \"short film\"\n" + "}\n" + "],\n" + "match: false\n" + " }\n" + " ]\n" + " }\n" + "}\n";
try (MockWebServer server = new MockWebServer()) {
server.start();
HttpUrl url = server.url("/openrefine-wikidata/en/api");
// service initially overloaded
server.enqueue(new MockResponse().setResponseCode(503));
// service returns successfully
server.enqueue(new MockResponse().setBody(reconResponse));
server.enqueue(new MockResponse());
String configJson = " {\n" + " \"mode\": \"standard-service\",\n" + " \"service\": \"" + url + "\",\n" + " \"identifierSpace\": \"http://www.wikidata.org/entity/\",\n" + " \"schemaSpace\": \"http://www.wikidata.org/prop/direct/\",\n" + " \"type\": {\n" + " \"id\": \"Q11424\",\n" + " \"name\": \"film\"\n" + " },\n" + " \"autoMatch\": true,\n" + " \"columnDetails\": [\n" + " {\n" + " \"column\": \"director\",\n" + " \"propertyName\": \"Director\",\n" + " \"propertyID\": \"P57\"\n" + " }\n" + " ]}";
StandardReconConfig config = StandardReconConfig.reconstruct(configJson);
ReconOperation op = new ReconOperation(EngineConfig.reconstruct(null), "director", config);
Process process = op.createProcess(project, new Properties());
ProcessManager pm = project.getProcessManager();
process.startPerforming(pm);
Assert.assertTrue(process.isRunning());
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
Assert.fail("Test interrupted");
}
Assert.assertFalse(process.isRunning());
// ignore the first request which was a 503 error
server.takeRequest();
RecordedRequest request1 = server.takeRequest();
assertNotNull(request1);
String query = request1.getBody().readUtf8Line();
assertNotNull(query);
String expected = "queries=" + URLEncoder.encode("{\"q0\":{\"query\":\"david lynch\",\"type\":\"Q11424\",\"properties\":[{\"pid\":\"P57\",\"v\":\"david lynch\"}],\"type_strict\":\"should\"}}", "UTF-8");
assertEquals(query, expected);
Row row = project.rows.get(0);
Cell cell = row.cells.get(1);
assertNotNull(cell.recon);
assertEquals(cell.recon.service, url.toString());
assertEquals(cell.recon.getBestCandidate().types[0], "Q24862");
}
}
use of com.google.refine.process.Process in project OpenRefine by OpenRefine.
the class ExtendDataOperationTests method serializeExtendDataProcess.
@Test
public void serializeExtendDataProcess() throws Exception {
Process p = ParsingUtilities.mapper.readValue(operationJson, ExtendDataOperation.class).createProcess(project, new Properties());
TestUtils.isSerializedTo(p, String.format(processJson, p.hashCode()));
}
use of com.google.refine.process.Process in project OpenRefine by OpenRefine.
the class ColumnAdditionByFetchingURLsOperationTests method serializeUrlFetchingProcess.
@Test
public void serializeUrlFetchingProcess() throws Exception {
AbstractOperation op = ParsingUtilities.mapper.readValue(json, ColumnAdditionByFetchingURLsOperation.class);
Process process = op.createProcess(project, new Properties());
TestUtils.isSerializedTo(process, String.format(processJson, process.hashCode()));
}
Aggregations