private static View readView(JsonObject json, TextAnnotation ta) throws Exception { String viewClass = readString("viewType", json); String viewName = readString("viewName", json); String viewGenerator = readString("generator", json); double score = 0; if (json.has("score")) score = readDouble("score", json); View view = createEmptyView(ta, viewClass, viewName, viewGenerator, score); List<Constituent> constituents = new ArrayList<>(); if (json.has("constituents")) { JsonArray cJson = json.getAsJsonArray("constituents"); for (int i = 0; i < cJson.size(); i++) { JsonObject cJ = (JsonObject) cJson.get(i); Constituent c = readConstituent(cJ, ta, viewName); constituents.add(c); view.addConstituent(c); } } if (json.has("relations")) { JsonArray rJson = json.getAsJsonArray("relations"); for (int i = 0; i < rJson.size(); i++) { JsonObject rJ = (JsonObject) rJson.get(i); String name = readString("relationName", rJ); double s = 0; if (rJ.has("score")) s = readDouble("score", rJ); int src = readInt("srcConstituent", rJ); int tgt = readInt("targetConstituent", rJ); Map<String, Double> labelsToScores = null; if (rJ.has(LABEL_SCORE_MAP)) { labelsToScores = new HashMap<>(); readLabelsToScores(labelsToScores, rJ); } Relation rel = null; if (null == labelsToScores) rel = new Relation(name, constituents.get(src), constituents.get(tgt), s); else rel = new Relation(labelsToScores, constituents.get(src), constituents.get(tgt)); readAttributes(rel, rJ); view.addRelation(rel); } } return view; }