当前位置: 首页>>代码示例>>Java>>正文


Java SemanticGraph.getOutEdgesSorted方法代码示例

本文整理汇总了Java中edu.stanford.nlp.semgraph.SemanticGraph.getOutEdgesSorted方法的典型用法代码示例。如果您正苦于以下问题:Java SemanticGraph.getOutEdgesSorted方法的具体用法?Java SemanticGraph.getOutEdgesSorted怎么用?Java SemanticGraph.getOutEdgesSorted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.stanford.nlp.semgraph.SemanticGraph的用法示例。


在下文中一共展示了SemanticGraph.getOutEdgesSorted方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findDescendantRelativeRelation

import edu.stanford.nlp.semgraph.SemanticGraph; //导入方法依赖的package包/类
/** Finds the first occurrence of a grammatical relation or its descendants for a relative pronoun */
public static SemanticGraphEdge findDescendantRelativeRelation(SemanticGraph semanticGraph, IndexedWord root, 
        GrammaticalRelation rel) {
    List<SemanticGraphEdge> outedges = semanticGraph.getOutEdgesSorted(root);
    for (SemanticGraphEdge e : outedges) {
        if (e.getDependent().tag().charAt(0) == 'W' && rel.isAncestor(e.getRelation())) {
            return e;
        } else
            return findDescendantRelativeRelation(semanticGraph, e.getDependent(), rel);
    }
    return null;
}
 
开发者ID:gkiril,项目名称:minie,代码行数:13,代码来源:DpUtils.java

示例2: subgraph

import edu.stanford.nlp.semgraph.SemanticGraph; //导入方法依赖的package包/类
/** Implementation for
 * {@link #removeEdges(SemanticGraph, IndexedWord, Collection, Collection, Collection)} */
private static int subgraph(SemanticGraph graph, IndexedWord root, Collection<IndexedWord> excludeVertexes,
        Collection<GrammaticalRelation> excludeRelations, Collection<GrammaticalRelation> excludeRelationsTop,
        Collection<SemanticGraphEdge> edgesToRemove, int counter) {
    
    /* TODO: In some sentences there is infinite recursion. Dirty fix to stop it. 
     
     Example sentence:
     "Policies on electronic tickets differ ''from airline to airline and airport to airport,'' said Ms. McInerney, 
     whose group is working with the airline industry on e-ticket policies and the matter of standardizing itineraries 
     and receipts, perhaps with a universal template to create more readily verifiable printouts that carry uniform 
     information like a ticket number that can be matched to an airline computer reservation."
 
     */
    counter++;
    if (counter > MAX_RECURSION_ITERATIONS){
        return counter;
    }

    List<SemanticGraphEdge> edges = graph.getOutEdgesSorted(root);
    for (SemanticGraphEdge e : edges) {
        IndexedWord child = e.getDependent();
        if (excludeVertexes.contains(child) || excludeRelations.contains(e.getRelation())
                || excludeRelationsTop.contains(e.getRelation())) {
            edgesToRemove.add(graph.getEdge(root, child));
        } else {
            counter = subgraph(graph, child, excludeVertexes, excludeRelations, 
                    Collections.<GrammaticalRelation> emptySet(), edgesToRemove, counter);
        }
    }
    
    return counter;
}
 
开发者ID:gkiril,项目名称:minie,代码行数:35,代码来源:DpUtils.java

示例3: disconectClauses

import edu.stanford.nlp.semgraph.SemanticGraph; //导入方法依赖的package包/类
/** Disconnects independent clauses by removing the edge representing the coordinating conjunction */
public static void disconectClauses(SemanticGraph graph, Constituent constituent) {
    List<SemanticGraphEdge> outedges = graph.getOutEdgesSorted(((IndexedConstituent) constituent).getRoot());
    for (int i = 0; i < outedges.size(); i++) {
        SemanticGraphEdge e = outedges.get(i);
        if (DpUtils.isAnyConj(e)) {
            IndexedWord child = e.getDependent();
            List<SemanticGraphEdge> outNewRoot = graph.getOutEdgesSorted(child);
            SemanticGraphEdge sub = DpUtils.findFirstOfRelationOrDescendent(outNewRoot, 
                    EnglishGrammaticalRelations.SUBJECT);
            if (sub != null)
                graph.removeEdge(e);
        }
    }
}
 
开发者ID:gkiril,项目名称:minie,代码行数:16,代码来源:DpUtils.java

示例4: createRelConstituent

import edu.stanford.nlp.semgraph.SemanticGraph; //导入方法依赖的package包/类
/** Creates a constituent for the relative clause implied by rel 
 * @param semanticGraph The semantic graph
 * @param root The root of the constituent
 * @param type The type of the constituent
 */
