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 {
}
}
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) {}
}
}
Aggregations