use of net.idea.modbcum.i.exceptions.AmbitException in project ambit-mirror by ideaconsult.
the class ARFFIterator method getIterator.
@Override
public Iterator<IStructureRecord> getIterator(File[] target) throws AmbitException {
try {
input = new BufferedReader(new FileReader(target[0]));
results = new BufferedReader(new FileReader(target[1]));
arffInput = new ArffReader(input, 1);
arffResults = new ArffReader(results, 1);
dataInput = arffInput.getStructure();
dataResults = arffResults.getStructure();
properties = new Property[dataResults.numAttributes()];
for (int i = 0; i < dataResults.numAttributes(); i++) {
Attribute attribute = dataResults.attribute(i);
RDFPropertyIterator reader = null;
Property p = null;
try {
reader = new RDFPropertyIterator(new Reference(attribute.name()), "arff");
reader.setBaseReference(baseReference);
while (reader.hasNext()) {
p = reader.next();
}
} catch (Exception x) {
p = null;
// p.setId((Integer)OpenTox.URI.feature.getId(attribute.name(), baseReference));
} finally {
try {
reader.close();
} catch (Exception x) {
}
}
properties[i] = p;
}
return new Iterator<IStructureRecord>() {
public boolean hasNext() {
try {
inputInstance = arffInput.readInstance(dataInput);
resultInstance = arffResults.readInstance(dataResults);
return (inputInstance != null) && (resultInstance != null);
} catch (Exception x) {
return false;
}
}
public IStructureRecord next() {
record.clear();
Object[] ids = OpenTox.URI.conformer.getIds(inputInstance.toString(0), baseReference);
if ((ids != null) && (ids[0] != null) && (ids[1] != null)) {
record.setIdchemical((Integer) ids[0]);
record.setIdstructure((Integer) ids[1]);
} else {
Object id = OpenTox.URI.compound.getId(inputInstance.toString(0), baseReference);
if (id != null) {
record.setIdchemical((Integer) id);
record.setIdstructure(-1);
} else {
// retrieveStructure(uris[index]);
}
}
for (int i = 0; i < properties.length; i++) if (properties[i] != null) {
if (dataResults.attribute(i).isNumeric())
record.setRecordProperty(properties[i], resultInstance.value(i));
else
record.setRecordProperty(properties[i], resultInstance.toString(i));
}
return record;
}
public void remove() {
}
};
} catch (FileNotFoundException x) {
throw new AmbitException(x);
} catch (Exception x) {
throw new AmbitException(x);
}
}
use of net.idea.modbcum.i.exceptions.AmbitException in project ambit-mirror by ideaconsult.
the class Structure2DModelBuilder method process.
public ModelQueryResults process(Algorithm algorithm) throws AmbitException {
try {
ModelQueryResults mr = new ModelQueryResults();
mr.setHidden(modelHidden);
mr.setContentMediaType(AlgorithmFormat.Structure2D.getMediaType());
mr.setName(algorithm.getName());
mr.setContent(algorithm.getContent().toString());
mr.setAlgorithm(alg_reporter.getURI(algorithm));
mr.setPredictors(algorithm.getInput());
Template dependent = new Template("Empty");
mr.setDependent(dependent);
PredictedVarsTemplate predicted = new PredictedVarsTemplate("Empty");
mr.setPredicted(predicted);
return mr;
} catch (Exception x) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x.getCause() == null ? x.getMessage() : x.getCause().getMessage(), x);
}
}
use of net.idea.modbcum.i.exceptions.AmbitException in project ambit-mirror by ideaconsult.
the class TaskCreator method processItem.
@Override
public Object processItem(T item) throws AmbitException {
try {
ICallableTask callable = getCallable(form, item);
if (async) {
ITask<Reference, USERID> task = createTask(callable, item);
tasks.add(task.getUuid());
} else {
ITaskResult ref = callable.call();
}
} catch (AmbitException x) {
throw x;
} catch (Exception x) {
throw new AmbitException(x);
}
return item;
}
use of net.idea.modbcum.i.exceptions.AmbitException in project ambit-mirror by ideaconsult.
the class ClassHolder method load.
public static List<ClassHolder> load(InputStream input) throws AmbitException {
List<ClassHolder> classes = new ArrayList<ClassHolder>();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
boolean eof = false;
String fileLine;
while (!eof) {
fileLine = reader.readLine();
if (fileLine == null)
eof = true;
else {
classes.add(new ClassHolder(fileLine.trim(), fileLine, "", (String) null));
}
}
reader.close();
} catch (Exception x) {
} finally {
try {
input.close();
} catch (Exception x) {
}
}
return classes;
}
use of net.idea.modbcum.i.exceptions.AmbitException in project ambit-mirror by ideaconsult.
the class BatchProcessor method process.
/*
protected Iterator getIterator(IInputState target) throws AmbitException {
return target.getReader();
}
protected void closeIterator(Iterator iterator) throws AmbitException {
iterator.close();
}
*/
public IBatchStatistics process(INPUT target) throws AmbitException {
try {
DefaultBatchStatistics stats = new DefaultBatchStatistics();
stats.setResultCaption("Read");
stats.setFrequency(1);
Iterator reader = getIterator(target);
ProcessorsChain<Target, IBatchStatistics, IProcessor> processor = getProcessorChain();
if (processor == null)
throw new AmbitException("Processor not defined");
long started = System.currentTimeMillis();
while (reader.hasNext() && !cancelled) {
if ((stats.getRecords(IBatchStatistics.RECORDS_STATS.RECORDS_READ) % stats.getFrequency()) == 0)
propertyChangeSupport.firePropertyChange(PROPERTY_BATCHSTATS, null, stats);
Object object = null;
long ms = System.currentTimeMillis();
try {
object = reader.next();
stats.increment(IBatchStatistics.RECORDS_STATS.RECORDS_READ);
stats.incrementTimeElapsed(IBatchStatistics.RECORDS_STATS.RECORDS_READ, System.currentTimeMillis() - ms);
} catch (Exception x) {
stats.increment(IBatchStatistics.RECORDS_STATS.RECORDS_ERROR);
stats.incrementTimeElapsed(IBatchStatistics.RECORDS_STATS.RECORDS_ERROR, System.currentTimeMillis() - ms);
continue;
}
ms = System.currentTimeMillis();
try {
processor.process((Target) object);
stats.increment(IBatchStatistics.RECORDS_STATS.RECORDS_PROCESSED);
stats.incrementTimeElapsed(IBatchStatistics.RECORDS_STATS.RECORDS_PROCESSED, System.currentTimeMillis() - ms);
} catch (Exception x) {
stats.increment(IBatchStatistics.RECORDS_STATS.RECORDS_ERROR);
stats.incrementTimeElapsed(IBatchStatistics.RECORDS_STATS.RECORDS_ERROR, System.currentTimeMillis() - ms);
continue;
}
long elapsed = System.currentTimeMillis() - started;
if ((timeout > 0) && (elapsed > timeout)) {
stats.increment(IBatchStatistics.RECORDS_STATS.RECORDS_ERROR);
stats.incrementTimeElapsed(IBatchStatistics.RECORDS_STATS.RECORDS_ERROR, System.currentTimeMillis() - ms);
break;
}
}
propertyChangeSupport.firePropertyChange(PROPERTY_BATCHSTATS, null, stats);
closeIterator(reader);
return stats;
} catch (Exception x) {
throw new AmbitException(x);
}
}
Aggregations