Search in sources :

Example 11 with Process

use of com.google.refine.process.Process in project OpenRefine by OpenRefine.

the class DenormalizeCommand method doPost.

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        Project project = getProject(request);
        AbstractOperation op = new DenormalizeOperation();
        Process process = op.createProcess(project, new Properties());
        performProcessAndRespond(request, response, project, process);
    } catch (Exception e) {
        respondException(response, e);
    }
}
Also used : Project(com.google.refine.model.Project) AbstractOperation(com.google.refine.model.AbstractOperation) DenormalizeOperation(com.google.refine.operations.row.DenormalizeOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 12 with Process

use of com.google.refine.process.Process in project OpenRefine by OpenRefine.

the class TransposeTests method keyValueComumnize.

@Test
public void keyValueComumnize() throws Exception {
    String input = "ID;Cat;Val\n" + "1;a;1\n" + "1;b;3\n" + "2;b;4\n" + "2;c;5\n" + "3;a;2\n" + "3;b;5\n" + "3;d;3\n";
    prepareOptions(";", -1, 0, 0, 1, false, false);
    List<Exception> exceptions = new ArrayList<Exception>();
    importer.parseOneFile(project, metadata, job, "filesource", new StringReader(input), -1, options, exceptions);
    project.update();
    ProjectManager.singleton.registerProject(project, metadata);
    AbstractOperation op = new KeyValueColumnizeOperation("Cat", "Val", null);
    Process process = op.createProcess(project, new Properties());
    HistoryEntry historyEntry = process.performImmediate();
    // Expected output from the GUI. 
    // ID;a;b;c;d
    // 1;1;3;;
    // 2;;4;5;
    // 3;2;5;;3
    Assert.assertEquals(project.columnModel.columns.size(), 5);
    Assert.assertEquals(project.columnModel.columns.get(0).getName(), "ID");
    Assert.assertEquals(project.columnModel.columns.get(1).getName(), "a");
    Assert.assertEquals(project.columnModel.columns.get(2).getName(), "b");
    Assert.assertEquals(project.columnModel.columns.get(3).getName(), "c");
    Assert.assertEquals(project.columnModel.columns.get(4).getName(), "d");
    Assert.assertEquals(project.rows.size(), 3);
    // The actual row data structure has to leave the columns model untouched for redo/undo purpose.
    // So we have 2 empty columns(column 1,2) on the row level.
    // 1;1;3;;
    Assert.assertEquals(project.rows.get(0).cells.get(0).value, "1");
    Assert.assertEquals(project.rows.get(0).cells.get(3).value, "1");
    Assert.assertEquals(project.rows.get(0).cells.get(4).value, "3");
    // 2;;4;5;
    Assert.assertEquals(project.rows.get(1).cells.get(0).value, "2");
    Assert.assertEquals(project.rows.get(1).cells.get(4).value, "4");
    Assert.assertEquals(project.rows.get(1).cells.get(5).value, "5");
    // 3;2;5;;3
    Assert.assertEquals(project.rows.get(2).cells.get(0).value, "3");
    Assert.assertEquals(project.rows.get(2).cells.get(3).value, "2");
    Assert.assertEquals(project.rows.get(2).cells.get(4).value, "5");
    Assert.assertEquals(project.rows.get(2).cells.get(6).value, "3");
}
Also used : AbstractOperation(com.google.refine.model.AbstractOperation) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) HistoryEntry(com.google.refine.history.HistoryEntry) Process(com.google.refine.process.Process) Properties(java.util.Properties) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) RefineTest(com.google.refine.tests.RefineTest)

Example 13 with Process

use of com.google.refine.process.Process in project OpenRefine by OpenRefine.

the class UrlFetchingTests method testUrlCaching.

/**
     * Test for caching
     */
@Test
public void testUrlCaching() throws Exception {
    for (int i = 0; i < 100; i++) {
        Row row = new Row(2);
        row.setCell(0, new Cell(i < 5 ? "apple" : "orange", null));
        project.rows.add(row);
    }
    EngineDependentOperation op = new ColumnAdditionByFetchingURLsOperation(engine_config, "fruits", "\"https://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new&city=\"+value", OnError.SetToBlank, "rand", 1, 500, true);
    ProcessManager pm = project.getProcessManager();
    Process process = op.createProcess(project, options);
    process.startPerforming(pm);
    Assert.assertTrue(process.isRunning());
    try {
        // We have 100 rows and 500 ms per row but only two distinct
        // values so we should not wait more than ~2000 ms to get the
        // results. Just to make sure the test passes with plenty of
        // net latency we sleep for longer (but still less than
        // 50,000ms).
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        Assert.fail("Test interrupted");
    }
    Assert.assertFalse(process.isRunning());
    // Inspect rows
    String ref_val = (String) project.rows.get(0).getCellValue(1);
    // just to make sure I picked the right column
    Assert.assertTrue(ref_val != "apple");
    for (int i = 1; i < 4; i++) {
        // all random values should be equal due to caching
        Assert.assertEquals(project.rows.get(i).getCellValue(1), ref_val);
    }
}
Also used : EngineDependentOperation(com.google.refine.operations.EngineDependentOperation) ColumnAdditionByFetchingURLsOperation(com.google.refine.operations.column.ColumnAdditionByFetchingURLsOperation) Process(com.google.refine.process.Process) Row(com.google.refine.model.Row) Cell(com.google.refine.model.Cell) ProcessManager(com.google.refine.process.ProcessManager) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) RefineTest(com.google.refine.tests.RefineTest)

Aggregations

Process (com.google.refine.process.Process)13 AbstractOperation (com.google.refine.model.AbstractOperation)12 Properties (java.util.Properties)12 IOException (java.io.IOException)11 ServletException (javax.servlet.ServletException)11 Project (com.google.refine.model.Project)10 RefineTest (com.google.refine.tests.RefineTest)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 HistoryEntry (com.google.refine.history.HistoryEntry)1 Cell (com.google.refine.model.Cell)1 Row (com.google.refine.model.Row)1 EngineDependentOperation (com.google.refine.operations.EngineDependentOperation)1 KeyValueColumnizeOperation (com.google.refine.operations.cell.KeyValueColumnizeOperation)1 MultiValuedCellJoinOperation (com.google.refine.operations.cell.MultiValuedCellJoinOperation)1 MultiValuedCellSplitOperation (com.google.refine.operations.cell.MultiValuedCellSplitOperation)1 TransposeColumnsIntoRowsOperation (com.google.refine.operations.cell.TransposeColumnsIntoRowsOperation)1 TransposeRowsIntoColumnsOperation (com.google.refine.operations.cell.TransposeRowsIntoColumnsOperation)1 ColumnAdditionByFetchingURLsOperation (com.google.refine.operations.column.ColumnAdditionByFetchingURLsOperation)1 ColumnMoveOperation (com.google.refine.operations.column.ColumnMoveOperation)1