/** * @param node * @param mapNodeToId * @param nodeToConllStringConvertor * @return * @throws ConllConverterException */ private static <I extends Info, N extends AbstractNode<I, N>> StringBuilder nodeToConll(N node, Map<N, Integer> mapNodeToId, Map<N, N> nodeToParentMap, TreeConllStringConverter<I, N> nodeToConllStringConvertor) throws ConllConverterException { StringBuilder conllStr = new StringBuilder(); conllStr.append(nodeToConllStringConvertor.convert(node, mapNodeToId, nodeToParentMap.get(node))).append('\n'); if (node.hasChildren()) for (N child : node.getChildren()) conllStr.append(nodeToConll(child, mapNodeToId, nodeToParentMap, nodeToConllStringConvertor)); return conllStr; }
private boolean hasCopula(S node) { if (node.hasChildren()) { for (S child : node.getChildren()) { String relation = InfoGetFields.getRelation(child.getInfo()); if (COPULA_RELATION.equals(relation)) { return true; } } } return false; }
/** * @param node * @param mapNodeToId * @param id * @param nodeToConllStringConvertor * @param variableId * @return * @throws ConllConverterException */ private static <I extends Info, N extends AbstractNode<I, N>> StringBuilder nodeToConll(N node, BidirectionalMap<N, N> alignments, Map<N, Integer> mapNodeToId, RuleConllStringConverter<I, N> nodeToConllStringConvertor) throws ConllConverterException { StringBuilder conllStr = new StringBuilder(); int variableId = -1; // -1 means no alignment if (alignments.leftContains(node)) variableId = mapNodeToId.get(alignments.leftGet(node)); else if (alignments.rightContains(node)) variableId = mapNodeToId.get(alignments.rightGet(node)); conllStr.append(nodeToConllStringConvertor.convert(node, mapNodeToId, variableId)).append('\n'); if (node.hasChildren()) for (N child : node.getChildren()) conllStr.append(nodeToConll(child, alignments , mapNodeToId, nodeToConllStringConvertor)); return conllStr; }
private Set<S> getPredicateInternalNodes(S node) { Set<S> ret = new LinkedHashSet<S>(); ret.add(node); if (node.hasChildren()) { for (S child : node.getChildren()) { String relation = InfoGetFields.getRelation(child.getInfo()); if (RelationTypes.getSemanticInternalFacetRelations().contains(relation)) { ret.addAll(getPredicateInternalNodes(child)); } } } return ret; }
private Set<S> getPredicateInternalNodes(S node, Set<S> excludedDirectChildren) { Set<S> ret = new LinkedHashSet<S>(); ret.add(node); if (node.hasChildren()) { for (S child : node.getChildren()) { if (!excludedDirectChildren.contains(child)) { String relation = InfoGetFields.getRelation(child.getInfo()); if (RelationTypes.getSemanticInternalFacetRelations().contains(relation)) { ret.addAll(getPredicateInternalNodes(child)); } } } } return ret; }
public static <I extends Info, S extends AbstractNode<I, S>> Set<S> getInternalNodes(S node) { Set<S> ret = new LinkedHashSet<S>(); ret.add(node); if (node.hasChildren()) { for (S child : node.getChildren()) { String relation = InfoGetFields.getRelation(child.getInfo()); if (RelationTypes.getSemanticInternalFacetRelations().contains(relation)) { ret.addAll(getInternalNodes(child)); } } } return ret; }
/** * skip the artificial "ROOT" node * @param tree * @return * @throws AnnotatorException */ public static <N extends AbstractNode<? extends Info, N>> N skipRoot(N tree) throws AnnotatorException { if (tree == null) throw new AnnotatorException("got null tree"); N nodeToAnnotate; if (tree.getInfo().getId().equals(AbstractMiniparParser.ROOT_NODE_ID)) // skip the artificial "ROOT" node if (tree.hasChildren()) nodeToAnnotate = tree.getChildren().get(0); else throw new AnnotatorException("got a sentence that is an empty root: " + tree); else nodeToAnnotate = tree; return nodeToAnnotate; }
if (predicate.getHead().hasChildren())
/** * Given a node in the parse-tree, this method finds a direct-child of that node * that is connected to it via "ref" relation, and also has an antecedent. * * @param node * @return */ @StandardSpecific("stanford-dependencies") @ParserSpecific("easyfirst") public static <I extends Info, S extends AbstractNode<I, S>> S getRefWithAntecedent(S node) { S refWithAntecedent = null; if (node.hasChildren()) { for (S child : node.getChildren()) { if ("ref".equals(InfoGetFields.getRelation(child.getInfo()))) { if (child.getAntecedent()!=null) { refWithAntecedent = child; break; } } } } return refWithAntecedent; }
if (predicateHead.hasChildren())
/** * make sure each node under the root has a relation and a POS * @param root * @throws CompilationException */ private static <I extends Info, N extends AbstractNode<I,N>> void sanityCheckChildren(N root) throws CompilationException { if (root.hasChildren()) for (N child : root.getChildren()) { // make sure each node under the root has a relation if (ExtendedInfoGetFields.getRelation(child .getInfo(), null) == null) throw new CompilationException("This node has no relation: " + child ); checkPos(child ); sanityCheckChildren(child); } }
if (InfoGetFields.getRelation(child.getInfo()).equals("prep")) if (child.hasChildren())
if (predicateHead.hasChildren())