Package org.openrefine.operations
Class RowMapOperation
- java.lang.Object
-
- org.openrefine.operations.EngineDependentOperation
-
- org.openrefine.operations.RowMapOperation
-
- All Implemented Interfaces:
Operation
- Direct Known Subclasses:
ColumnMoveOperation
,ColumnRemovalOperation
,ColumnRenameOperation
,ColumnReorderOperation
,ColumnSplitOperation
,ExpressionBasedOperation
,ReconClearSimilarCellsOperation
,ReconCopyAcrossColumnsOperation
,ReconDiscardJudgmentsOperation
,ReconJudgeSimilarCellsOperation
,ReconMarkNewTopicsOperation
,ReconMatchBestCandidatesOperation
,ReconMatchSpecificTopicOperation
,ReconUseValuesAsIdentifiersOperation
,RowFlagOperation
,RowStarOperation
public abstract class RowMapOperation extends EngineDependentOperation
Simplifies the architecture for immediate operations which simply act by mapping rows. This allows the mapper to be defined in a method of the operation. This class can also be subclassed by operations which ignore the engine, by initializing the engine config withEngineConfig.ALL_ROWS
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RowMapOperation.GridMap
Stores the new column model to be applied on the new grid, and the row mappers used to derive the new grid.
-
Field Summary
-
Fields inherited from class org.openrefine.operations.EngineDependentOperation
_engineConfig
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
RowMapOperation(EngineConfig engineConfig)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ChangeResult
apply(Grid projectState, ChangeContext context)
Derives the new grid state from the current grid state.protected RowMapOperation.GridMap
getGridMap(Grid state, ChangeContext context)
Returns the function that is applied to each row and row index, the new column model applied to the grid, and the new overlay models.protected RowInRecordMapper
getNegativeRowMapper(Grid state, ChangeContext context)
Returns the row mapper applied to the rows not matched by the filter.protected ColumnModel
getNewColumnModel(Grid state, ChangeContext context)
Returns the column model after the change is applied to the given grid.protected Map<String,OverlayModel>
getNewOverlayModels(Grid state, ChangeContext context)
Returns the new overlay models after this change is applied.protected RowInRecordMapper
getPositiveRowMapper(Grid state, ChangeContext context)
Returns the row mapper applied to the rows matched by the filter.protected Grid
postTransform(Grid grid, ChangeContext context)
Method run at the end of the change to update any statistics (such as ReconStats or overlay models) on the resulting state.-
Methods inherited from class org.openrefine.operations.EngineDependentOperation
getEngine, getEngineConfig
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openrefine.operations.Operation
getDescription, getOperationId, isReproducible
-
-
-
-
Constructor Detail
-
RowMapOperation
protected RowMapOperation(EngineConfig engineConfig)
-
-
Method Detail
-
apply
public ChangeResult apply(Grid projectState, ChangeContext context) throws OperationException
Description copied from interface:Operation
Derives the new grid state from the current grid state. Executing this method should be quick (even on large datasets) since it is expected to just derive the new grid from the existing one without actually executing any expensive computation. Long-running computations should rather go in the derivation of aChangeData
which will be fetched asynchronously.- Parameters:
projectState
- the state of the grid before the change- Returns:
- an object which bundles up various pieces of information produced by the operation: primarily, the new grid after applying the operation. This object can be subclassed to expose more information, which should be serializable with Jackson so that it reaches the frontend.
- Throws:
OperationException
- when the change cannot be applied to the given grid
-
getGridMap
protected RowMapOperation.GridMap getGridMap(Grid state, ChangeContext context) throws OperationException
Returns the function that is applied to each row and row index, the new column model applied to the grid, and the new overlay models. Computing these in one go can be useful in certain situations, for instance when the number of columns added to the column model depends on the data. If a subclass needs to return only one non-default value out of mapper, column model and overlay models it can instead override the corresponding method.- Parameters:
state
- the initial column model- Throws:
OperationException
- if the change does not apply to the given grid
-
getNewColumnModel
protected ColumnModel getNewColumnModel(Grid state, ChangeContext context) throws OperationException
Returns the column model after the change is applied to the given grid. By default, returns the same column model.- Parameters:
state
- the grid to which the change should be applied- Returns:
- the column model of the new grid
- Throws:
OperationException
-
getPositiveRowMapper
protected RowInRecordMapper getPositiveRowMapper(Grid state, ChangeContext context) throws OperationException
Returns the row mapper applied to the rows matched by the filter.- Parameters:
state
- the initial state of the grid- Throws:
OperationException
-
getNegativeRowMapper
protected RowInRecordMapper getNegativeRowMapper(Grid state, ChangeContext context) throws OperationException
Returns the row mapper applied to the rows not matched by the filter.- Parameters:
state
- the initial state of the grid- Throws:
OperationException
-
getNewOverlayModels
protected Map<String,OverlayModel> getNewOverlayModels(Grid state, ChangeContext context) throws OperationException
Returns the new overlay models after this change is applied.- Throws:
OperationException
-
postTransform
protected Grid postTransform(Grid grid, ChangeContext context) throws OperationException
Method run at the end of the change to update any statistics (such as ReconStats or overlay models) on the resulting state.- Parameters:
grid
- the grid after the map operation- Returns:
- the grid with updated column statistics (or any other post transformation)
- Throws:
OperationException
-
-