Search in sources :

Example 1 with CallableDescriptorCalculator

use of ambit2.rest.task.CallableDescriptorCalculator 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 CallableDescriptorCalculator

use of ambit2.rest.task.CallableDescriptorCalculator in project ambit-mirror by ideaconsult.

the class AllAlgorithmsResource method createCallable.

@Override
protected ICallableTask createCallable(Form form, Algorithm<String> algorithm, ModelURIReporter<IQueryRetrieval<ModelQueryResults>> modelReporter, AlgorithmURIReporter algReporter, Object token) throws ResourceException {
    try {
        if (algorithm.hasType(AlgorithmType.Expert)) {
            String userName = "guest";
            try {
                userName = getRequest().getClientInfo().getUser().getIdentifier();
            } catch (Exception x) {
                userName = "guest";
            }
            Object datasetURI = OpenTox.params.dataset_uri.getFirstValue(form);
            return new CallableSimpleModelCreator(form, getContext(), algorithm, false, new ExpertModelBuilder(datasetURI == null ? null : datasetURI.toString(), userName, getRequest().getRootRef(), modelReporter, algReporter, getRequest().getResourceRef().toString()), token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (algorithm.hasType(AlgorithmType.SuperService)) {
            return new CallablePOST(form, getRequest().getRootRef(), token, getRequest().getResourceRef().toString());
        } else if (algorithm.hasType(AlgorithmType.SuperBuilder)) {
            return new CallableBuilder(form, getRequest().getRootRef(), token, getRequest().getResourceRef().toString());
        } else if (algorithm.hasType(AlgorithmType.Mockup)) {
            return new CallableMockup(form, token);
        } else if (algorithm.hasType(AlgorithmType.ExternalModels))
            return new CallableSimpleModelCreator(form, getRequest().getRootRef(), getContext(), algorithm, modelReporter, algReporter, false, token, getRequest().getResourceRef().toString(), getClientInfo());
        else if (algorithm.hasType(AlgorithmType.Rules))
            return new CallableSimpleModelCreator(form, getRequest().getRootRef(), getContext(), algorithm, modelReporter, algReporter, false, token, getRequest().getResourceRef().toString(), getClientInfo());
        else if (algorithm.hasType(AlgorithmType.Finder)) {
            return new CallableFinder(form, getRequest().getRootRef(), getContext(), algorithm, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (algorithm.hasType(AlgorithmType.Structure)) {
            return new CallableSimpleModelCreator(form, getContext(), algorithm, false, new OptimizerModelBuilder(getRequest().getRootRef(), form, modelReporter, algReporter, false, getRequest().getResourceRef().toString()), token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (algorithm.hasType(AlgorithmType.Structure2D)) {
            try {
                CallableSimpleModelCreator modelCreator = new CallableSimpleModelCreator(form, getContext(), algorithm, false, new Structure2DModelBuilder(getRequest().getRootRef(), modelReporter, algReporter, false, getRequest().getResourceRef().toString()), token, getRequest().getResourceRef().toString(), getClientInfo());
                TaskResult modelRef = modelCreator.call();
                ModelQueryResults model = modelCreator.getModel();
                Structure2DProcessor predictor = new Structure2DProcessor(getRequest().getRootRef(), model, new ModelURIReporter<IQueryRetrieval<ModelQueryResults>>(getRequest()), new PropertyURIReporter(getRequest()), null);
                return new CallableStructureOptimizer(form, getRequest().getRootRef(), getContext(), (Structure2DProcessor) predictor, token, getRequest().getResourceRef().toString(), getClientInfo());
            } catch (ResourceException x) {
                throw x;
            } catch (Exception x) {
                getLogger().log(Level.WARNING, x.getMessage(), x);
                throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x.getMessage(), x);
            }
        } else if (algorithm.hasType(AlgorithmType.TautomerGenerator)) {
            return new CallableSimpleModelCreator(form, getContext(), algorithm, false, new TautomersModelBuilder(getRequest().getRootRef(), modelReporter, algReporter, false, getRequest().getResourceRef().toString()), token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (algorithm.hasType(AlgorithmType.PreferredStructure)) {
            return new CallableFixPreferredStructure(form, getRequest().getRootRef(), getContext(), null, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (algorithm.hasType(AlgorithmType.DescriptorCalculation)) {
            try {
                CallableSimpleModelCreator modelCreator = new CallableSimpleModelCreator(form, getRequest().getRootRef(), getContext(), algorithm, modelReporter, algReporter, true, token, getRequest().getResourceRef().toString(), getClientInfo());
                TaskResult modelRef = modelCreator.call();
                ModelQueryResults model = modelCreator.getModel();
                if (algorithm.getParameters() != null) {
                    StringBuilder b = new StringBuilder();
                    for (Parameter prm : algorithm.getParameters()) // b.append(String.format("-%s\t'%s'\t",
                    // prm.getName(),prm.getValue()));
                    b.append(String.format("-%s\t'%s'\t", prm.getName(), prm.getValue()));
                    // this is wrong, the parameters should be stored in the
                    // model already (and in the database!)
                    model.setParameters(b.toString().split("\t"));
                }
                DescriptorPredictor predictor = new DescriptorPredictor(getRequest().getRootRef(), model, modelReporter, new PropertyURIReporter(getRequest()), null);
                return new CallableDescriptorCalculator(form, getRequest().getRootRef(), getContext(), predictor, token, getRequest().getResourceRef().toString(), getClientInfo());
            } catch (ResourceException x) {
                throw x;
            } catch (Exception x) {
                getLogger().log(Level.WARNING, x.getMessage(), x);
                throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x.getMessage(), x);
            }
        } else if (algorithm.hasType(AlgorithmType.AppDomain)) {
            switch(algorithm.getRequirement()) {
                case structure:
                    {
                        return new CallableFingerprintsModelCreator(form, getRequest().getRootRef(), getContext(), algorithm, modelReporter, algReporter, token, getRequest().getResourceRef().toString(), getClientInfo());
                    }
                case property:
                    {
                        return new CallableNumericalModelCreator(form, getRequest().getRootRef(), getContext(), algorithm, modelReporter, algReporter, token, getRequest().getResourceRef().toString(), getClientInfo());
                    }
                default:
                    {
                        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, algorithm.toString());
                    }
            }
        } else if (algorithm.hasType(AlgorithmType.Fingerprints.toString())) {
            return new CallableFingerprintsCalculator(form, getRequest().getRootRef(), getContext(), algorithm, token, getRequest().getResourceRef().toString(), getClientInfo());
        /*
				 * } else if
				 * (AlgorithmFormat.WAFFLES_JSON.equals(algorithm.getFormat()))
				 * { return new CallableWafflesModelCreator(form,
				 * getRequest().getRootRef(), getContext(), algorithm,
				 * modelReporter, algReporter,
				 * token,getRequest().getResourceRef().toString());
				 */
        } else {
            return new CallableWekaModelCreator(form, getRequest().getRootRef(), getContext(), algorithm, modelReporter, algReporter, token, getRequest().getResourceRef().toString(), getClientInfo());
        }
    } catch (ResourceException x) {
        throw x;
    } catch (Exception x) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL);
    } finally {
    // try { connection.close(); } catch (Exception x) {}
    }
}
Also used : CallableBuilder(ambit2.rest.task.CallableBuilder) OptimizerModelBuilder(ambit2.rest.task.OptimizerModelBuilder) CallablePOST(ambit2.rest.task.CallablePOST) PropertyURIReporter(ambit2.rest.property.PropertyURIReporter) CallableStructureOptimizer(ambit2.rest.task.CallableStructureOptimizer) DescriptorPredictor(ambit2.rest.model.predictor.DescriptorPredictor) CallableSimpleModelCreator(ambit2.rest.task.CallableSimpleModelCreator) CallableNumericalModelCreator(ambit2.rest.task.CallableNumericalModelCreator) CallableFingerprintsCalculator(ambit2.rest.task.dbpreprocessing.CallableFingerprintsCalculator) ResourceException(org.restlet.resource.ResourceException) TautomersModelBuilder(ambit2.rest.task.tautomers.TautomersModelBuilder) ModelQueryResults(ambit2.core.data.model.ModelQueryResults) ExpertModelBuilder(ambit2.rest.model.builder.ExpertModelBuilder) CallableFixPreferredStructure(ambit2.rest.task.dbpreprocessing.CallableFixPreferredStructure) Structure2DProcessor(ambit2.rest.model.predictor.Structure2DProcessor) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) CallableMockup(ambit2.rest.task.CallableMockup) CallableWekaModelCreator(ambit2.rest.task.weka.CallableWekaModelCreator) CallableFinder(ambit2.rest.task.dbpreprocessing.CallableFinder) TaskResult(ambit2.rest.task.TaskResult) Parameter(ambit2.core.data.model.Parameter) CallableDescriptorCalculator(ambit2.rest.task.CallableDescriptorCalculator) Structure2DModelBuilder(ambit2.rest.task.Structure2DModelBuilder) CallableFingerprintsModelCreator(ambit2.rest.task.CallableFingerprintsModelCreator)

Aggregations

Structure2DProcessor (ambit2.rest.model.predictor.Structure2DProcessor)2 CallableDescriptorCalculator (ambit2.rest.task.CallableDescriptorCalculator)2 CallableStructureOptimizer (ambit2.rest.task.CallableStructureOptimizer)2 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)2 ResourceException (org.restlet.resource.ResourceException)2 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 ModelQueryResults (ambit2.core.data.model.ModelQueryResults)1 Parameter (ambit2.core.data.model.Parameter)1 ExpertModelBuilder (ambit2.rest.model.builder.ExpertModelBuilder)1 DescriptorPredictor (ambit2.rest.model.predictor.DescriptorPredictor)1 ExpertModelpredictor (ambit2.rest.model.predictor.ExpertModelpredictor)1 ExternalModelPredictor (ambit2.rest.model.predictor.ExternalModelPredictor)1 FingerprintsPredictor (ambit2.rest.model.predictor.FingerprintsPredictor)1 ModelPredictor (ambit2.rest.model.predictor.ModelPredictor)1 CallableModelPredictor (ambit2.rest.model.task.CallableModelPredictor)1 PropertyURIReporter (ambit2.rest.property.PropertyURIReporter)1 CallableBuilder (ambit2.rest.task.CallableBuilder)1 CallableFingerprintsModelCreator (ambit2.rest.task.CallableFingerprintsModelCreator)1 CallableMockup (ambit2.rest.task.CallableMockup)1 CallableNumericalModelCreator (ambit2.rest.task.CallableNumericalModelCreator)1