{
throw new ActivityProcessingException(e);
}
catch (PipeTerminatedException e)
{
throw new ActivityTerminatedException();
}
metadataSent = true;
}
}
// retrieve the classifier
block = inputs[1].read();
if (block != ControlBlock.NO_MORE_DATA)
{
classifier = (Classifier)block;
featuresMatrix = classifier.getFeaturesMatrix();
classType = classifier.getClassType();
LOG.debug("featuresMatrix size: " + featuresMatrix.length + " ; [0] " + featuresMatrix[0]);
LOG.debug("classType size: " + classType.length + " ; [0] " + classType[0]);
}
block = inputs[0].read();
if (block != ControlBlock.NO_MORE_DATA)
{
if(block instanceof Tuple){
Tuple tuple = (Tuple) block;
// read the feature
double[] data = (double[]) tuple.getObject(0);
LOG.debug("features to be classified: size " + data.length + " ; [0] " + data[0]);
classification = KNNclassify(data,featuresMatrix,classType,NumberOfNeighbour);
LOG.debug("classification: " + classification);
List elements = new ArrayList();
elements.add(classification);
Tuple tupleC = new SimpleTuple(elements);
try{
mOutput.write(tupleC);
}
catch (PipeTerminatedException e)
{
throw new ActivityTerminatedException();
}
catch (PipeClosedException e)
{
// Consumer does not want any more data, just stop.
}