Search in sources :

Example 1 with ModelQueryResults

use of ambit2.core.data.model.ModelQueryResults in project ambit-mirror by ideaconsult.

the class ModelResource method createCallable.

@Override
protected CallableQueryProcessor createCallable(Form form, ModelQueryResults model) throws ResourceException {
    try {
        readVariables(model);
        Object token = getToken();
        final ModelPredictor thepredictor = ModelResource.getPredictor(model, getRequest());
        if (model.getContentMediaType().equals(AlgorithmFormat.WWW_FORM.getMediaType())) {
            if (thepredictor instanceof ExpertModelpredictor)
                return new CallableModelPredictor<IStructureRecord, ExpertModelpredictor, Object>(form, getRequest().getRootRef(), getContext(), (ExpertModelpredictor) thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo()) {

                    @Override
                    protected void processForm(Reference applicationRootReference, Form form) {
                        super.processForm(applicationRootReference, form);
                        ((ExpertModelpredictor) thepredictor).setValue(form.getFirstValue("value"));
                    }
                };
            else
                return new CallableModelPredictor<IStructureRecord, ModelPredictor, Object>(form, getRequest().getRootRef(), getContext(), thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (model.getContentMediaType().equals(AlgorithmFormat.WEKA.getMediaType())) {
            return // reads Instances, instead of IStructureRecord
            new CallableWekaPredictor<Object, Object>(form, getRequest().getRootRef(), getContext(), thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
        /*
				 * } else if (model.getContentMediaType().equals(
				 * 
				 * AlgorithmFormat.WAFFLES_JSON.getMediaType())) { return new
				 * CallableWafflesPredictor(form, getRequest() .getRootRef(),
				 * getContext(), (WafflesPredictor) thepredictor,
				 * token,getRequest().getResourceRef().toString());
				 */
        } else if (model.getContentMediaType().equals(AlgorithmFormat.COVERAGE_SERIALIZED.getMediaType())) {
            if (model.getPredictors().size() == 0) {
                // based AD
                if (thepredictor instanceof FingerprintsPredictor)
                    return new CallableModelPredictor<IStructureRecord, FingerprintsPredictor, Object>(form, getRequest().getRootRef(), getContext(), (FingerprintsPredictor) thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
                else
                    throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, String.format("Not supported %s", thepredictor.getClass().getName()));
            } else {
                return new CallableModelPredictor(form, getRequest().getRootRef(), getContext(), thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
            /*
					 * return new CallableWekaPredictor<DataCoverage>( //reads
					 * Instances, instead of IStructureRecord form,
					 * getRequest().getRootRef(), getContext(), predictor) ;
					 */
            }
        } else if (model.getContentMediaType().equals(AlgorithmFormat.Structure2D.getMediaType())) {
            return new CallableStructureOptimizer(form, getRequest().getRootRef(), getContext(), (Structure2DProcessor) thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (model.getContentMediaType().equals(AlgorithmFormat.MOPAC.getMediaType())) {
            return new CallableStructureOptimizer(form, getRequest().getRootRef(), getContext(), (StructureProcessor) thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (model.getContentMediaType().equals(AlgorithmFormat.TAUTOMERS.getMediaType())) {
            return new CallableTautomersGenerator(form, getRequest().getRootRef(), getContext(), (TautomersGenerator) thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (model.getContentMediaType().equals(AlgorithmFormat.JAVA_CLASS.getMediaType())) {
            return new CallableDescriptorCalculator(form, getRequest().getRootRef(), getContext(), (DescriptorPredictor) thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else
            throw new ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE, model.getContentMediaType());
    } catch (ResourceException x) {
        throw x;
    } catch (Exception x) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x.getMessage(), x);
    } finally {
    }
}
Also used : ExpertModelpredictor(ambit2.rest.model.predictor.ExpertModelpredictor) Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) Structure2DProcessor(ambit2.rest.model.predictor.Structure2DProcessor) CallableTautomersGenerator(ambit2.rest.task.tautomers.CallableTautomersGenerator) TautomersGenerator(ambit2.rest.task.tautomers.TautomersGenerator) ModelPredictor(ambit2.rest.model.predictor.ModelPredictor) CallableModelPredictor(ambit2.rest.model.task.CallableModelPredictor) ExternalModelPredictor(ambit2.rest.model.predictor.ExternalModelPredictor) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException) FingerprintsPredictor(ambit2.rest.model.predictor.FingerprintsPredictor) CallableStructureOptimizer(ambit2.rest.task.CallableStructureOptimizer) IStructureRecord(ambit2.base.interfaces.IStructureRecord) CallableModelPredictor(ambit2.rest.model.task.CallableModelPredictor) CallableTautomersGenerator(ambit2.rest.task.tautomers.CallableTautomersGenerator) CallableDescriptorCalculator(ambit2.rest.task.CallableDescriptorCalculator) ResourceException(org.restlet.resource.ResourceException)

Example 2 with ModelQueryResults

use of ambit2.core.data.model.ModelQueryResults in project ambit-mirror by ideaconsult.

the class ModelTextReporter method processItem.

@Override
public Object processItem(ModelQueryResults model) throws AmbitException {
    try {
        ModelPredictor predictor = ModelResource.getPredictor(model, request);
        getOutput().write(predictor.toString());
        return null;
    } catch (AmbitException x) {
        throw x;
    } catch (Exception x) {
        throw new AmbitException(x);
    }
}
Also used : ModelPredictor(ambit2.rest.model.predictor.ModelPredictor) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 3 with ModelQueryResults

use of ambit2.core.data.model.ModelQueryResults in project ambit-mirror by ideaconsult.

the class ModelImageReporter method processItem.

@Override
public Object processItem(ModelQueryResults model) throws Exception {
    ModelPredictor predictor = ModelResource.getPredictor(model, request);
    String resultsURI = String.format("%s/%s", modelURIReporter.getURI(model), OpenTox.URI.feature);
    setOutput(getImage(predictor, resultsURI));
    return model;
}
Also used : ModelPredictor(ambit2.rest.model.predictor.ModelPredictor)

Example 4 with ModelQueryResults

use of ambit2.core.data.model.ModelQueryResults in project ambit-mirror by ideaconsult.

the class ModelJSONReporter method parseContent.

protected void parseContent(ModelQueryResults model) {
    ObjectInputStream ois = null;
    try {
        Form form = new Form(model.getContent());
        InputStream in = new ByteArrayInputStream(Base64.decode(form.getFirstValue("model")));
        ois = new ObjectInputStream(in);
        Object o = ois.readObject();
        if (o == null)
            throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, String.format("Error when reading model %s", model.getName()));
        List<IEvaluation<String>> e = new ArrayList<IEvaluation<String>>();
        for (EVType evt : EVType.values()) {
            String[] evals = form.getValuesArray(evt.name());
            for (int i = 0; i < evals.length; i++) {
                EvaluationStats<String> stats = new EvaluationStats<String>(evt, evals[i]);
                for (EVStatsType evst : EVStatsType.values()) {
                    Object value = form.getFirstValue(evt.name() + "_" + evst.name());
                    if (value == null)
                        continue;
                    try {
                        stats.getStats().put(evst, Double.parseDouble(value.toString()));
                    } catch (Exception x) {
                    }
                }
                e.add(stats);
            }
        }
        if (e.size() == 0)
            model.setEvaluation(null);
        else
            model.setEvaluation(e);
    } catch (Exception x) {
    } finally {
        try {
            ois.close();
        } catch (Exception x) {
        }
    }
}
Also used : Form(org.restlet.data.Form) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) EVType(ambit2.core.data.model.IEvaluation.EVType) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) IEvaluation(ambit2.core.data.model.IEvaluation) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceException(org.restlet.resource.ResourceException) EVStatsType(ambit2.core.data.model.IEvaluation.EVStatsType) EvaluationStats(ambit2.model.evaluation.EvaluationStats) ObjectInputStream(java.io.ObjectInputStream)

Example 5 with ModelQueryResults

use of ambit2.core.data.model.ModelQueryResults in project ambit-mirror by ideaconsult.

the class PropertyModelResource method createQuery.

@Override
protected IQueryRetrieval<Property> createQuery(Context context, Request request, Response response) throws ResourceException {
    Form form = request.getResourceRef().getQueryAsForm();
    try {
        headless = Boolean.parseBoolean(form.getFirstValue("headless"));
    } catch (Exception x) {
        headless = false;
    }
    ModelQueryResults model = new ModelQueryResults();
    try {
        model.setId(Integer.parseInt(getRequest().getAttributes().get(MLResources.model_resourcekey).toString()));
    } catch (Exception x) {
        model.setId(-1);
        if ("null".equals(getRequest().getAttributes().get(MLResources.model_resourcekey).toString()))
            model = null;
        else
            model.setName(getRequest().getAttributes().get(MLResources.model_resourcekey).toString());
    }
    ModelTemplates query = new ModelTemplates();
    try {
        query.setValue(Reference.decode(getRequest().getAttributes().get(resourceKey).toString()));
    } catch (Exception x) {
        query.setValue(null);
    }
    query.setFieldname(model);
    return query;
}
Also used : ModelTemplates(ambit2.db.search.property.ModelTemplates) ModelQueryResults(ambit2.core.data.model.ModelQueryResults) Form(org.restlet.data.Form) ResourceException(org.restlet.resource.ResourceException)

Aggregations

ModelQueryResults (ambit2.core.data.model.ModelQueryResults)24 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)23 ResourceException (org.restlet.resource.ResourceException)21 PredictedVarsTemplate (ambit2.base.data.PredictedVarsTemplate)13 Template (ambit2.base.data.Template)13 IOException (java.io.IOException)10 Form (org.restlet.data.Form)9 Property (ambit2.base.data.Property)8 EvaluationStats (ambit2.model.evaluation.EvaluationStats)7 IEvaluation (ambit2.core.data.model.IEvaluation)6 LiteratureEntry (ambit2.base.data.LiteratureEntry)5 PropertyAnnotation (ambit2.base.data.PropertyAnnotation)5 PropertyAnnotations (ambit2.base.data.PropertyAnnotations)5 AlgorithmURIReporter (ambit2.rest.algorithm.AlgorithmURIReporter)5 Reference (org.restlet.data.Reference)5 EVStatsType (ambit2.core.data.model.IEvaluation.EVStatsType)4 CreateModel (ambit2.db.update.model.CreateModel)3 ModelPredictor (ambit2.rest.model.predictor.ModelPredictor)3 WekaException (weka.core.WekaException)3 Remove (weka.filters.unsupervised.attribute.Remove)3