use of ambit2.db.update.model.ReadModel in project ambit-mirror by ideaconsult.
the class ReadModelTest method verify.
@Override
protected void verify(ReadModel query, ResultSet rs) throws Exception {
int count = 0;
while (rs.next()) {
ModelQueryResults record = query.getObject(rs);
Assert.assertEquals("Model", record.getName());
Assert.assertEquals("A123 B456", record.getParameters()[0]);
count++;
}
Assert.assertEquals(1, count);
}
use of ambit2.db.update.model.ReadModel in project ambit-mirror by ideaconsult.
the class ModelResource method getModelQuery.
protected AbstractModelQuery getModelQuery(Object idmodel, Form form) throws ResourceException {
_dmode = DisplayMode.singleitem;
AbstractModelQuery query = null;
ModelQueryResults model_query = null;
String algorithm = form.getFirstValue(AbstractModelQuery._models_criteria.algorithm.name());
if (algorithm != null) {
model_query = new ModelQueryResults();
model_query.setCreator(null);
model_query.setAlgorithm(algorithm);
}
String dataset = form.getFirstValue(AbstractModelQuery._models_criteria.dataset.name());
if (dataset != null) {
if (model_query == null) {
model_query = new ModelQueryResults();
model_query.setCreator(null);
}
model_query.setTrainingInstances(dataset);
}
String creator = form.getFirstValue(AbstractModelQuery._models_criteria.creator.name());
if (creator != null) {
if (model_query == null) {
model_query = new ModelQueryResults();
}
model_query.setCreator(creator);
}
String endpoint = form.getFirstValue(AbstractModelQuery._models_criteria.endpoint.name());
if (endpoint != null) {
if (model_query == null) {
model_query = new ModelQueryResults();
model_query.setEndpoint(null);
}
model_query.setEndpoint(endpoint);
}
if (model_query == null) {
query = new ReadModel();
String condition = form.getFirstValue(QueryResource.condition);
if (condition != null)
query.setCondition(StringCondition.getInstance(condition));
String name = form.getFirstValue(QueryResource.search_param);
if (name != null) {
query.setFieldname(name.trim());
if (condition == null)
query.setCondition(StringCondition.getInstance(StringCondition.C_STARTS_WITH));
}
if (idmodel == null) {
_dmode = DisplayMode.table;
return query;
} else if (idmodel instanceof Integer) {
_dmode = DisplayMode.singleitem;
query.setValue((Integer) idmodel);
return query;
} else {
_dmode = DisplayMode.table;
query.setFieldname(idmodel.toString());
return query;
}
} else {
String name = form.getFirstValue(QueryResource.search_param);
if (name != null)
model_query.setName(name);
if (idmodel != null)
if (idmodel instanceof Integer)
model_query.setId((Integer) idmodel);
else
model_query.setName(idmodel.toString());
return new QueryModel(model_query);
}
}
use of ambit2.db.update.model.ReadModel in project ambit-mirror by ideaconsult.
the class CallableModelCreator method createReference.
/**
* Writes the model into database and returns a reference
*/
@Override
protected TaskResult createReference(Connection connection) throws Exception {
UpdateExecutor x = new UpdateExecutor();
try {
model = createModel();
CreateModel update = new CreateModel(model);
x.setConnection(connection);
Integer i = (Integer) x.process(update);
writeAnnotations(model.getPredicted(), x);
newModel = i > 0;
if ((model.getId() == null) || (model.getId() < 0)) {
ReadModel q = new ReadModel();
q.setFieldname(model.getName());
QueryExecutor<ReadModel> exec = new QueryExecutor<ReadModel>();
exec.setConnection(connection);
exec.setCloseConnection(false);
java.sql.ResultSet rs = null;
try {
rs = exec.process(q);
while (rs.next()) {
ModelQueryResults result = q.getObject(rs);
model.setId(result.getId());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
rs = null;
} catch (Exception xx) {
}
try {
exec.closeResults(null);
exec = null;
} catch (Exception xx) {
}
}
}
return new TaskResult(builder.getModelReporter().getURI(model), newModel);
} catch (Exception e) {
Context.getCurrentLogger().severe(e.getMessage());
throw e;
} finally {
try {
x.close();
} catch (Exception xx) {
}
}
}
Aggregations