Search in sources :

Example 1 with CSVInstanceReader

use of eu.esdihumboldt.hale.io.csv.reader.internal.CSVInstanceReader in project hale by halestudio.

the class CSVInstanceReaderTest method readCSVInstances.

private InstanceCollection readCSVInstances(String sourceLocation, String typeName, boolean skipFirst, Schema sourceSchema, String seperator, String quote, String escape, String decimal) throws Exception {
    InstanceReader instanceReader = new CSVInstanceReader();
    instanceReader.setSource(new DefaultInputSupplier(getClass().getResource(sourceLocation).toURI()));
    instanceReader.setParameter(CommonSchemaConstants.PARAM_TYPENAME, Value.of(typeName));
    instanceReader.setParameter(CommonSchemaConstants.PARAM_SKIP_FIRST_LINE, Value.of(skipFirst));
    instanceReader.setParameter(CSVSchemaReader.PARAM_SEPARATOR, Value.of(seperator));
    instanceReader.setParameter(CSVSchemaReader.PARAM_QUOTE, Value.of(quote));
    instanceReader.setParameter(CSVSchemaReader.PARAM_ESCAPE, Value.of(escape));
    instanceReader.setParameter(CSVSchemaReader.PARAM_DECIMAL, Value.of(decimal));
    instanceReader.setSourceSchema(sourceSchema);
    // Test instances
    IOReport report = instanceReader.execute(null);
    assertTrue("Data import was not successfull.", report.isSuccess());
    return instanceReader.getInstances();
}
Also used : CSVInstanceReader(eu.esdihumboldt.hale.io.csv.reader.internal.CSVInstanceReader) InstanceReader(eu.esdihumboldt.hale.common.instance.io.InstanceReader) CSVInstanceReader(eu.esdihumboldt.hale.io.csv.reader.internal.CSVInstanceReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Aggregations

IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)1 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)1 InstanceReader (eu.esdihumboldt.hale.common.instance.io.InstanceReader)1 CSVInstanceReader (eu.esdihumboldt.hale.io.csv.reader.internal.CSVInstanceReader)1