Java Code Examples for org.datavec.api.transform.metadata.ColumnMetaData#clone()
The following examples show how to use
org.datavec.api.transform.metadata.ColumnMetaData#clone() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringReducer.java From DataVec with Apache License 2.0 | 6 votes |
private static ColumnMetaData getMetaForColumn(StringReduceOp op, String name, ColumnMetaData inMeta) { inMeta = inMeta.clone(); switch (op) { case PREPEND: inMeta.setName("prepend(" + name + ")"); return inMeta; case APPEND: inMeta.setName("append(" + name + ")"); return inMeta; case REPLACE: inMeta.setName("replace(" + name + ")"); return inMeta; case MERGE: inMeta.setName("merge(" + name + ")"); return inMeta; default: throw new UnsupportedOperationException("Unknown or not implemented op: " + op); } }
Example 2
Source File: StringReducer.java From deeplearning4j with Apache License 2.0 | 6 votes |
private static ColumnMetaData getMetaForColumn(StringReduceOp op, String name, ColumnMetaData inMeta) { inMeta = inMeta.clone(); switch (op) { case PREPEND: inMeta.setName("prepend(" + name + ")"); return inMeta; case APPEND: inMeta.setName("append(" + name + ")"); return inMeta; case REPLACE: inMeta.setName("replace(" + name + ")"); return inMeta; case MERGE: inMeta.setName("merge(" + name + ")"); return inMeta; default: throw new UnsupportedOperationException("Unknown or not implemented op: " + op); } }
Example 3
Source File: BaseDoubleTransform.java From DataVec with Apache License 2.0 | 5 votes |
@Override public ColumnMetaData getNewColumnMetaData(String newColumnName, ColumnMetaData oldColumnMeta) { if (oldColumnMeta instanceof DoubleMetaData) { ColumnMetaData meta = oldColumnMeta.clone(); meta.setName(newColumnName); return meta; } else return new DoubleMetaData(newColumnName); }
Example 4
Source File: SequenceMovingWindowReduceTransform.java From DataVec with Apache License 2.0 | 5 votes |
@Override public Schema transform(Schema inputSchema) { int colIdx = inputSchema.getIndexOfColumn(columnName); //Approach here: The reducer gives us a schema for one time step -> simply convert this to a sequence schema... List<ColumnMetaData> oldMeta = inputSchema.getColumnMetaData(); List<ColumnMetaData> meta = new ArrayList<>(oldMeta); ColumnMetaData m; switch (op) { case Min: case Max: case Range: case TakeFirst: case TakeLast: //Same type as input m = oldMeta.get(colIdx); m = m.clone(); m.setName(newColumnName); break; case Prod: case Sum: case Mean: case Stdev: //Double type m = new DoubleMetaData(newColumnName); break; case Count: case CountUnique: //Integer type m = new IntegerMetaData(newColumnName); break; default: throw new UnsupportedOperationException("Unknown op type: " + op); } meta.add(m); return new SequenceSchema(meta); }
Example 5
Source File: BaseFloatTransform.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public ColumnMetaData getNewColumnMetaData(String newColumnName, ColumnMetaData oldColumnMeta) { if (oldColumnMeta instanceof FloatMetaData) { ColumnMetaData meta = oldColumnMeta.clone(); meta.setName(newColumnName); return meta; } else return new FloatMetaData(newColumnName); }
Example 6
Source File: BaseDoubleTransform.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public ColumnMetaData getNewColumnMetaData(String newColumnName, ColumnMetaData oldColumnMeta) { if (oldColumnMeta instanceof DoubleMetaData) { ColumnMetaData meta = oldColumnMeta.clone(); meta.setName(newColumnName); return meta; } else return new DoubleMetaData(newColumnName); }
Example 7
Source File: SequenceMovingWindowReduceTransform.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public Schema transform(Schema inputSchema) { int colIdx = inputSchema.getIndexOfColumn(columnName); //Approach here: The reducer gives us a schema for one time step -> simply convert this to a sequence schema... List<ColumnMetaData> oldMeta = inputSchema.getColumnMetaData(); List<ColumnMetaData> meta = new ArrayList<>(oldMeta); ColumnMetaData m; switch (op) { case Min: case Max: case Range: case TakeFirst: case TakeLast: //Same type as input m = oldMeta.get(colIdx); m = m.clone(); m.setName(newColumnName); break; case Prod: case Sum: case Mean: case Stdev: //Double type m = new DoubleMetaData(newColumnName); break; case Count: case CountUnique: //Integer type m = new IntegerMetaData(newColumnName); break; default: throw new UnsupportedOperationException("Unknown op type: " + op); } meta.add(m); return new SequenceSchema(meta); }
Example 8
Source File: BaseIntegerTransform.java From DataVec with Apache License 2.0 | 4 votes |
@Override public ColumnMetaData getNewColumnMetaData(String newName, ColumnMetaData oldColumnMeta) { ColumnMetaData meta = oldColumnMeta.clone(); meta.setName(newName); return meta; }
Example 9
Source File: PivotTransform.java From DataVec with Apache License 2.0 | 4 votes |
@Override public Schema transform(Schema inputSchema) { if (!inputSchema.hasColumn(keyColumn) || !inputSchema.hasColumn(valueColumn)) { throw new UnsupportedOperationException("Key or value column not found: " + keyColumn + ", " + valueColumn + " in " + inputSchema.getColumnNames()); } List<String> origNames = inputSchema.getColumnNames(); List<ColumnMetaData> origMeta = inputSchema.getColumnMetaData(); int i = 0; Iterator<String> namesIter = origNames.iterator(); Iterator<ColumnMetaData> typesIter = origMeta.iterator(); List<ColumnMetaData> newMeta = new ArrayList<>(inputSchema.numColumns()); int idxKey = inputSchema.getIndexOfColumn(keyColumn); int idxValue = inputSchema.getIndexOfColumn(valueColumn); ColumnMetaData valueMeta = inputSchema.getMetaData(idxValue); while (namesIter.hasNext()) { String s = namesIter.next(); ColumnMetaData t = typesIter.next(); if (i == idxKey) { //Convert this to a set of separate columns List<String> stateNames = ((CategoricalMetaData) inputSchema.getMetaData(idxKey)).getStateNames(); for (String stateName : stateNames) { String newName = s + "[" + stateName + "]"; ColumnMetaData newValueMeta = valueMeta.clone(); newValueMeta.setName(newName); newMeta.add(newValueMeta); } } else if (i == idxValue) { i++; continue; //Skip column } else { newMeta.add(t); } i++; } //Infer the default value if necessary if (defaultValue == null) { switch (valueMeta.getColumnType()) { case String: defaultValue = new Text(""); break; case Integer: defaultValue = new IntWritable(0); break; case Long: defaultValue = new LongWritable(0); break; case Double: defaultValue = new DoubleWritable(0.0); break; case Float: defaultValue = new FloatWritable(0.0f); break; case Categorical: defaultValue = new NullWritable(); break; case Time: defaultValue = new LongWritable(0); break; case Bytes: throw new UnsupportedOperationException("Cannot infer default value for bytes"); case Boolean: defaultValue = new Text("false"); break; default: throw new UnsupportedOperationException( "Cannot infer default value for " + valueMeta.getColumnType()); } } return inputSchema.newSchema(newMeta); }
Example 10
Source File: NDArrayMathFunctionTransform.java From DataVec with Apache License 2.0 | 4 votes |
@Override public ColumnMetaData getNewColumnMetaData(String newName, ColumnMetaData oldColumnType) { ColumnMetaData m = oldColumnType.clone(); m.setName(newName); return m; }
Example 11
Source File: BaseIntegerTransform.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public ColumnMetaData getNewColumnMetaData(String newName, ColumnMetaData oldColumnMeta) { ColumnMetaData meta = oldColumnMeta.clone(); meta.setName(newName); return meta; }
Example 12
Source File: PivotTransform.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public Schema transform(Schema inputSchema) { if (!inputSchema.hasColumn(keyColumn) || !inputSchema.hasColumn(valueColumn)) { throw new UnsupportedOperationException("Key or value column not found: " + keyColumn + ", " + valueColumn + " in " + inputSchema.getColumnNames()); } List<String> origNames = inputSchema.getColumnNames(); List<ColumnMetaData> origMeta = inputSchema.getColumnMetaData(); int i = 0; Iterator<String> namesIter = origNames.iterator(); Iterator<ColumnMetaData> typesIter = origMeta.iterator(); List<ColumnMetaData> newMeta = new ArrayList<>(inputSchema.numColumns()); int idxKey = inputSchema.getIndexOfColumn(keyColumn); int idxValue = inputSchema.getIndexOfColumn(valueColumn); ColumnMetaData valueMeta = inputSchema.getMetaData(idxValue); while (namesIter.hasNext()) { String s = namesIter.next(); ColumnMetaData t = typesIter.next(); if (i == idxKey) { //Convert this to a set of separate columns List<String> stateNames = ((CategoricalMetaData) inputSchema.getMetaData(idxKey)).getStateNames(); for (String stateName : stateNames) { String newName = s + "[" + stateName + "]"; ColumnMetaData newValueMeta = valueMeta.clone(); newValueMeta.setName(newName); newMeta.add(newValueMeta); } } else if (i == idxValue) { i++; continue; //Skip column } else { newMeta.add(t); } i++; } //Infer the default value if necessary if (defaultValue == null) { switch (valueMeta.getColumnType()) { case String: defaultValue = new Text(""); break; case Integer: defaultValue = new IntWritable(0); break; case Long: defaultValue = new LongWritable(0); break; case Double: defaultValue = new DoubleWritable(0.0); break; case Float: defaultValue = new FloatWritable(0.0f); break; case Categorical: defaultValue = new NullWritable(); break; case Time: defaultValue = new LongWritable(0); break; case Bytes: throw new UnsupportedOperationException("Cannot infer default value for bytes"); case Boolean: defaultValue = new Text("false"); break; default: throw new UnsupportedOperationException( "Cannot infer default value for " + valueMeta.getColumnType()); } } return inputSchema.newSchema(newMeta); }
Example 13
Source File: NDArrayMathFunctionTransform.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public ColumnMetaData getNewColumnMetaData(String newName, ColumnMetaData oldColumnType) { ColumnMetaData m = oldColumnType.clone(); m.setName(newName); return m; }