use of de.lmu.ifi.dbs.elki.datasource.bundle.BundleMeta in project elki by elki-project.
the class SimpleTransactionParser method getMeta.
@Override
public BundleMeta getMeta() {
if (meta == null) {
meta = new BundleMeta(1);
meta.add(new VectorTypeInformation<>(BitVector.FACTORY, BitVector.SHORT_SERIALIZER, 0, numterms));
}
return meta;
}
use of de.lmu.ifi.dbs.elki.datasource.bundle.BundleMeta in project elki by elki-project.
the class EvaluatePrecomputedOutlierScores method run.
@Override
public void run() {
try (//
FileInputStream fis = new FileInputStream(infile);
//
InputStream is = new BufferedInputStream(FileUtil.tryGzipInput(fis));
FileOutputStream fosResult = new FileOutputStream(outfile, true);
PrintStream fout = new PrintStream(fosResult);
FileChannel chan = fosResult.getChannel()) {
// Setup the input stream.
parser.initStream(is);
// Lock the output file:
chan.lock();
if (chan.position() == 0L) {
writeHeader(fout);
} else {
LOG.info("Appending to existing output " + outfile);
}
int lcol = -1, dcol = -1;
loop: while (true) {
BundleStreamSource.Event ev = parser.nextEvent();
switch(ev) {
case END_OF_STREAM:
break loop;
case META_CHANGED:
BundleMeta meta = parser.getMeta();
lcol = -1;
dcol = -1;
for (int i = 0; i < meta.size(); i++) {
SimpleTypeInformation<?> m = meta.get(i);
if (TypeUtil.NUMBER_VECTOR_VARIABLE_LENGTH.isAssignableFromType(m)) {
if (dcol >= 0) {
throw new AbortException("More than one vector column.");
}
dcol = i;
} else if (TypeUtil.GUESSED_LABEL.isAssignableFromType(m)) {
if (lcol >= 0) {
throw new AbortException("More than one label column.");
}
lcol = i;
} else {
throw new AbortException("Unexpected data column type: " + m);
}
}
break;
case NEXT_OBJECT:
if (lcol < 0) {
throw new AbortException("No label column available.");
}
if (dcol < 0) {
throw new AbortException("No vector column available.");
}
processRow(fout, (NumberVector) parser.data(dcol), parser.data(lcol).toString());
break;
}
}
} catch (IOException e) {
throw new AbortException("IO error.", e);
}
}
use of de.lmu.ifi.dbs.elki.datasource.bundle.BundleMeta in project elki by elki-project.
the class ClusteringVectorParser method getMeta.
@Override
public BundleMeta getMeta() {
if (meta == null) {
meta = new BundleMeta(haslbl ? 2 : 1);
meta.add(Clustering.TYPE);
if (haslbl) {
meta.add(TypeUtil.LABELLIST);
}
}
return meta;
}
use of de.lmu.ifi.dbs.elki.datasource.bundle.BundleMeta in project elki by elki-project.
the class ByLabelFilter method nextEvent.
@Override
public Event nextEvent() {
while (true) {
Event ev = source.nextEvent();
switch(ev) {
case END_OF_STREAM:
if (lblcol < 0) {
LOG.warning("By label filter was used, but never saw a label relation!");
}
return Event.END_OF_STREAM;
case META_CHANGED:
// Search for the first label column
if (lblcol < 0) {
BundleMeta meta = source.getMeta();
lblcol = FilterUtil.findLabelColumn(meta);
}
return Event.META_CHANGED;
case NEXT_OBJECT:
if (lblcol > 0) {
Object l = source.data(lblcol);
if (l instanceof LabelList) {
boolean good = false;
final LabelList ll = (LabelList) l;
for (int i = 0; i < ll.size(); i++) {
matcher.reset(ll.get(i));
if (matcher.matches()) {
good = true;
break;
}
}
if (good == inverted) {
continue;
}
} else {
matcher.reset(l.toString());
if (!matcher.matches()) {
continue;
}
}
} else {
// No labels known yet.
if (!inverted) {
continue;
}
}
return Event.NEXT_OBJECT;
default:
LOG.warning("Unknown event: " + ev);
}
}
}
use of de.lmu.ifi.dbs.elki.datasource.bundle.BundleMeta in project elki by elki-project.
the class ConcatenateFilesDatabaseConnection method loadData.
@Override
public MultipleObjectsBundle loadData() {
MultipleObjectsBundle objects = new MultipleObjectsBundle();
objects.appendColumn(TypeUtil.STRING, new ArrayList<>());
for (File file : files) {
String filestr = file.getPath();
try (InputStream inputStream = //
FileUtil.tryGzipInput(new BufferedInputStream(new FileInputStream(file)))) {
final BundleStreamSource source;
if (parser instanceof StreamingParser) {
final StreamingParser streamParser = (StreamingParser) parser;
streamParser.initStream(inputStream);
source = streamParser;
} else {
MultipleObjectsBundle parsingResult = parser.parse(inputStream);
// normalize objects and transform labels
source = parsingResult.asStream();
}
// NullPointerException on invalid streams
BundleMeta meta = null;
loop: for (Event e = source.nextEvent(); ; e = source.nextEvent()) {
switch(e) {
case END_OF_STREAM:
break loop;
case META_CHANGED:
meta = source.getMeta();
for (int i = 0; i < meta.size(); i++) {
if (i + 1 >= objects.metaLength()) {
objects.appendColumn(meta.get(i), new ArrayList<>());
} else {
// Ensure compatibility:
if (!objects.meta(i + 1).isAssignableFromType(meta.get(i))) {
throw new AbortException("Incompatible files loaded. Cannot concatenate with unaligned columns, please preprocess manually.");
}
}
}
// switch
break;
case NEXT_OBJECT:
Object[] o = new Object[objects.metaLength()];
o[0] = filestr;
for (int i = 0; i < meta.size(); i++) {
o[i + 1] = source.data(i);
}
objects.appendSimple(o);
// switch
break;
}
}
} catch (IOException e) {
throw new AbortException("Loading file " + filestr + " failed: " + e.toString(), e);
}
}
parser.cleanup();
// Invoke filters
if (LOG.isDebugging()) {
LOG.debugFine("Invoking filters.");
}
return invokeBundleFilters(objects);
}
Aggregations