Java Code Examples for edu.stanford.nlp.semgraph.SemanticGraph#hasChildren()

The following examples show how to use edu.stanford.nlp.semgraph.SemanticGraph#hasChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoreNLPUtils.java    From minie with GNU General Public License v3.0 6 votes vote down vote up
private static SemanticGraph getSubgraph(ObjectArrayList<TypedDependency> tds, SemanticGraph sg, IndexedWord parent,
        SemanticGraphEdge e, int maxPathLength, ObjectArrayList<IndexedWord> words){
    Set<IndexedWord> children = sg.getChildren(parent);
    
    for (IndexedWord child: children){
        if (((sg.getShortestDirectedPathEdges(sg.getFirstRoot(), child)).size() <= maxPathLength) &&
                words.contains(child)){   
            e = sg.getEdge(parent, child);
            tds.add(new TypedDependency(e.getRelation(), parent, child));
            if (sg.hasChildren(child))
                getSubgraph(tds, sg, child, e, maxPathLength, words);
        } // else break;
    }

    TreeGraphNode rootTGN = new TreeGraphNode(new CoreLabel(parent));
    EnglishGrammaticalStructure gs = new EnglishGrammaticalStructure(tds, rootTGN);
    return SemanticGraphFactory.generateUncollapsedDependencies(gs);
}
 
Example 2
Source File: CoreNLPUtils.java    From minie with GNU General Public License v3.0 5 votes vote down vote up
private static ObjectArrayList<TypedDependency> getSubgraphTypedDependencies(SemanticGraph sg, IndexedWord parent, 
        ObjectArrayList<TypedDependency> tds){
    Set<IndexedWord> children = sg.getChildren(parent);
    
    for (IndexedWord child: children){
        GrammaticalRelation gRel = sg.getEdge(parent, child).getRelation();
        tds.add(new TypedDependency(gRel, parent, child));
        if (sg.hasChildren(child))
            getSubgraphTypedDependencies(sg, child, tds);
    }
    
    return tds; 
}