Java Code Examples for org.datavec.api.transform.metadata.ColumnMetaData#isValid()
The following examples show how to use
org.datavec.api.transform.metadata.ColumnMetaData#isValid() .
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: FilterInvalidValues.java From DataVec with Apache License 2.0 | 6 votes |
private boolean filterColumn(List<?> row, int i) { ColumnMetaData meta = schema.getMetaData(i); if (row.get(i) instanceof Float) { if (!meta.isValid(new FloatWritable((Float) row.get(i)))) return true; } else if (row.get(i) instanceof Double) { if (!meta.isValid(new DoubleWritable((Double) row.get(i)))) return true; } else if (row.get(i) instanceof String) { if (!meta.isValid(new Text(((String) row.get(i)).toString()))) return true; } else if (row.get(i) instanceof Integer) { if (!meta.isValid(new IntWritable((Integer) row.get(i)))) return true; } else if (row.get(i) instanceof Long) { if (!meta.isValid(new LongWritable((Long) row.get(i)))) return true; } else if (row.get(i) instanceof Boolean) { if (!meta.isValid(new BooleanWritable((Boolean) row.get(i)))) return true; } return false; }
Example 2
Source File: FilterInvalidValues.java From deeplearning4j with Apache License 2.0 | 6 votes |
private boolean filterColumn(List<?> row, int i) { ColumnMetaData meta = schema.getMetaData(i); if (row.get(i) instanceof Float) { if (!meta.isValid(new FloatWritable((Float) row.get(i)))) return true; } else if (row.get(i) instanceof Double) { if (!meta.isValid(new DoubleWritable((Double) row.get(i)))) return true; } else if (row.get(i) instanceof String) { if (!meta.isValid(new Text(((String) row.get(i)).toString()))) return true; } else if (row.get(i) instanceof Integer) { if (!meta.isValid(new IntWritable((Integer) row.get(i)))) return true; } else if (row.get(i) instanceof Long) { if (!meta.isValid(new LongWritable((Long) row.get(i)))) return true; } else if (row.get(i) instanceof Boolean) { if (!meta.isValid(new BooleanWritable((Boolean) row.get(i)))) return true; } return false; }
Example 3
Source File: RecordConverter.java From deeplearning4j with Apache License 2.0 | 4 votes |
/** * Convert a collection into a `List<Writable>`, i.e. a record that can be used with other datavec methods. * Uses a schema to decide what kind of writable to use. * * @return a record */ public static List<Writable> toRecord(Schema schema, List<Object> source){ final List<Writable> record = new ArrayList<>(source.size()); final List<ColumnMetaData> columnMetaData = schema.getColumnMetaData(); if(columnMetaData.size() != source.size()){ throw new IllegalArgumentException("Schema and source list don't have the same length!"); } for (int i = 0; i < columnMetaData.size(); i++) { final ColumnMetaData metaData = columnMetaData.get(i); final Object data = source.get(i); if(!metaData.isValid(data)){ throw new IllegalArgumentException("Element "+i+": "+data+" is not valid for Column \""+metaData.getName()+"\" ("+metaData.getColumnType()+")"); } try { final Writable writable; switch (metaData.getColumnType().getWritableType()){ case Float: writable = new FloatWritable((Float) data); break; case Double: writable = new DoubleWritable((Double) data); break; case Int: writable = new IntWritable((Integer) data); break; case Byte: writable = new ByteWritable((Byte) data); break; case Boolean: writable = new BooleanWritable((Boolean) data); break; case Long: writable = new LongWritable((Long) data); break; case Null: writable = new NullWritable(); break; case Bytes: writable = new BytesWritable((byte[]) data); break; case NDArray: writable = new NDArrayWritable((INDArray) data); break; case Text: if(data instanceof String) writable = new Text((String) data); else if(data instanceof Text) writable = new Text((Text) data); else if(data instanceof byte[]) writable = new Text((byte[]) data); else throw new IllegalArgumentException("Element "+i+": "+data+" is not usable for Column \""+metaData.getName()+"\" ("+metaData.getColumnType()+")"); break; default: throw new IllegalArgumentException("Element "+i+": "+data+" is not usable for Column \""+metaData.getName()+"\" ("+metaData.getColumnType()+")"); } record.add(writable); } catch (ClassCastException e) { throw new IllegalArgumentException("Element "+i+": "+data+" is not usable for Column \""+metaData.getName()+"\" ("+metaData.getColumnType()+")", e); } } return record; }