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();
}
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;
}
}
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();
}
Aggregations