private static IndexedConstituent createRelConstituent(SemanticGraph semanticGraph, IndexedWord root, Type type) {
    List<SemanticGraphEdge> outrcmod = semanticGraph.getOutEdgesSorted(root);
    SemanticGraphEdge rccop = DpUtils.findFirstOfRelation(outrcmod, EnglishGrammaticalRelations.COPULA);
    if (rccop != null) {
        Set<IndexedWord> excludercmod = DpUtils.exclude(semanticGraph, EXCLUDE_RELATIONS_COMPLEMENT, root);
        return new IndexedConstituent(semanticGraph, root, Collections.<IndexedWord> emptySet(), excludercmod, type);
    } else
        return new IndexedConstituent(semanticGraph, root, type);
}
 
开发者ID:gkiril,项目名称:minie,代码行数:15,代码来源:ClauseDetector.java

示例5: addPossessiveClause

import edu.stanford.nlp.semgraph.SemanticGraph; //导入方法依赖的package包/类
/** Generates a clause from a possessive relation
* @param subject The subject of the clause
* @param object  The object of the clause 
*/
private static void addPossessiveClause(ClausIE clausIE, IndexedWord subject, IndexedWord object) {
    Clause clause = new Clause();
    SemanticGraph newSemanticGraph = new SemanticGraph(clausIE.getSemanticGraph());
    clause.setSubject(0);
    clause.verb = 1;
    clause.dobjects.add(2);
    Set<IndexedWord> excludesub = new TreeSet<IndexedWord>();
    Set<IndexedWord> excludeobj = new TreeSet<IndexedWord>();

    excludeobj.add(subject);
    List<SemanticGraphEdge> outedobj = newSemanticGraph.getOutEdgesSorted(object);
    excludeVertexPoss(outedobj, excludeobj, clausIE);

    SemanticGraphEdge rcmod = null;
    if (subject.tag().charAt(0) == 'W') {
        IndexedWord root = newSemanticGraph.getParent(object); 
        if (root != null){
            if (root.tag().equals(POS_TAG.IN)){
                root = newSemanticGraph.getParent(root); // "I saw the man in whose wife I trust"
            }
            List<SemanticGraphEdge> inedges = newSemanticGraph.getIncomingEdgesSorted(root);
            rcmod = DpUtils.findFirstOfRelation(inedges, EnglishGrammaticalRelations.RELATIVE_CLAUSE_MODIFIER);
        }
    } else {
        List<SemanticGraphEdge> outedges = newSemanticGraph.getOutEdgesSorted(subject);
        SemanticGraphEdge ps = DpUtils.findFirstOfRelation(outedges, EnglishGrammaticalRelations.POSSESSIVE_MODIFIER);
        if (ps != null){
            excludesub.add(ps.getDependent());
        }
    }

    if (rcmod != null) {
        clause.constituents.add(createRelConstituent(newSemanticGraph, rcmod.getGovernor(), Type.SUBJECT));
        // To avoid the s in  "Bill's clothes are great".
        ((IndexedConstituent) clause.constituents.get(0)).getExcludedVertexes().addAll(excludesub);
    } else {
        clause.constituents.add(new IndexedConstituent(newSemanticGraph, subject, Collections.<IndexedWord> emptySet(), 
                                                        excludesub, Type.SUBJECT));
    }
    
    // Create a relation phrase with the possessive verb 'has'
    Phrase possPhrase = new Phrase();
    IndexedWord possessiveVerb = new IndexedWord();
    possessiveVerb.setWord("has");
    possessiveVerb.setTag(POS_TAG.VBZ);
    possessiveVerb.setNER(NE_TYPE.NO_NER);
    possessiveVerb.setLemma("have");
    possessiveVerb.setValue("has");
    possessiveVerb.setIndex(-2);
    possPhrase.addWordToList(possessiveVerb);
    possPhrase.setRoot(possessiveVerb);
    
    clause.constituents.add(new PhraseConstituent(possPhrase, Constituent.Type.VERB));
    clause.constituents.add(new IndexedConstituent(newSemanticGraph, object, Collections.<IndexedWord> emptySet(), 
                                                    excludeobj, Constituent.Type.DOBJ));
    clause.setType(Clause.Type.SVO);
    clausIE.getClauses().add(clause);
}
 
开发者ID:gkiril,项目名称:minie,代码行数:63,代码来源:ClauseDetector.java


注:本文中的edu.stanford.nlp.semgraph.SemanticGraph.getOutEdgesSorted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。