Search in sources :

Example 6 with InputStreamDatabaseConnection

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());
}
Also used : ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) InputStream(java.io.InputStream) MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) InputStreamDatabaseConnection(de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection) Test(org.junit.Test) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest)

Example 7 with InputStreamDatabaseConnection

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());
}
Also used : ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) InputStream(java.io.InputStream) MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) InputStreamDatabaseConnection(de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection) Test(org.junit.Test) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest)

Example 8 with InputStreamDatabaseConnection

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;
    }
}
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

InputStreamDatabaseConnection (de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection)8 InputStream (java.io.InputStream)8 Test (org.junit.Test)7 AbstractDataSourceTest (de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest)5 MultipleObjectsBundle (de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle)5 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)3 ELKIBuilder (de.lmu.ifi.dbs.elki.utilities.ELKIBuilder)3 AbstractSimpleAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.AbstractSimpleAlgorithmTest)2 AbstractDatabase (de.lmu.ifi.dbs.elki.database.AbstractDatabase)2 Database (de.lmu.ifi.dbs.elki.database.Database)2 StaticArrayDatabase (de.lmu.ifi.dbs.elki.database.StaticArrayDatabase)2 ListParameterization (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)1 SparseDoubleVector (de.lmu.ifi.dbs.elki.data.SparseDoubleVector)1 SparseNumberVector (de.lmu.ifi.dbs.elki.data.SparseNumberVector)1 HashmapDatabase (de.lmu.ifi.dbs.elki.database.HashmapDatabase)1 UpdatableDatabase (de.lmu.ifi.dbs.elki.database.UpdatableDatabase)1 ArrayDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs)1