TreebankNodeUtil { public static List<TreebankNode> getPathToRoot(TreebankNode startNode) { List<TreebankNode> nlist = new ArrayList<TreebankNode>(20); TreebankNode cursorNode = startNode; while (cursorNode != null) { nlist.add(cursorNode); cursorNode = cursorNode.getParent(); } return nlist; }  static TreebankNode selectMatchingLeaf(JCas jCas, Annotation annotation); static TreebankNode selectHighestMatchingTreebankNode(JCas jCas, Annotation annotation); static TreebankNode selectHighestCoveredTreebankNode(JCas jCas, Annotation annotation); static int getDepth(TreebankNode node); static List<TreebankNode> getPathToRoot(TreebankNode startNode); static TreebankNodePath getPath(TreebankNode source, TreebankNode target); static String toTreebankString(TreebankNode node); static TreebankNode getParent(TreebankNode node); static TreebankNode getAncestorWithType(TreebankNode node, String type); static TreebankNode newNode(JCas jCas, int begin, int end, String nodeType); static TreebankNode newNode(JCas jCas, String nodeType, TreebankNode... children); static TopTreebankNode getTopNode(TreebankNode node); static void print(PrintStream out, TreebankNode node);  }
@Test public void testGetPathToRoot() throws Exception { this.jCas.setDocumentText("The cat chased mice ."); top( "S", jCas, node("NP", jCas, leaf("DT", "The", jCas), leaf("NN", "cat", jCas)), node("VP", jCas, leaf("VBD", "chased", jCas), node("NP", jCas, leaf("NNS", "mice", jCas))), leaf(".", ".", jCas)); TopTreebankNode root = JCasUtil.selectSingle(this.jCas, TopTreebankNode.class); Assert.assertEquals(Arrays.asList(root), TreebankNodeUtil.getPathToRoot(root)); TreebankNode np = root.getChildren(0); TreebankNode vp = root.getChildren(1); TreebankNode period = root.getChildren(2); Assert.assertEquals(Arrays.asList(np, root), TreebankNodeUtil.getPathToRoot(np)); Assert.assertEquals(Arrays.asList(vp, root), TreebankNodeUtil.getPathToRoot(vp)); Assert.assertEquals(Arrays.asList(period, root), TreebankNodeUtil.getPathToRoot(period)); TreebankNode the = np.getChildren(0); TreebankNode cat = np.getChildren(1); Assert.assertEquals(Arrays.asList(the, np, root), TreebankNodeUtil.getPathToRoot(the)); Assert.assertEquals(Arrays.asList(cat, np, root), TreebankNodeUtil.getPathToRoot(cat)); TreebankNode chased = vp.getChildren(0); TreebankNode np2 = vp.getChildren(1); Assert.assertEquals(Arrays.asList(chased, vp, root), TreebankNodeUtil.getPathToRoot(chased)); Assert.assertEquals(Arrays.asList(np2, vp, root), TreebankNodeUtil.getPathToRoot(np2)); TreebankNode mice = np2.getChildren(0); Assert.assertEquals(Arrays.asList(mice, np2, vp, root), TreebankNodeUtil.getPathToRoot(mice)); }