本文整理汇总了Java中edu.stanford.nlp.semgraph.SemanticGraph.typedDependencies方法的典型用法代码示例。如果您正苦于以下问题:Java SemanticGraph.typedDependencies方法的具体用法?Java SemanticGraph.typedDependencies怎么用?Java SemanticGraph.typedDependencies使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.semgraph.SemanticGraph
的用法示例。
在下文中一共展示了SemanticGraph.typedDependencies方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSubgraphFromWords
import edu.stanford.nlp.semgraph.SemanticGraph; //导入方法依赖的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;
}
示例2: findTypeDependency
import edu.stanford.nlp.semgraph.SemanticGraph; //导入方法依赖的package包/类
/**
* Finds type dependencies in semantics graph.
*/
private TypedDependency findTypeDependency(SemanticGraph semanticGraph, CoreLabel coreLabel) {
Collection<TypedDependency> deps = semanticGraph.typedDependencies();
for (TypedDependency dependency : deps) {
if (dependency.dep().backingLabel() == coreLabel) {
return dependency;
}
}
//throw new RuntimeException("TypeDependency not found");
return null;
}
示例3: setTdsFromSentenceSemGraph
import edu.stanford.nlp.semgraph.SemanticGraph; //导入方法依赖的package包/类
/**
* Given a sentence semantic graph, set the typed dependencies list of the phrase. For this to work, the list of
* words (this.wordlist) must be already known. Otherwise, the tds list will be empty. Each typed dependency in the list
* must contain both the parent and the child in the wordslist.
* @param sg: sentence semantic graph (the phrase must be derived from this graph, i.e. all the nodes and edges of the
* phrase must be found in this graph. Otherwise, the TDs list will be empty)
*/
public void setTdsFromSentenceSemGraph(SemanticGraph sg){
// If the semantic graph of the sentence or the list of words are empty, return
if (sg.isEmpty() || this.wordList.isEmpty()){
tds = new ObjectArrayList<TypedDependency>();
return;
}
for (TypedDependency td: sg.typedDependencies()){
if (this.wordList.contains(td.dep()) && this.wordList.contains(td.gov()))
this.tds.add(td);
}
}