Search in sources :

Example 16 with AmbitException

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);
    }
}
Also used : Attribute(weka.core.Attribute) RDFPropertyIterator(ambit2.rest.rdf.RDFPropertyIterator) Reference(org.restlet.data.Reference) ArffReader(weka.core.converters.ArffLoader.ArffReader) FileNotFoundException(java.io.FileNotFoundException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) Iterator(java.util.Iterator) RDFPropertyIterator(ambit2.rest.rdf.RDFPropertyIterator) FileReader(java.io.FileReader) Property(ambit2.base.data.Property) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 17 with AmbitException

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);
    }
}
Also used : PredictedVarsTemplate(ambit2.base.data.PredictedVarsTemplate) ModelQueryResults(ambit2.core.data.model.ModelQueryResults) ResourceException(org.restlet.resource.ResourceException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) PredictedVarsTemplate(ambit2.base.data.PredictedVarsTemplate) Template(ambit2.base.data.Template)

Example 18 with AmbitException

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;
}
Also used : ICallableTask(net.idea.restnet.i.task.ICallableTask) Reference(org.restlet.data.Reference) ITaskResult(net.idea.restnet.i.task.ITaskResult) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) ResourceException(org.restlet.resource.ResourceException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException)

Example 19 with AmbitException

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 20 with AmbitException

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);
    }
}
Also used : DefaultBatchStatistics(net.idea.modbcum.i.batch.DefaultBatchStatistics) Iterator(java.util.Iterator) IBatchStatistics(net.idea.modbcum.i.batch.IBatchStatistics) IProcessor(net.idea.modbcum.i.processors.IProcessor) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Aggregations

AmbitException (net.idea.modbcum.i.exceptions.AmbitException)378 ArrayList (java.util.ArrayList)119 QueryParam (net.idea.modbcum.i.query.QueryParam)109 SQLException (java.sql.SQLException)85 Property (ambit2.base.data.Property)68 DbAmbitException (net.idea.modbcum.i.exceptions.DbAmbitException)56 IStructureRecord (ambit2.base.interfaces.IStructureRecord)48 ResourceException (org.restlet.resource.ResourceException)43 IOException (java.io.IOException)35 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)35 LiteratureEntry (ambit2.base.data.LiteratureEntry)21 StructureRecord (ambit2.base.data.StructureRecord)19 ResultSet (java.sql.ResultSet)19 SubstanceRecord (ambit2.base.data.SubstanceRecord)14 Template (ambit2.base.data.Template)13 ModelQueryResults (ambit2.core.data.model.ModelQueryResults)12 Form (org.restlet.data.Form)12 PredictedVarsTemplate (ambit2.base.data.PredictedVarsTemplate)11 StringWriter (java.io.StringWriter)11 OperationNotSupportedException (javax.naming.OperationNotSupportedException)11