Search in sources :

Example 1 with ObjectFilter

use of de.lmu.ifi.dbs.elki.datasource.filter.ObjectFilter in project elki by elki-project.

the class AbstractDatabaseConnection method invokeStreamFilters.

/**
 * Transforms the specified list of objects and their labels into a list of
 * objects and their associations.
 *
 * @param stream the objects to process
 * @return processed objects
 */
protected BundleStreamSource invokeStreamFilters(BundleStreamSource stream) {
    if (filters == null) {
        return stream;
    }
    // We dynamically switch between streaming and bundle operations.
    MultipleObjectsBundle bundle = null;
    for (ObjectFilter filter : filters) {
        if (filter instanceof StreamFilter) {
            stream = ((StreamFilter) filter).init((stream != null) ? stream : bundle.asStream());
            bundle = null;
        } else {
            bundle = filter.filter((bundle != null) ? bundle : stream.asMultipleObjectsBundle());
            stream = null;
        }
    }
    return (stream != null) ? stream : bundle.asStream();
}
Also used : MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) ObjectFilter(de.lmu.ifi.dbs.elki.datasource.filter.ObjectFilter) StreamFilter(de.lmu.ifi.dbs.elki.datasource.filter.StreamFilter)

Example 2 with ObjectFilter

use of de.lmu.ifi.dbs.elki.datasource.filter.ObjectFilter 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)

Example 3 with ObjectFilter

use of de.lmu.ifi.dbs.elki.datasource.filter.ObjectFilter in project elki by elki-project.

the class AbstractDatabaseConnection method invokeBundleFilters.

/**
 * Transforms the specified list of objects and their labels into a list of
 * objects and their associations.
 *
 * @param bundle the objects to process
 * @return processed objects
 */
protected MultipleObjectsBundle invokeBundleFilters(MultipleObjectsBundle bundle) {
    if (filters == null) {
        return bundle;
    }
    // We dynamically switch between streaming and bundle operations.
    BundleStreamSource stream = null;
    for (ObjectFilter filter : filters) {
        if (filter instanceof StreamFilter) {
            StreamFilter sfilter = (StreamFilter) filter;
            stream = sfilter.init((stream != null) ? stream : bundle.asStream());
            // No longer a bundle
            bundle = null;
        } else {
            bundle = filter.filter((bundle != null) ? bundle : stream.asMultipleObjectsBundle());
            // No longer a stream
            stream = null;
        }
    }
    return (bundle != null) ? bundle : stream.asMultipleObjectsBundle();
}
Also used : ObjectFilter(de.lmu.ifi.dbs.elki.datasource.filter.ObjectFilter) StreamFilter(de.lmu.ifi.dbs.elki.datasource.filter.StreamFilter) BundleStreamSource(de.lmu.ifi.dbs.elki.datasource.bundle.BundleStreamSource)

Aggregations

ObjectFilter (de.lmu.ifi.dbs.elki.datasource.filter.ObjectFilter)3 StreamFilter (de.lmu.ifi.dbs.elki.datasource.filter.StreamFilter)2 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 BundleStreamSource (de.lmu.ifi.dbs.elki.datasource.bundle.BundleStreamSource)1 MultipleObjectsBundle (de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle)1 FixedDBIDsFilter (de.lmu.ifi.dbs.elki.datasource.filter.FixedDBIDsFilter)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