Generating stanford semantic graph with nodes storing lemma

雨燕双飞 提交于 2019-12-13 04:32:33

问题


I am trying to generate a SemanticGraph and use semgrex to find the specific node. I would like to use lemma as one of node attribute in semgrex. I saw a relevant question and answer here:

CoreNLP SemanticGraph - search for edges with specific lemmas

It is mentioned that

Make sure that the nodes are storing lemmas -- see the lemma annotator of CoreNLP (currently available for English, only).

I current can use pipeline to generate the desired annotation to generate the semantic graph.

 Properties props = new Properties();
 props.put("annotators", "tokenize, ssplit, pos, lemma, parse");
 StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

However, after searching for relevant information, I only find a deprecated function at here:

https://github.com/chbrown/nlp/blob/master/src/main/java/edu/stanford/nlp/pipeline/ParserAnnotatorUtils.java

public static SemanticGraph generateDependencies(Tree tree,
    boolean collapse,
    boolean ccProcess,
    boolean includeExtras,
    boolean lemmatize,
    boolean threadSafe) {
  SemanticGraph deps = SemanticGraphFactory.makeFromTree(tree, collapse, ccProcess, includeExtras, lemmatize, threadSafe);
  return deps;
}

which seemed to be removed from newest coreNLP.

Could anyone give some hint on how to generate the semantic graph with nodes that storing the lemmas?


回答1:


The function as you have it should work. The lemmas will be stored in the SemanticGraph produced by the parse annotator. You can retrieve the graph after running your text through pipeline.annotate(Annotation) with:

sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class)

Or, the equivalent for Collapsed and CollapsedCCProcessed dependencies. See http://www-nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/semgraph/SemanticGraphCoreAnnotations.html. Note that these are attached to a sentence (CoreMap), not a document (Annotation).

You can then run Semgrex over the graph as usual; e.g., {lemma:/foo/} >arctype {lemma:/bar/}.



来源:https://stackoverflow.com/questions/31177593/generating-stanford-semantic-graph-with-nodes-storing-lemma

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!