public static DEPTree buildFrom(IDEPTreeDatum treeDatum) { List<IDEPNodeDatum> nodeData = treeDatum.getDEPNodeData(); DEPTree tree = new DEPTree(); int i, size = nodeData.size(); IDEPNodeDatum nd; DEPNode node; for (i = 0; i < size; i++) { nd = nodeData.get(i); tree.add( new DEPNode( nd.getID(), nd.getForm(), nd.getLemma(), nd.getPOS(), nd.getNamedEntity(), new DEPFeat(nd.getFeats()))); } for (i = 0; i < size; i++) { nd = nodeData.get(i); node = tree.get(i + 1); node.initSHeads(); node.setHead(new DEPArc(tree, nd.getSyntacticHead())); node.addSHeads(DEPLib.getSRLArcs(tree, nd.getSemanticHeads())); } tree.resetDependents(); return tree; }
public DEPTree clone() { IntObjectOpenHashMap<DEPNode> map = new IntObjectOpenHashMap<DEPNode>(); DEPNode oNode, nNode, oHead, nHead; DEPTree tree = new DEPTree(); int i, size = size(); for (i = 1; i < size; i++) { oNode = get(i); nNode = new DEPNode(oNode); tree.add(nNode); nNode.id = i; map.put(oNode.id, nNode); if (oNode.x_heads != null) nNode.initXHeads(); if (oNode.s_heads != null) nNode.initSHeads(); } for (i = 1; i < size; i++) { oNode = get(i); nNode = tree.get(i); oHead = oNode.getHead(); nHead = map.get(oHead.id); if (nHead == null) { nHead = tree.get(0); } else { if (oNode.x_heads != null) { for (DEPArc xHead : oNode.x_heads) { oHead = xHead.getNode(); nNode.addXHead(map.get(oHead.id), xHead.getLabel()); } } if (oNode.s_heads != null) { for (DEPArc sHead : oNode.s_heads) { oHead = sHead.getNode(); nNode.addSHead(map.get(oHead.id), sHead.getLabel()); } } } nNode.setHead(nHead, oNode.getLabel()); } return tree; }