本文整理汇总了Java中edu.stanford.nlp.semgraph.SemanticGraphEdge类的典型用法代码示例。如果您正苦于以下问题:Java SemanticGraphEdge类的具体用法?Java SemanticGraphEdge怎么用?Java SemanticGraphEdge使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SemanticGraphEdge类属于edu.stanford.nlp.semgraph包,在下文中一共展示了SemanticGraphEdge类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: isDescendant
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/** Checks if a node depending on one conjoint also depends to the other */
//"He buys and sells electronic products" "Is products depending on both sells and buys?"
private static boolean isDescendant(IndexedWord checkWord, IndexedWord pivotWord, IndexedWord elementWord,
SemanticGraph semGraph) {
Collection <IndexedWord> roots = semGraph.getRoots();
while (!roots.contains(elementWord)){
if (!semGraph.getShortestUndirectedPathNodes(elementWord, pivotWord).isEmpty())
break;
elementWord = semGraph.getParent(elementWord);
}
List<SemanticGraphEdge> path = semGraph.getShortestDirectedPathEdges(elementWord, checkWord);
if (path == null)
return false;
else
return true;
}
开发者ID:gkiril,项目名称:minie,代码行数:18,代码来源:ProcessConjunctions.java
示例2: getSubgraph
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
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);
}
开发者ID:gkiril,项目名称:minie,代码行数:19,代码来源:CoreNLPUtils.java
示例3: setQuantitiesFromWordList
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/**
* A helper function used in detectQuantities. When we have a list of quantity words, quantity edges and the
* sentence semantic graph, add quantities to the list of quantities and clear the reusable lists.
* If there are quantities in the phrase, replace them with the word SOME_n_i, where i = the place of the quantity
* (0 - subject, 1 - relation, 2 - object) and j = # of quantity within the phrase.
*
* @param qWords: list of quantity indexed words
* @param qEdges: list of semantic graph edges (reusable)
* @param sentSemGraph: sentence semantic graph
* @param i: used for ID-ying purposes of the quantities' annotations
* @param j: used for ID-ying purposes of the quantities' annotations
*/
private void setQuantitiesFromWordList(ObjectArrayList<IndexedWord> qWords, ObjectArrayList<SemanticGraphEdge> qEdges,
SemanticGraph sentSemGraph, int i, int j){
// Quantity ID
StringBuffer sbId = new StringBuffer();
if (i == 0)
sbId.append(Quantity.SUBJECT_ID);
else if (i == 1)
sbId.append(Quantity.RELATION_ID);
else
sbId.append(Quantity.OBJECT_ID);
sbId.append(CHARACTER.UNDERSCORE);
sbId.append(j + 1); // Indexing starts from 1
for (IndexedWord w: qWords){
qEdges.add(sentSemGraph.getEdge(sentSemGraph.getParent(w), w));
}
// Add the quantity to the list
this.quantities.add(new Quantity(qWords, qEdges, sbId.toString()));
// Clear the lists
qWords.clear();
qEdges.clear();
}
开发者ID:gkiril,项目名称:minie,代码行数:37,代码来源:AnnotatedPhrase.java
示例4: addDroppedEdges
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
public void addDroppedEdges(ObjectArrayList<SemanticGraphEdge> edges) {
// check for duplicates
for (SemanticGraphEdge edge: edges) {
if (edge==null) continue;
boolean edgeAlreadyListed = false;
for (SemanticGraphEdge listedEdge: this.droppedEdges) {
if (edge.getTarget().index() == listedEdge.getTarget().index()) {
edgeAlreadyListed = true;
break;
}
}
if (!edgeAlreadyListed) {
this.droppedEdges.add(edge);
}
}
}
开发者ID:gkiril,项目名称:minie,代码行数:17,代码来源:AnnotatedPhrase.java
示例5: toString
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/** Given a polarity object, convert it into a string */
@Override
public String toString(){
StringBuffer sb = new StringBuffer();
sb.append(CHARACTER.LPARENTHESIS);
if (this.polarityType == Polarity.Type.POSITIVE)
sb.append(CHARACTER.PLUS);
else {
sb.append(CHARACTER.MINUS);
sb.append(CHARACTER.COMMA);
sb.append(SEPARATOR.SPACE);
for (SemanticGraphEdge edge: this.negativeEdges){
sb.append(edge.toString());
sb.append(CHARACTER.COMMA);
sb.append(SEPARATOR.SPACE);
}
}
sb.append(CHARACTER.RPARENTHESIS);
return sb.toString().trim();
}
开发者ID:gkiril,项目名称:minie,代码行数:22,代码来源:Polarity.java
示例6: findFirstOfRelation
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/** Finds the first occurrence of a grammatical relation in a set of edges */
public static SemanticGraphEdge findFirstOfRelation(List<SemanticGraphEdge> edges, GrammaticalRelation rel) {
for (SemanticGraphEdge e : edges) {
if (rel.equals(e.getRelation())) {
return e;
}
}
return null;
}
开发者ID:gkiril,项目名称:minie,代码行数:10,代码来源:DpUtils.java
示例7: findFirstOfRelationOrDescendent
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/** Finds the first occurrence of a grammatical relation or its descendants in a set of edges */
public static SemanticGraphEdge findFirstOfRelationOrDescendent(List<SemanticGraphEdge> edges, GrammaticalRelation rel) {
for (SemanticGraphEdge e : edges) {
if (rel.isAncestor(e.getRelation())) {
return e;
}
}
return null;
}
开发者ID:gkiril,项目名称:minie,代码行数:10,代码来源:DpUtils.java
示例8: createRelConstituent
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的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
示例9: getEdges
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/** Finds all occurrences of a grammatical relation or its descendants in a set of edges */
public static List<SemanticGraphEdge> getEdges(List<SemanticGraphEdge> edges, GrammaticalRelation rel) {
List<SemanticGraphEdge> result = new ArrayList<SemanticGraphEdge>();
for (SemanticGraphEdge e : edges) {
if (rel.isAncestor(e.getRelation())) {
result.add(e);
}
}
return result;
}
开发者ID:gkiril,项目名称:minie,代码行数:11,代码来源:DpUtils.java
示例10: isPrepositionalPhrase
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/** Checks whether this constituent is a prepositional phrase (i.e., starts with a preposition). */
public boolean isPrepositionalPhrase(SemanticGraph sentSemanticGraph) { //This is a mess, find other way of fixing. This is purelly heuristic.
//It needs to know the semantic graph for the sentence after this is fixed the member variable sentSemanticGraph
//can be removed
List<IndexedWord> parents = semanticGraph.getParentList(root); //This is not the cleanest way semantics messed up.
//specially with the rel we cannot just check if
//the head is a preposition
//(return root.tag().equals("IN")) because the
//parser some times includes a preposition in the
//verbal phrase "He is about to win"
for(IndexedWord parent: parents) {
SemanticGraphEdge edge = semanticGraph.getEdge(parent, root);
if(DpUtils.isRel(edge))
return true;
if(DpUtils.isAnyPrep(edge)) {
List<IndexedWord> ancestors = sentSemanticGraph.getParentList(parent);
for(IndexedWord ancestor: ancestors) {
SemanticGraphEdge ed = sentSemanticGraph.getEdge(ancestor, parent);
if(DpUtils.isRcmod(ed))
return true;
}
}
}
return false;
//return root.tag().equals("IN");
}
开发者ID:gkiril,项目名称:minie,代码行数:29,代码来源:IndexedConstituent.java
示例11: nextToVerb
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/** Checks if two nodes are conjoined by a given conjunction */
private static boolean nextToVerb(IndexedWord firstVerb, IndexedWord secondVerb, IndexedWord conj,
SemanticGraph semGraph, List<SemanticGraphEdge> sortedOutEdges){
// The index of the 'conj' relation in 'sortedOutEdges'. Initially, set to -1.
int conjIndex = -1;
// Go to the "conj" relation linking the first and the second conjoin.
// Store the relation index in 'conjIndex'
for (int i=0; i<=sortedOutEdges.size(); i++){
SemanticGraphEdge edge = sortedOutEdges.get(i);
if (edge.getSource().equals(firstVerb) && edge.getTarget().equals(secondVerb) &&
edge.getRelation().getShortName().equals("conj")){
conjIndex = i;
break;
}
}
// Move to the first relation to the left. If it is is a "cc" relation, this is the relation corresponding to
// the coordinating conjunction (return true), else -> return false
if (conjIndex > 0){
SemanticGraphEdge leftConjEdge = sortedOutEdges.get(conjIndex-1);
if (leftConjEdge.getRelation().getShortName().equals("cc")){
return true;
} else {
return false;
}
} else {
return false;
}
}
开发者ID:gkiril,项目名称:minie,代码行数:32,代码来源:ProcessConjunctions.java
示例12: ancestorOf
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/** TODO */
private static int ancestorOf(SemanticGraph semanticGraph, IndexedWord node, List<IndexedWord> ancestors) {
for (SemanticGraphEdge e : semanticGraph.getIncomingEdgesSorted(node)) {
int index = ancestors.indexOf(node);
if (index >= 0)
return index;
index = ancestorOf(semanticGraph, e.getGovernor(), ancestors);
if (index >= 0)
return index;
}
return -1;
}
开发者ID:gkiril,项目名称:minie,代码行数:13,代码来源:ClauseDetector.java
示例13: removeEdges
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/** Removes some edges from the given semantic graph.
*
* This method traverses the semantic graph starting from the given root. An edge is removed if
* (1) its child appears in <code>excludeVertexes</code>, (2) its relation appears in
* <code>excludeRelations</code>, or (3) the edge has the root as parent and its relation
* appears in <code>excludeRelationsTop</code>. */
public static void removeEdges(SemanticGraph graph, IndexedWord root, Collection<IndexedWord> excludeVertexes,
Collection<GrammaticalRelation> excludeRelations, Collection<GrammaticalRelation> excludeRelationsTop) {
if (!excludeVertexes.contains(root)) {
Set<SemanticGraphEdge> edgesToRemove = new HashSet<SemanticGraphEdge>();
subgraph(graph, root, excludeVertexes, excludeRelations, excludeRelationsTop, edgesToRemove, 0);
for (SemanticGraphEdge edge : edgesToRemove) {
graph.removeEdge(edge);
}
}
}
开发者ID:gkiril,项目名称:minie,代码行数:17,代码来源:DpUtils.java
示例14: subgraph
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的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
示例15: disconectClauses
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的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
示例16: containsAncestor
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/** Check if an edge is descendant of any grammatical relation in the given set */
private static boolean containsAncestor(Collection<GrammaticalRelation> rels, SemanticGraphEdge edge) {
for (GrammaticalRelation rel : rels) {
if (rel.isAncestor(edge.getRelation()))
return true;
}
return false;
}
开发者ID:gkiril,项目名称:minie,代码行数:9,代码来源:DpUtils.java
示例17: removePunctEdges
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/**
* Remove the 'punct' edges
* @param g -> Semantic graph gotten from the dependency parse
*/
public static void removePunctEdges(SemanticGraph semanticGraph){
for (SemanticGraphEdge edge : new ArrayList<>(semanticGraph.edgeListSorted())){
if (EnglishGrammaticalRelations.PUNCTUATION.equals(edge.getRelation())){
semanticGraph.removeEdge(edge);
}
}
}
开发者ID:gkiril,项目名称:minie,代码行数:12,代码来源:DpUtils.java
示例18: listOfIndexedWordsToParentEdges
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/**
*
*/
public static ObjectArrayList<SemanticGraphEdge> listOfIndexedWordsToParentEdges(SemanticGraph semanticGraph, ObjectOpenHashSet<IndexedWord> wordList) {
ObjectArrayList<SemanticGraphEdge> result = new ObjectArrayList<>();
for (IndexedWord word: wordList) {
SemanticGraphEdge edge = semanticGraph.getEdge(semanticGraph.getParent(word), word);
result.add(edge);
}
return result;
}
开发者ID:gkiril,项目名称:minie,代码行数:12,代码来源:CoreNLPUtils.java
示例19: getSortedWordsFromListOfEdges
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
/**
* Given a list of edges, get all the indexed words from them (their nodes) and return them sorted by index
* @param edges: list of edges
* @return list of indexed words sorted by index
*/
public static ObjectArrayList<IndexedWord> getSortedWordsFromListOfEdges(Set<SemanticGraphEdge> edges){
ObjectOpenHashSet<IndexedWord> wordsSet = new ObjectOpenHashSet<>();
for (SemanticGraphEdge e: edges){
wordsSet.add(e.getGovernor());
wordsSet.add(e.getDependent());
}
return getSortedWordsFromSetOfWords(wordsSet);
}
开发者ID:gkiril,项目名称:minie,代码行数:15,代码来源:CoreNLPUtils.java
示例20: semanticGraphUniversalEnglishToEnglish
import edu.stanford.nlp.semgraph.SemanticGraphEdge; //导入依赖的package包/类
public static SemanticGraph semanticGraphUniversalEnglishToEnglish(SemanticGraph semanticGraph) {
for (SemanticGraphEdge edge: semanticGraph.edgeListSorted()) {
GrammaticalRelation oldRel = edge.getRelation();
edge.setRelation(EnglishGrammaticalRelations.shortNameToGRel.get(oldRel.getShortName()));
}
return semanticGraph;
}
开发者ID:gkiril,项目名称:minie,代码行数:9,代码来源:CoreNLPUtils.java
注:本文中的edu.stanford.nlp.semgraph.SemanticGraphEdge类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论