2017-08-29 98 views
0

我正在为我的一个项目使用coreNLP的依赖分析。基本和增强的依赖关系对于特定的依赖关系是不同的结果。 我使用下面的代码来获得增强的依赖关系。基本和增强的依赖关系在Standford核心中给出了不同的结果NLP

val lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz") 
lp.setOptionFlags("-maxLength", "80") 
val rawWords = edu.stanford.nlp.ling.Sentence.toCoreLabelList(tokens_arr:_*) 
val parse = lp.apply(rawWords) 
val tlp = new PennTreebankLanguagePack() 
val gsf:GrammaticalStructureFactory = tlp.grammaticalStructureFactory() 
val gs:GrammaticalStructure = gsf.newGrammaticalStructure(parse) 
val tdl = gs.typedDependenciesCCprocessed() 

在下面的例子,

Account name of ramkumar. 

我用简单的API来获得基本的依赖关系。我在 (account,name)之间得到的依赖是(复合)。但是当我使用上面的代码来获得增强的依赖关系时,我得到(帐户,名称)之间的关系为(dobj)。

这是什么修复?这是一个错误还是我做错了什么?

回答

0

当我运行此命令:

java -Xmx8g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,parse -file example.txt -outputFormat json 

随着文件example.txt在您的示例文本,我看到compound作为两种类型的依赖关系这两方面的词与词之间的关系。

我也试过这与simple API并得到了相同的结果。

你可以看到simple此代码产生:

package edu.stanford.nlp.examples; 

import edu.stanford.nlp.semgraph.SemanticGraphFactory; 
import edu.stanford.nlp.simple.*; 

import java.util.*; 

public class SimpleDepParserExample { 

    public static void main(String[] args) { 
    Sentence sent = new Sentence("...example text..."); 
    Properties props = new Properties(); 
    // use sent.dependencyGraph() or sent.dependencyGraph(props, SemanticGraphFactory.Mode.ENHANCED) to see enhanced dependencies 
    System.out.println(sent.dependencyGraph(props, SemanticGraphFactory.Mode.BASIC)); 
    } 

} 

我不知道斯坦福CoreNLP任何斯卡拉接口东西。我还应该注意我的结果是使用GitHub的最新代码,但我认为斯坦福CoreNLP 3.8.0也会产生类似的结果。如果您使用的是Stanford CoreNLP的旧版本,可能是此错误的潜在原因。

但使用Java以各种方式运行此示例我没有看到您遇到的问题。

相关问题