use of de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection in project elki by elki-project.
the class SparseNumberVectorLabelParserTest method parameters.
@Test
public void parameters() throws IOException {
String filename = UNITTEST + "parsertest.sparse";
Parser parser = //
new ELKIBuilder<>(SparseNumberVectorLabelParser.class).with(NumberVectorLabelParser.Parameterizer.VECTOR_TYPE_ID, //
SparseDoubleVector.Factory.class).build();
MultipleObjectsBundle bundle;
try (InputStream is = open(filename);
InputStreamDatabaseConnection dbc = new InputStreamDatabaseConnection(is, null, parser)) {
bundle = dbc.loadData();
}
// Ensure that the filter has correctly formed the bundle.
// We expect that the bundle's first column is a number vector field.
// We expect that the bundle's second column is a LabelList
// Ensure the first column are the vectors.
assertTrue("Test file not as expected", TypeUtil.SPARSE_VECTOR_VARIABLE_LENGTH.isAssignableFromType(bundle.meta(0)));
assertTrue("Test file not as expected", TypeUtil.LABELLIST.isAssignableFromType(bundle.meta(1)));
assertEquals("Length", 3, bundle.dataLength());
assertEquals("Length", 4, ((SparseNumberVector) bundle.data(0, 0)).getDimensionality());
// Ensure that the third column are the LabelList objects.
assertEquals("Unexpected data type", SparseDoubleVector.class, bundle.data(0, 0).getClass());
assertEquals("Unexpected data type", LabelList.class, bundle.data(0, 1).getClass());
}
use of de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection in project elki by elki-project.
the class TermFrequencyParserTest method parameters.
@Test
public void parameters() throws IOException {
String filename = UNITTEST + "parsertest.tf";
Parser parser = //
new ELKIBuilder<>(TermFrequencyParser.class).with(//
TermFrequencyParser.Parameterizer.NORMALIZE_FLAG).build();
MultipleObjectsBundle bundle;
try (InputStream is = open(filename);
InputStreamDatabaseConnection dbc = new InputStreamDatabaseConnection(is, null, parser)) {
bundle = dbc.loadData();
}
// Ensure that the filter has correctly formed the bundle.
// We expect that the bundle's first column is a number vector field.
// We expect that the bundle's second column is a LabelList
// Ensure the first column are the vectors.
assertTrue("Test file not as expected", TypeUtil.SPARSE_VECTOR_VARIABLE_LENGTH.isAssignableFromType(bundle.meta(0)));
assertTrue("Test file not as expected", TypeUtil.LABELLIST.isAssignableFromType(bundle.meta(1)));
assertEquals("Length", 2, bundle.dataLength());
assertEquals("Length", 2, ((SparseNumberVector) bundle.data(0, 0)).getDimensionality());
assertEquals("Length", 4, ((SparseNumberVector) bundle.data(1, 0)).getDimensionality());
// TODO: the map of words to columns is currently NOT kept.
// Add this, and test this.
// Ensure that the third column are the LabelList objects.
assertEquals("Unexpected data type", SparseFloatVector.class, bundle.data(0, 0).getClass());
assertEquals("Unexpected data type", LabelList.class, bundle.data(0, 1).getClass());
}
use of de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection in project elki by elki-project.
the class AbstractFrequentItemsetAlgorithmTest method loadTransactions.
/**
* Load a transaction database.
*
* @param filename Filename
* @param expectedSize Expected size
* @return Database
*/
public static <T> Database loadTransactions(String filename, int expectedSize) {
// Allow loading test data from resources.
try (InputStream is = open(filename)) {
// Instantiate filters manually. TODO: redesign
List<ObjectFilter> filterlist = new ArrayList<>();
filterlist.add(new FixedDBIDsFilter(1));
// Setup parser and data loading
SimpleTransactionParser parser = new SimpleTransactionParser(CSVReaderFormat.DEFAULT_FORMAT);
InputStreamDatabaseConnection dbc = new InputStreamDatabaseConnection(is, filterlist, parser);
// We want to allow the use of indexes via "params"
Database db = //
new ELKIBuilder<>(StaticArrayDatabase.class).with(AbstractDatabase.Parameterizer.DATABASE_CONNECTION_ID, dbc).build();
db.initialize();
Relation<?> rel = db.getRelation(TypeUtil.ANY);
if (expectedSize > 0) {
assertEquals("Database size does not match.", expectedSize, rel.size());
}
return db;
} catch (IOException e) {
fail("Test data " + filename + " not found.");
// Not reached.
return null;
}
}
Aggregations