}
} catch (Exception e) {
logger.error("Error in ExtractEntitiesCommand" + e.toString());
Util.logException(logger, e);
return new UpdateContainer(new ErrorUpdate(e.getMessage()));
}
// print result
logger.info("Got extractions:");
logger.info(extractions);
JSONArray result = (JSONArray) JSONUtil.createJson(extractions);
//Final Data for AddValuesCommand
JSONArray rowData = new JSONArray();
// index for result iteration
int index = 0;
for(Table table : tables) {
ArrayList<Row> rows = table.getRows(0, table.getNumRows(), selection);
for (Row row : rows) {
if (index < result.length()) {
JSONObject extraction = (JSONObject) result.getJSONObject(index++).get("extractions");
JSONObject extractionValues = new JSONObject();
//Check if the user wants People entities
if(entitiesReqd.contains("People")) {
//***Extracting People***
JSONArray peopleExtract = (JSONArray) extraction.get("people");
JSONArray peopleValues = new JSONArray();
for(int i=0; i<peopleExtract.length(); i++) {
peopleValues.put(new JSONObject().put("extraction", ((JSONObject)peopleExtract.get(i)).getString("extraction")));
}
extractionValues.put("People", peopleValues);
}
//Check if the user wants Places entities
if(entitiesReqd.contains("Places")) {
//***Extracting Places***
JSONArray placesExtract = (JSONArray) extraction.get("places");
JSONArray placesValues = new JSONArray();
for(int i=0; i<placesExtract.length(); i++) {
placesValues.put(new JSONObject().put("extraction", ((JSONObject)placesExtract.get(i)).getString("extraction")));
}
extractionValues.put("Places", placesValues);
}
//Check if the user wants Date entities
if(entitiesReqd.contains("Dates")) {
//***Extracting People***
JSONArray datesExtract = (JSONArray) extraction.get("dates");
JSONArray datesValues = new JSONArray();
for(int i=0; i<datesExtract.length(); i++) {
datesValues.put(new JSONObject().put("extraction", ((JSONObject)datesExtract.get(i)).getString("extraction")));
}
extractionValues.put("Dates", datesValues);
}
JSONObject extractionsObj = new JSONObject();
extractionsObj.put("extractions", extractionValues);
JSONObject rowDataObject = new JSONObject();
rowDataObject.put("values", extractionsObj);
rowDataObject.put("rowId", row.getId());
rowData.put(rowDataObject);
}
}
}
JSONObject addValuesObj = new JSONObject();
addValuesObj.put("name", "AddValues");
addValuesObj.put("value", rowData.toString());
addValuesObj.put("type", "other");
JSONArray addValues = new JSONArray();
addValues.put(addValuesObj);
System.out.println(JSONUtil.prettyPrintJson(addValues.toString()));
try {
AddValuesCommandFactory factory = new AddValuesCommandFactory();
cmd = (AddValuesCommand) factory.createCommand(addValues, workspace, hNodeId, worksheetId,
ht.getId(), HNodeType.Transformation, selection.getName());
HNode hnode = repFactory.getHNode(hNodeId);
cmd.setColumnName(hnode.getColumnName()+" Extractions");
cmd.doIt(workspace);
newHNodeId = cmd.getNewHNodeId();
UpdateContainer c = new UpdateContainer(new InfoUpdate("Extracted Entities"));
c.append(WorksheetUpdateFactory
.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet)));
c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
//c.append(new InfoUpdate("Extracted Entities"));
return c;
} catch (Exception e) {
logger.error("Error in ExtractEntitiesCommand" + e.toString());
Util.logException(logger, e);
return new UpdateContainer(new ErrorUpdate(e.getMessage()));
}
// return new UpdateContainer(new InfoUpdate("Extracted Entities"));