/** Normalizes empty category indices and gapping relation indices of the specific tree. */ public void normalizeIndices() { // retrieve all co-indexes IntObjectHashMap<List<CTNode>> mOrg = new IntObjectHashMap<List<CTNode>>(); getCoIndexMap(n_root, mOrg); if (mOrg.isEmpty()) return; List<ObjectIntPair<List<CTNode>>> ps = mOrg.toList(); Collections.sort(ps); IntIntOpenHashMap mNew = new IntIntOpenHashMap(); int coIndex = 1, last, i; boolean isAnteFound; List<CTNode> list; CTNode curr, ec; for (ObjectIntPair<List<CTNode>> p : ps) { list = p.o; last = list.size() - 1; isAnteFound = false; for (i = last; i >= 0; i--) { curr = list.get(i); if (curr.isEmptyCategoryTerminal()) { ec = curr.getTerminalList().get(0); if (i == last || isAnteFound || CTLibEn.isDiscontinuousConstituent(ec) || CTLibEn.containsCoordination(curr.getLowestCommonAncestor(list.get(i + 1)))) curr.setEmptyCategoryIndex(-1); else curr.setEmptyCategoryIndex(coIndex++); if (isAnteFound || i > 0) ec.appendWordForm("-" + coIndex); } else if (isAnteFound) { curr.setEmptyCategoryIndex(-1); } else { curr.setEmptyCategoryIndex(coIndex); mNew.put(p.i, coIndex); isAnteFound = true; } } coIndex++; } int[] lastIndex = {coIndex}; remapGapIndices(mNew, lastIndex, n_root); }
/** Called by {@link #normalizeIndices()}. */ private void getCoIndexMap(CTNode curr, IntObjectHashMap<List<CTNode>> map) { if (!curr.isTerminal()) { if (curr.getEmptyCategoryIndex() != -1) { int key = curr.getEmptyCategoryIndex(); List<CTNode> list; if (map.containsKey(key)) list = map.get(key); else { list = new ArrayList<CTNode>(); map.put(key, list); } list.add(curr); } for (CTNode child : curr.getChildrenList()) getCoIndexMap(child, map); } else if (curr.isEmptyCategory()) { if (curr.isWordForm("*0*")) curr.setWordForm("0"); } }