Java Code Examples for org.datavec.api.transform.schema.Schema#hasColumn()

The following examples show how to use org.datavec.api.transform.schema.Schema#hasColumn() . 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: TimeWindowFunction.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Override
public void setInputSchema(Schema schema) {
    if (!(schema instanceof SequenceSchema))
        throw new IllegalArgumentException(
                        "Invalid schema: TimeWindowFunction can " + "only operate on SequenceSchema");
    if (!schema.hasColumn(timeColumn))
        throw new IllegalStateException("Input schema does not have a column with name \"" + timeColumn + "\"");

    if (schema.getMetaData(timeColumn).getColumnType() != ColumnType.Time)
        throw new IllegalStateException("Invalid column: column \"" + timeColumn + "\" is not of type "
                        + ColumnType.Time + "; is " + schema.getMetaData(timeColumn).getColumnType());

    this.inputSchema = schema;

    timeZone = ((TimeMetaData) schema.getMetaData(timeColumn)).getTimeZone();
}
 
Example 2
Source File: OverlappingTimeWindowFunction.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Override
public void setInputSchema(Schema schema) {
    if (!(schema instanceof SequenceSchema))
        throw new IllegalArgumentException(
                        "Invalid schema: OverlappingTimeWindowFunction can only operate on SequenceSchema");
    if (!schema.hasColumn(timeColumn))
        throw new IllegalStateException("Input schema does not have a column with name \"" + timeColumn + "\"");

    if (schema.getMetaData(timeColumn).getColumnType() != ColumnType.Time)
        throw new IllegalStateException("Invalid column: column \"" + timeColumn + "\" is not of type "
                        + ColumnType.Time + "; is " + schema.getMetaData(timeColumn).getColumnType());

    this.inputSchema = schema;

    timeZone = ((TimeMetaData) schema.getMetaData(timeColumn)).getTimeZone();
}
 
Example 3
Source File: TimeWindowFunction.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Override
public void setInputSchema(Schema schema) {
    if (!(schema instanceof SequenceSchema))
        throw new IllegalArgumentException(
                        "Invalid schema: TimeWindowFunction can " + "only operate on SequenceSchema");
    if (!schema.hasColumn(timeColumn))
        throw new IllegalStateException("Input schema does not have a column with name \"" + timeColumn + "\"");

    if (schema.getMetaData(timeColumn).getColumnType() != ColumnType.Time)
        throw new IllegalStateException("Invalid column: column \"" + timeColumn + "\" is not of type "
                        + ColumnType.Time + "; is " + schema.getMetaData(timeColumn).getColumnType());

    this.inputSchema = schema;

    timeZone = ((TimeMetaData) schema.getMetaData(timeColumn)).getTimeZone();
}
 
Example 4
Source File: ConcatenateStringColumns.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Override
public void setInputSchema(Schema inputSchema) {
    for (String s : columnsToConcatenate) {
        if (!inputSchema.hasColumn(s)) {
            throw new IllegalStateException("Input schema does not contain column with name \"" + s + "\"");
        }
    }
    this.inputSchema = inputSchema;
}
 
Example 5
Source File: ConditionalCopyValueTransform.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public void setInputSchema(Schema inputSchema) {
    if (!inputSchema.hasColumn(columnToReplace))
        throw new IllegalStateException("Column \"" + columnToReplace + "\" not found in input schema");
    if (!inputSchema.hasColumn(sourceColumn))
        throw new IllegalStateException("Column \"" + sourceColumn + "\" not found in input schema");
    columnToReplaceIdx = inputSchema.getIndexOfColumn(columnToReplace);
    sourceColumnIdx = inputSchema.getIndexOfColumn(sourceColumn);
    condition.setInputSchema(inputSchema);
}
 
Example 6
Source File: SequenceDifferenceTransform.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public void setInputSchema(Schema inputSchema) {
    if (!inputSchema.hasColumn(columnName)) {
        throw new IllegalStateException("Invalid input schema: does not have column with name \"" + columnName
                        + "\"\n. All schema names: " + inputSchema.getColumnNames());
    }

    this.columnType = inputSchema.getMetaData(columnName).getColumnType();
    this.inputSchema = inputSchema;
}
 
