Exemplo n.º 1
0
  public JSONObject getAsJSONObject(OntologyManager ontMgr) throws JSONException {
    JSONObject obj = new JSONObject();
    JSONArray arr = new JSONArray();

    // Need to sort
    HashMap<String, Double> sortedMap = Util.sortHashMap(scoreMap);

    for (String label : sortedMap.keySet()) {
      JSONObject oj = new JSONObject();

      // Check if the type contains domain
      if (label.contains("|")) {
        URI domainURI = ontMgr.getURIFromString(label.split("\\|")[0]);
        URI typeURI = ontMgr.getURIFromString(label.split("\\|")[1]);
        if (domainURI == null || typeURI == null) continue;
        oj.put(
            SemanticTypesUpdate.JsonKeys.DisplayDomainLabel.name(),
            domainURI.getLocalNameWithPrefixIfAvailable());
        oj.put(SemanticTypesUpdate.JsonKeys.Domain.name(), label.split("\\|")[0]);
        oj.put(
            SemanticTypesUpdate.JsonKeys.DisplayLabel.name(),
            typeURI.getLocalNameWithPrefixIfAvailable());
        oj.put(SemanticTypesUpdate.JsonKeys.FullType.name(), label.split("\\|")[1]);
      } else {
        URI typeURI = ontMgr.getURIFromString(label);
        if (typeURI == null) continue;
        oj.put(SemanticTypesUpdate.JsonKeys.FullType.name(), label);
        oj.put(
            SemanticTypesUpdate.JsonKeys.DisplayLabel.name(),
            typeURI.getLocalNameWithPrefixIfAvailable());
        oj.put(SemanticTypesUpdate.JsonKeys.DisplayDomainLabel.name(), "");
        oj.put(SemanticTypesUpdate.JsonKeys.Domain.name(), "");
      }

      oj.put("Probability", scoreMap.get(label));
      arr.put(oj);
    }
    obj.put("Labels", arr);
    return obj;
  }
Exemplo n.º 2
0
 @Override
 public void write(JSONWriter writer) throws JSONException {
   writer.object();
   writer.array();
   for (String label : scoreMap.keySet()) {
     writer.object();
     writer.key(SemanticTypesUpdate.JsonKeys.FullType.name()).value(label);
     writer.key("probability").value(scoreMap.get(label));
     writer.endObject();
   }
   writer.endArray();
   writer.endObject();
 }