public static JSONObject getLabelJson(int crisisID, DocumentLabel label) { try { if (label instanceof NominalLabelBC) { // logger.info("Going to insert existing label to nominal_labels"); NominalLabelBC l = (NominalLabelBC) label; ModelFamilyEC family = getModelFamily(crisisID, l.getAttributeID()); JSONObject obj = new JSONObject(); obj.put("source_id", l.getSourceID()); obj.put("attribute_code", family.getNominalAttribute().getCode()); obj.put("attribute_name", family.getNominalAttribute().getName()); obj.put("attribute_description", family.getNominalAttribute().getDescription()); NominalLabelEC lEC = family.getNominalAttribute().getNominalLabel(l.getNominalLabelID()); obj.put("label_code", lEC.getNominalLabelCode()); obj.put("label_name", lEC.getName()); obj.put("label_description", lEC.getDescription()); obj.put("confidence", l.getConfidence()); obj.put("from_human", l.isHumanLabel()); return obj; } } catch (JSONException e) { logger.error("Error in creating json object from: " + label); logger.error(elog.toStringException(e)); throw new RuntimeException(e); } logger.error("Unsupported label type: " + label.getClass().getSimpleName()); throw new RuntimeException("Unsupported label type: " + label.getClass().getSimpleName()); }
@SuppressWarnings("unchecked") public <T extends DocumentLabel> ArrayList<T> getLabels(Class<T> classFilter) { ArrayList<T> items = new ArrayList<T>(); for (DocumentLabel label : labels) { if (classFilter.isAssignableFrom(label.getClass())) items.add((T) label); } return items; }