Example 7
Source File: BaseColumnsMathOpTransform.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public void setInputSchema(Schema inputSchema) {
    columnIdxs = new int[columns.length];
    int i = 0;
    for (String name : columns) {
        if (!inputSchema.hasColumn(name))
            throw new IllegalStateException("Input schema does not have column with name \"" + name + "\"");
        columnIdxs[i++] = inputSchema.getIndexOfColumn(name);
    }

    this.inputSchema = inputSchema;
}
 
Example 8
Source File: BaseColumnsMathOpTransform.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public Schema transform(Schema inputSchema) {
    for (String name : columns) {
        if (!inputSchema.hasColumn(name))
            throw new IllegalStateException("Input schema does not have column with name \"" + name + "\"");
    }

    List<ColumnMetaData> newMeta = new ArrayList<>(inputSchema.getColumnMetaData());

    newMeta.add(derivedColumnMetaData(newColumnName, inputSchema));

    return inputSchema.newSchema(newMeta);
}
 
Example 9
Source File: ConcatenateStringColumns.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public void setInputSchema(Schema inputSchema) {
    for (String s : columnsToConcatenate) {
        if (!inputSchema.hasColumn(s)) {
            throw new IllegalStateException("Input schema does not contain column with name \"" + s + "\"");
        }
    }
    this.inputSchema = inputSchema;
}
 
Example 10
Source File: ConcatenateStringColumns.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public Schema transform(Schema inputSchema) {
    for (String s : columnsToConcatenate) {
        if (!inputSchema.hasColumn(s)) {
            throw new IllegalStateException("Input schema does not contain column with name \"" + s + "\"");
        }
    }

    List<ColumnMetaData> outMeta = new ArrayList<>();
    outMeta.addAll(inputSchema.getColumnMetaData());

    ColumnMetaData newColMeta = ColumnType.String.newColumnMetaData(newColumnName);
    outMeta.add(newColMeta);
    return inputSchema.newSchema(outMeta);
}
 
Example 11
Source File: SequenceSplitTimeSeparation.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Override
public void setInputSchema(Schema inputSchema) {
    if (!inputSchema.hasColumn(timeColumn))
        throw new IllegalStateException(
                        "Invalid state: schema does not have column " + "with name \"" + timeColumn + "\"");
    if (inputSchema.getMetaData(timeColumn).getColumnType() != ColumnType.Time) {
        throw new IllegalStateException("Invalid input schema: schema column \"" + timeColumn
                        + "\" is not a time column." + " (Is type: "
                        + inputSchema.getMetaData(timeColumn).getColumnType() + ")");
    }

    this.timeColumnIdx = inputSchema.getIndexOfColumn(timeColumn);
    this.schema = inputSchema;
}
 
Example 12
Source File: NDArrayDistanceTransform.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Override
public void setInputSchema(Schema inputSchema) {
    if (!inputSchema.hasColumn(firstCol)) {
        throw new IllegalStateException("Input schema does not have first column: " + firstCol);
    }
    if (!inputSchema.hasColumn(secondCol)) {
        throw new IllegalStateException("Input schema does not have first column: " + secondCol);
    }

    this.inputSchema = inputSchema;
}
 
Example 13
Source File: NDArrayDistanceTransform.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public void setInputSchema(Schema inputSchema) {
    if (!inputSchema.hasColumn(firstCol)) {
        throw new IllegalStateException("Input schema does not have first column: " + firstCol);
    }
    if (!inputSchema.hasColumn(secondCol)) {
        throw new IllegalStateException("Input schema does not have first column: " + secondCol);
    }

    this.inputSchema = inputSchema;
}
 
Example 14
Source File: ConditionalCopyValueTransform.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Override
public void setInputSchema(Schema inputSchema) {
    if (!inputSchema.hasColumn(columnToReplace))
        throw new IllegalStateException("Column \"" + columnToReplace + "\" not found in input schema");
    if (!inputSchema.hasColumn(sourceColumn))
        throw new IllegalStateException("Column \"" + sourceColumn + "\" not found in input schema");
    columnToReplaceIdx = inputSchema.getIndexOfColumn(columnToReplace);
    sourceColumnIdx = inputSchema.getIndexOfColumn(sourceColumn);
    condition.setInputSchema(inputSchema);
}
 
