Search in sources :

Example 31 with Process

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");
}
Also used : AbstractOperation(com.google.refine.model.AbstractOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 32 with Process

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);
}
Also used : Process(com.google.refine.process.Process) ProcessManager(com.google.refine.process.ProcessManager)

Example 33 with Process

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");
    }
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Process(com.google.refine.process.Process) ReconOperation(com.google.refine.operations.recon.ReconOperation) Properties(java.util.Properties) HttpUrl(okhttp3.HttpUrl) Project(com.google.refine.model.Project) MockWebServer(okhttp3.mockwebserver.MockWebServer) Row(com.google.refine.model.Row) Cell(com.google.refine.model.Cell) ProcessManager(com.google.refine.process.ProcessManager) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 34 with Process

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()));
}
Also used : Process(com.google.refine.process.Process) Properties(java.util.Properties) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 35 with Process

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()));
}
Also used : AbstractOperation(com.google.refine.model.AbstractOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

Process (com.google.refine.process.Process)43 Properties (java.util.Properties)41 AbstractOperation (com.google.refine.model.AbstractOperation)36 Test (org.testng.annotations.Test)29 RefineTest (com.google.refine.RefineTest)27 BeforeTest (org.testng.annotations.BeforeTest)20 Project (com.google.refine.model.Project)17 IOException (java.io.IOException)14 ServletException (javax.servlet.ServletException)13 Cell (com.google.refine.model.Cell)5 Row (com.google.refine.model.Row)5 Column (com.google.refine.model.Column)4 ProcessManager (com.google.refine.process.ProcessManager)4 ArrayList (java.util.ArrayList)4 StandardReconConfig (com.google.refine.model.recon.StandardReconConfig)2 ReconOperation (com.google.refine.operations.recon.ReconOperation)2 RefineTest (com.google.refine.tests.RefineTest)2 StringReader (java.io.StringReader)2 HttpUrl (okhttp3.HttpUrl)2 MockResponse (okhttp3.mockwebserver.MockResponse)2