try {
input = objectMapper.readValue(body, HashMap.class);
} catch (Exception e) {
return Response.status(200).entity("{\"error\":\"" + Arrays.toString(e.getStackTrace()) + "\"}").build();
}
LabeledText labeledText = new LabeledText();
ArrayList labels = (ArrayList) input.get("label");
ArrayList texts = new ArrayList();
if (input.get("text").getClass() == ArrayList.class) {
texts = (ArrayList) input.get("text");
} else {
texts.add(input.get("text"));
}
for (int i = 0; i < texts.size(); i++) {
texts.set(i, cleanText((String) texts.get(i)));
}
labeledText.setLabel((String[]) labels.toArray(new String[labels.size()]));
labeledText.setText((String[]) texts.toArray(new String[texts.size()]));
if (input.containsKey("focus")) {
labeledText.setFocus((int) input.get("focus"));
} else {
labeledText.setFocus(1);
}
// Add first matcher
for (int i = 0; i < labeledText.getFocus(); i++) {
Transaction tx = db.beginTx();
getRootPatternNode(db);
LearningManager.trainInput(Arrays.asList(labeledText.getText()), Arrays.asList(labeledText.getLabel()), GRAPH_MANAGER, db);
tx.success();
tx.close();
}
return Response.ok()