public static void replaceChild(TreebankNode parent, TreebankNode oldTree, TreebankNode newTree) { // if parent is null that means we're already at the top -- no pointers to fix. if(parent != null){ for(int i = 0; i < parent.getChildren().size(); i++){ if(parent.getChildren(i) == oldTree){ parent.setChildren(i, newTree); } } } }
public static void replaceChild(TreebankNode parent, TreebankNode oldTree, TreebankNode newTree) { // if parent is null that means we're already at the top -- no pointers to fix. if(parent != null){ for(int i = 0; i < parent.getChildren().size(); i++){ if(parent.getChildren(i) == oldTree){ parent.setChildren(i, newTree); } } } }
lca = new TopTreebankNode(jcas); lca.setNodeType("TOP"); lca.setChildren(new FSArray(jcas,2)); if(l1.size()==0){ l1.add(t1); l2.add(t2); lca.setChildren(0, l1.get(0)); lca.setChildren(1, l2.get(0));
lca = new TopTreebankNode(jcas); lca.setNodeType("TOP"); lca.setChildren(new FSArray(jcas,2)); if(l1.size()==0){ l1.add(t1); l2.add(t2); lca.setChildren(0, l1.get(0)); lca.setChildren(1, l2.get(0));
public static TreebankNode getTreeCopy(JCas jcas, TreebankNode orig){ TreebankNode copy = null; if(orig instanceof TerminalTreebankNode){ copy = new TerminalTreebankNode(jcas); copy.setLeaf(true); copy.setChildren(null); }else{ copy = new TreebankNode(jcas); copy.setChildren(new FSArray(jcas, orig.getChildren().size())); for(int i = 0; i < orig.getChildren().size(); i++){ copy.setChildren(i, getTreeCopy(jcas, orig.getChildren(i))); copy.getChildren(i).setParent(copy); } } copy.setNodeType(orig.getNodeType()); copy.setNodeValue(orig.getNodeValue()); copy.setBegin(orig.getBegin()); copy.setEnd(orig.getEnd()); return copy; }
public static TreebankNode getTreeCopy(JCas jcas, TreebankNode orig){ TreebankNode copy = null; if(orig instanceof TerminalTreebankNode){ copy = new TerminalTreebankNode(jcas); copy.setLeaf(true); copy.setChildren(null); }else{ copy = new TreebankNode(jcas); copy.setChildren(new FSArray(jcas, orig.getChildren().size())); for(int i = 0; i < orig.getChildren().size(); i++){ copy.setChildren(i, getTreeCopy(jcas, orig.getChildren(i))); copy.getChildren(i).setParent(copy); } } copy.setNodeType(orig.getNodeType()); copy.setNodeValue(orig.getNodeValue()); copy.setBegin(orig.getBegin()); copy.setEnd(orig.getEnd()); return copy; }
tree.setChildren(conceptIndex, entityRoot); entityRoot.setParent(tree); replacementNode.setChildren(tree.getChildren()); for(int i = 0; i < replacementNode.getChildren().size(); i++){ replacementNode.getChildren(i).setParent(replacementNode); tree.setChildren(children);
tree.setChildren(conceptIndex, entityRoot); entityRoot.setParent(tree); replacementNode.setChildren(tree.getChildren()); for(int i = 0; i < replacementNode.getChildren().size(); i++){ replacementNode.getChildren(i).setParent(replacementNode); tree.setChildren(children);
public static void removeRightOfAnnotation(JCas jcas, TreebankNode node, Annotation annot) { // if the whole tree is to the left of the annotation then do nothing: if(node.getEnd() <= annot.getBegin() || node.getLeaf()) return; // if there is some overlap then iterate over trees, ignoring those to the left, recursing on those that overlap, and deleting those to the right for(int i = 0; i < node.getChildren().size(); i++){ TreebankNode child = node.getChildren(i); if(child.getEnd() <= annot.getBegin()){ // child is to the left of annotation completely continue; }else if(child.getBegin() > annot.getEnd()){ // child is to the right of annotation completely -- remove it and all to the right FSArray newChildren = new FSArray(jcas, i); for(int j = 0; j < i; j++){ newChildren.set(j, node.getChildren(j)); } node.setChildren(newChildren); break; }else{ removeRightOfAnnotation(jcas, child, annot); } } }
newTree.setChildren(new FSArray(jcas, 1)); newTree.setChildren(0, tree); newTree.setParent(tree.getParent()); TreeUtils.replaceChild(tree.getParent(), tree, newTree); newTree.setParent(tree); int numStolenChildren = endChild-startChild+1; newTree.setChildren(new FSArray(jcas, numStolenChildren)); newTree.setChildren(i-startChild, tree.getChildren(i)); children.set(i-numStolenChildren+1, tree.getChildren(i)); tree.setChildren(children); }else{ newTree.setChildren(new FSArray(jcas, 1)); newTree.setChildren(0, tree); newTree.setParent(tree.getParent()); TreeUtils.replaceChild(tree.getParent(), tree, newTree);
public static void removeRightOfAnnotation(JCas jcas, TreebankNode node, Annotation annot) { // if the whole tree is to the left of the annotation then do nothing: if(node.getEnd() <= annot.getBegin() || node.getLeaf()) return; // if there is some overlap then iterate over trees, ignoring those to the left, recursing on those that overlap, and deleting those to the right for(int i = 0; i < node.getChildren().size(); i++){ TreebankNode child = node.getChildren(i); if(child.getEnd() <= annot.getBegin()){ // child is to the left of annotation completely continue; }else if(child.getBegin() > annot.getEnd()){ // child is to the right of annotation completely -- remove it and all to the right FSArray newChildren = new FSArray(jcas, i); for(int j = 0; j < i; j++){ newChildren.set(j, node.getChildren(j)); } node.setChildren(newChildren); break; }else{ removeRightOfAnnotation(jcas, child, annot); } } }
newTree.setChildren(new FSArray(jcas, 1)); newTree.setChildren(0, tree); newTree.setParent(tree.getParent()); TreeUtils.replaceChild(tree.getParent(), tree, newTree); newTree.setParent(tree); int numStolenChildren = endChild-startChild+1; newTree.setChildren(new FSArray(jcas, numStolenChildren)); newTree.setChildren(i-startChild, tree.getChildren(i)); children.set(i-numStolenChildren+1, tree.getChildren(i)); tree.setChildren(children); }else{ newTree.setChildren(new FSArray(jcas, 1)); newTree.setChildren(0, tree); newTree.setParent(tree.getParent()); TreeUtils.replaceChild(tree.getParent(), tree, newTree);
parent.setChildren(children);
parent.setChildren(children);
public static void removeLeftOfAnnotation(JCas jcas, TreebankNode node, Annotation annot) { if(node.getEnd() <= annot.getBegin() || node.getLeaf()) return; // go through tree and create a list of children that are overalpping or to the right of the concept node: for(int i = 0; i < node.getChildren().size(); i++){ TreebankNode child = node.getChildren(i); if(child.getEnd() < annot.getBegin()){ // ignore for now but this will be removed later continue; }else if(child.getEnd() > annot.getBegin()){ // if it has substructure to the left of the concept we have to recurse if(child.getBegin() < annot.getBegin()){ removeLeftOfAnnotation(jcas, child, annot); } if(i > 0){ // if we're leaving some out we need to rebuild the whole children array // now create a child array of children partially or completely to the right FSArray newChildren = new FSArray(jcas, node.getChildren().size()-i); for(int j = i; j < node.getChildren().size(); j++){ newChildren.set(j-i, node.getChildren(j)); } node.setChildren(newChildren); } break; } } }
public static void removeLeftOfAnnotation(JCas jcas, TreebankNode node, Annotation annot) { if(node.getEnd() <= annot.getBegin() || node.getLeaf()) return; // go through tree and create a list of children that are overalpping or to the right of the concept node: for(int i = 0; i < node.getChildren().size(); i++){ TreebankNode child = node.getChildren(i); if(child.getEnd() < annot.getBegin()){ // ignore for now but this will be removed later continue; }else if(child.getEnd() > annot.getBegin()){ // if it has substructure to the left of the concept we have to recurse if(child.getBegin() < annot.getBegin()){ removeLeftOfAnnotation(jcas, child, annot); } if(i > 0){ // if we're leaving some out we need to rebuild the whole children array // now create a child array of children partially or completely to the right FSArray newChildren = new FSArray(jcas, node.getChildren().size()-i); for(int j = i; j < node.getChildren().size(); j++){ newChildren.set(j-i, node.getChildren(j)); } node.setChildren(newChildren); } break; } } }