private void setBestPathMap(WrappedPositionArray positions, int startPos, Position endPosData, int fromIDX) { bestPathMap.clear(); int pos = endPosData.pos; int bestIDX = fromIDX; while (pos > startPos) { final Position posData = positions.get(pos); final int backPos = posData.backPos[bestIDX]; final int backIDX = posData.backIndex[bestIDX]; final String toNodeID = getNodeID(pos, bestIDX); final String fromNodeID = getNodeID(backPos, backIDX); assert !bestPathMap.containsKey(fromNodeID); assert !bestPathMap.containsValue(toNodeID); bestPathMap.put(fromNodeID, toNodeID); pos = backPos; bestIDX = backIDX; } }
void onBacktrace(JapaneseTokenizer tok, WrappedPositionArray positions, int lastBackTracePos, Position endPosData, int fromIDX, char[] fragment, boolean isEnd) { setBestPathMap(positions, lastBackTracePos, endPosData, fromIDX); sb.append(formatNodes(tok, positions, lastBackTracePos, endPosData, fragment)); if (isEnd) { sb.append(" fini [style=invis]\n"); sb.append(" "); sb.append(getNodeID(endPosData.pos, fromIDX)); sb.append(" -> fini [label=\"" + EOS_LABEL + "\"]"); } }