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


Java IndexedWord.index方法代码示例

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


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

示例1: getSubgraphFromWords

import edu.stanford.nlp.ling.IndexedWord; //导入方法依赖的package包/类
/**
 * Given the sentence semantic graph and a list of words, get a subgraph containing just the words in the list
 * 'words'. Each typed dependency has each word from the list as a governor.
 * @param sg: sentence semantic graph
 * @param words: list of words which should contain the semantic graph
 * @return subgraph containing the words from 'words'
 * TODO: this needs to be double checked! In some cases we have weird graphs, where there are words missing. 
 * E.g. the sentence 120 from NYT "The International ... ". Try this for getting the subgraph when the source is 
 * detected.
 */
public static SemanticGraph getSubgraphFromWords(SemanticGraph sg, ObjectArrayList<IndexedWord> words){        
    // Determining the root
    int minInd = Integer.MAX_VALUE;
    IndexedWord root = new IndexedWord();
    for (IndexedWord w: words){
        if (w.index() < minInd){
            minInd = w.index();
            root = w;
        }
    }
    
    // Getting the typed dependency
    ObjectArrayList<TypedDependency> tds = new ObjectArrayList<TypedDependency>();
    for (TypedDependency td: sg.typedDependencies()){
        if (words.contains(td.gov()) && words.contains(td.dep()))
            tds.add(td);
    }
    
    // Create the semantic graph
    TreeGraphNode rootTGN = new TreeGraphNode(new CoreLabel(root));
    EnglishGrammaticalStructure gs = new EnglishGrammaticalStructure(tds, rootTGN);
    SemanticGraph phraseSg = SemanticGraphFactory.generateUncollapsedDependencies(gs);
    
    return phraseSg;
}
 
开发者ID:gkiril,项目名称:minie,代码行数:36,代码来源:CoreNLPUtils.java


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