Example #1
0
  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());
  }
Example #2
0
 public static NominalLabelBC parseNominalLabel(JSONObject input) {
   try {
     int crisisID = getCrisisID(input.getString("crisis_code"));
     ModelFamilyEC modelFamily = getModelFamily(crisisID, input.getString("attribute_code"));
     NominalAttributeEC attr = modelFamily.getNominalAttribute();
     NominalLabelBC l =
         new NominalLabelBC(
             input.getLong("source_id"),
             attr.getNominalAttributeID(),
             attr.getNominalLabel(input.getString("label_code")).getNominalLabelID(),
             input.getDouble(
                 "confidence")); // TODO: Remove this, training samples should be "true"
     if (input.has("from_human")) l.setHumanLabel(input.getBoolean("from_human"));
     return l;
   } catch (JSONException e) {
     logger.error("Error in parsing nominal label for: " + input);
     logger.error(elog.toStringException(e));
     throw new RuntimeException(e);
   }
 }
Example #3
0
  private static void updateModelInfo() {
    activeModelFamiliesByID.clear();
    activeModelFamiliesByCode.clear();
    activeCrisisIDs.clear();

    activeCrisisIDs = DataStore.getCrisisIDs();

    ArrayList<ModelFamilyEC> families = DataStore.getActiveModels();
    for (ModelFamilyEC family : families) {

      int crisisID = family.getCrisisID();
      int attributeID = family.getNominalAttribute().getNominalAttributeID();
      String attributeCode = family.getNominalAttribute().getCode();

      if (!activeModelFamiliesByID.containsKey(crisisID)) {
        activeModelFamiliesByID.put(crisisID, new HashMap<Integer, ModelFamilyEC>());
        activeModelFamiliesByCode.put(crisisID, new HashMap<String, ModelFamilyEC>());
      }
      activeModelFamiliesByID.get(crisisID).put(attributeID, family);
      activeModelFamiliesByCode.get(crisisID).put(attributeCode, family);
    }

    lastModelInfoUpdate = System.currentTimeMillis();
  }