Example 15
Source File: SequenceDifferenceTransform.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Override
public void setInputSchema(Schema inputSchema) {
    if (!inputSchema.hasColumn(columnName)) {
        throw new IllegalStateException("Invalid input schema: does not have column with name \"" + columnName
                        + "\"\n. All schema names: " + inputSchema.getColumnNames());
    }

    this.columnType = inputSchema.getMetaData(columnName).getColumnType();
    this.inputSchema = inputSchema;
}
 
Example 16
Source File: SequenceSplitTimeSeparation.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public void setInputSchema(Schema inputSchema) {
    if (!inputSchema.hasColumn(timeColumn))
        throw new IllegalStateException(
                        "Invalid state: schema does not have column " + "with name \"" + timeColumn + "\"");
    if (inputSchema.getMetaData(timeColumn).getColumnType() != ColumnType.Time) {
        throw new IllegalStateException("Invalid input schema: schema column \"" + timeColumn
                        + "\" is not a time column." + " (Is type: "
                        + inputSchema.getMetaData(timeColumn).getColumnType() + ")");
    }

    this.timeColumnIdx = inputSchema.getIndexOfColumn(timeColumn);
    this.schema = inputSchema;
}
 
Example 17
Source File: BaseColumnsMathOpTransform.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Override
public Schema transform(Schema inputSchema) {
    for (String name : columns) {
        if (!inputSchema.hasColumn(name))
            throw new IllegalStateException("Input schema does not have column with name \"" + name + "\"");
    }

    List<ColumnMetaData> newMeta = new ArrayList<>(inputSchema.getColumnMetaData());

    newMeta.add(derivedColumnMetaData(newColumnName, inputSchema));

    return inputSchema.newSchema(newMeta);
}
 
Example 18
Source File: ConcatenateStringColumns.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Override
public Schema transform(Schema inputSchema) {
    for (String s : columnsToConcatenate) {
        if (!inputSchema.hasColumn(s)) {
            throw new IllegalStateException("Input schema does not contain column with name \"" + s + "\"");
        }
    }

    List<ColumnMetaData> outMeta = new ArrayList<>();
    outMeta.addAll(inputSchema.getColumnMetaData());

    ColumnMetaData newColMeta = ColumnType.String.newColumnMetaData(newColumnName);
    outMeta.add(newColMeta);
    return inputSchema.newSchema(outMeta);
}
 
Example 19
Source File: SequenceDifferenceTransform.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public Schema transform(Schema inputSchema) {
    if (!inputSchema.hasColumn(columnName)) {
        throw new IllegalStateException("Invalid input schema: does not have column with name \"" + columnName
                        + "\"\n. All schema names: " + inputSchema.getColumnNames());
    }
    if (!(inputSchema instanceof SequenceSchema)) {
        throw new IllegalStateException(
                        "Invalid input schema: expected a SequenceSchema, got " + inputSchema.getClass());
    }

    List<ColumnMetaData> newMeta = new ArrayList<>(inputSchema.numColumns());
    for (ColumnMetaData m : inputSchema.getColumnMetaData()) {
        if (columnName.equals(m.getName())) {
            switch (m.getColumnType()) {
                case Integer:
                    newMeta.add(new IntegerMetaData(newColumnName));
                    break;
                case Long:
                    newMeta.add(new LongMetaData(newColumnName));
                    break;
                case Double:
                    newMeta.add(new DoubleMetaData(newColumnName));
                    break;
                case Float:
                    newMeta.add(new FloatMetaData(newColumnName));
                    break;
                case Time:
                    newMeta.add(new LongMetaData(newColumnName)); //not Time - time column isn't used for duration...
                    break;
                case Categorical:
                case Bytes:
                case String:
                case Boolean:
                default:
                    throw new IllegalStateException(
                                    "Cannot perform sequence difference on column of type " + m.getColumnType());
            }
        } else {
            newMeta.add(m);
        }
    }

    return inputSchema.newSchema(newMeta);
}
 
Example 20
Source File: PivotTransform.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@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);
}