ParseHelper { public static Constituent getPhraseFromHead(Constituent predicate, Constituent argHead, String parseViewName) { TextAnnotation ta = argHead.getTextAnnotation(); int sentenceOffset = ta.getSentence(ta.getSentenceId(argHead)).getStartSpan(); int argStart = argHead.getStartSpan() - sentenceOffset; Tree<Pair<String, IntPair>> predParentTree = getTokenIndexedTreeCovering(predicate, parseViewName).getParent(); boolean found = false; for (Tree<Pair<String, IntPair>> s : predParentTree.getYield()) { if (s.getLabel().getSecond().getFirst() == argStart) found = true; } if (!found) return null; Tree<Pair<String, IntPair>> argPhrase = getTokenIndexedTreeCovering(argHead, parseViewName); while (!checkForPredicate(argPhrase.getParent(), predicate.getStartSpan() - sentenceOffset)) { if (argPhrase.getParent() == null) break; argPhrase = argPhrase.getParent(); } if (argPhrase.getParent() == null) return null; int start = predicate.getStartSpan() + 1; int end = start + argPhrase.getYield().size(); return new Constituent(argHead.getLabel(), argHead.getViewName(), argHead.getTextAnnotation(), start, end); }  static String[] getAllPhraseSiblingLabels(String parseViewName, Constituent constituent); static String[] getAllSiblingLabels(Tree<String> node); @Deprecated static Tree<T> getCommonAncestor(Tree<T> t1, Tree<T> t2, Tree<T> tree); static Tree<String> getParseTree(String parseViewName, Sentence s); static Tree<String> getParseTree(String parseViewName, TextAnnotation ta, int sentenceId); @Deprecated static Tree<String> getParseTree(TextAnnotation ta, int sentenceId); static Tree<String> getParseTreeCovering(String parseViewName, Constituent c); @Deprecated static Pair<List<Tree<T>>, List<Tree<T>>> getPath(Tree<T> start, Tree<T> end,
            Tree<T> tree, int maxDepth); @Deprecated static String getPathString(Tree<T> start, Tree<T> end, Tree<T> tree, int maxDepth); @Deprecated static String getPathStringIgnoreLexicalItems(Tree<T> start, Tree<T> end,
            Tree<T> tree, int maxDepth); @Deprecated static String getPathStringToCommonAncestor(Tree<T> start, Tree<T> end,
            Tree<T> tree, int maxDepth); @Deprecated static List<T> getPathToRoot(Tree<T> tree, Tree<T> leaf, int maxDepth); @Deprecated static List<Tree<T>> getPathTreesToRoot(Tree<T> tree, Tree<T> node, int maxDepth); static String getSubcatFrame(Tree<String> yieldNode); static String getTerminalString(Tree<String> tree); static String getTerminalStringSentence(Tree<String> tree); static List<String> getTerminalTokens(Tree<String> tree); static Tree<Pair<String, IntPair>> getTokenIndexedCleanedParseTreeNodeCovering(
            Constituent c, String parseViewName); static Tree<Pair<String, IntPair>> getTokenIndexedParseTreeNodeCovering(
            String parseViewName, Constituent c); static Tree<Pair<String, IntPair>> getTokenIndexedTreeCovering(Tree<String> parse,
            int start, int end); static Tree<String> getTreeCovering(Tree<String> parse, int start, int end); static int getHeadWordPosition(Constituent c, HeadFinderBase headFinder,
            String parseViewName); static Constituent getPhraseFromHead(Constituent predicate, Constituent argHead,
            String parseViewName); final static String PATH_UP_STRING; final static String PATH_DOWN_STRING; }
@Test public void testGetPhraseFromHead() { PredicateArgumentView prepSRLView = new PredicateArgumentView(ViewNames.SRL_PREP, "test", ta, 1.0); Constituent predicate = new Constituent("with", ViewNames.SRL_PREP, ta, 2, 3); predicate.addAttribute(PredicateArgumentView.LemmaIdentifier, "Attribute"); Constituent argGov = new Constituent("", ViewNames.SRL_PREP, ta, 0, 2); Constituent argObj = new Constituent("", ViewNames.SRL_PREP, ta, 4, 5); prepSRLView.addConstituent(predicate); prepSRLView.addConstituent(argGov); prepSRLView.addConstituent(argObj); prepSRLView.addRelation(new Relation("Governor", predicate, argGov, 1.0)); prepSRLView.addRelation(new Relation("Object", predicate, argObj, 1.0)); ta.addView(ViewNames.SRL_PREP, prepSRLView); Constituent argPhrase = ParseHelper.getPhraseFromHead(predicate, argObj, parserView); assert argPhrase != null; assertEquals("bag", argObj.toString()); assertEquals("a bag", argPhrase.toString()); }