Search in sources :

Example 11 with BundleMeta

use of de.lmu.ifi.dbs.elki.datasource.bundle.BundleMeta in project elki by elki-project.

the class SimpleTransactionParser method nextEvent.

@Override
public Event nextEvent() {
    if (nextevent != null) {
        Event ret = nextevent;
        nextevent = null;
        return ret;
    }
    try {
        while (reader.nextLineExceptComments()) {
            // Don't reuse bitsets, will not be copied by BitVector constructor.
            buf.clear();
            for (; /* initialized by nextLineExceptComments() */
            tokenizer.valid(); tokenizer.advance()) {
                String token = tokenizer.getSubstring();
                int t = keymap.getInt(token);
                if (t < 0) {
                    t = keymap.size();
                    keymap.put(token, t);
                }
                final int word = t >>> 6;
                final int off = t & 0x3F;
                while (word >= buf.size()) {
                    // Ensure size.
                    buf.add(0L);
                }
                buf.set(word, buf.getLong(word) | (1L << off));
            }
            curvec = new BitVector(buf.toLongArray(), keymap.size());
            return Event.NEXT_OBJECT;
        }
        nextevent = Event.END_OF_STREAM;
        // Construct final metadata:
        meta = new BundleMeta(1);
        String[] colnames = new String[keymap.size()];
        for (ObjectIterator<Object2IntMap.Entry<String>> iter = keymap.object2IntEntrySet().fastIterator(); iter.hasNext(); ) {
            Object2IntMap.Entry<String> entry = iter.next();
            colnames[entry.getIntValue()] = entry.getKey();
        }
        meta.add(new VectorFieldTypeInformation<>(BitVector.FACTORY, colnames.length, colnames));
        // Force a final meta update.
        return Event.META_CHANGED;
    } catch (IOException e) {
        throw new IllegalArgumentException("Error while parsing line " + reader.getLineNumber() + ".");
    }
}
Also used : BitVector(de.lmu.ifi.dbs.elki.data.BitVector) BundleMeta(de.lmu.ifi.dbs.elki.datasource.bundle.BundleMeta) Object2IntMap(it.unimi.dsi.fastutil.objects.Object2IntMap) IOException(java.io.IOException)

Aggregations

BundleMeta (de.lmu.ifi.dbs.elki.datasource.bundle.BundleMeta)11 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)3 SimpleTypeInformation (de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation)2 IOException (java.io.IOException)2 BitVector (de.lmu.ifi.dbs.elki.data.BitVector)1 LabelList (de.lmu.ifi.dbs.elki.data.LabelList)1 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)1 VectorFieldTypeInformation (de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation)1 VectorTypeInformation (de.lmu.ifi.dbs.elki.data.type.VectorTypeInformation)1 BundleStreamSource (de.lmu.ifi.dbs.elki.datasource.bundle.BundleStreamSource)1 Event (de.lmu.ifi.dbs.elki.datasource.bundle.BundleStreamSource.Event)1 MultipleObjectsBundle (de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle)1 StreamingParser (de.lmu.ifi.dbs.elki.datasource.parser.StreamingParser)1 Object2IntMap (it.unimi.dsi.fastutil.objects.Object2IntMap)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 FileChannel (java.nio.channels.FileChannel)1 ArrayList (java.util.ArrayList)1