Search in sources :

Example 1 with SimpleTransactionParser

use of de.lmu.ifi.dbs.elki.datasource.parser.SimpleTransactionParser 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;
    }
}
Also used : FixedDBIDsFilter(de.lmu.ifi.dbs.elki.datasource.filter.FixedDBIDsFilter) InputStream(java.io.InputStream) ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) ArrayList(java.util.ArrayList) SimpleTransactionParser(de.lmu.ifi.dbs.elki.datasource.parser.SimpleTransactionParser) Database(de.lmu.ifi.dbs.elki.database.Database) AbstractDatabase(de.lmu.ifi.dbs.elki.database.AbstractDatabase) StaticArrayDatabase(de.lmu.ifi.dbs.elki.database.StaticArrayDatabase) ObjectFilter(de.lmu.ifi.dbs.elki.datasource.filter.ObjectFilter) InputStreamDatabaseConnection(de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection) IOException(java.io.IOException)

Aggregations

AbstractDatabase (de.lmu.ifi.dbs.elki.database.AbstractDatabase)1 Database (de.lmu.ifi.dbs.elki.database.Database)1 StaticArrayDatabase (de.lmu.ifi.dbs.elki.database.StaticArrayDatabase)1 InputStreamDatabaseConnection (de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection)1 FixedDBIDsFilter (de.lmu.ifi.dbs.elki.datasource.filter.FixedDBIDsFilter)1 ObjectFilter (de.lmu.ifi.dbs.elki.datasource.filter.ObjectFilter)1 SimpleTransactionParser (de.lmu.ifi.dbs.elki.datasource.parser.SimpleTransactionParser)1 ELKIBuilder (de.lmu.ifi.dbs.elki.utilities.ELKIBuilder)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1