运行斯坦福corenlp服务器与法国模型

时间:2016-06-15 14:31:19

标签: stanford-nlp stanford-nlp-server

我试图用Stanford CoreNLP工具分析一些法语文本(这是我第一次尝试使用任何StanfordNLP软件)

为此,我已经下载了v3.6.0 jar和相应的french models

然后我用:

运行服务器
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer

如本answer所述,我将API调用为:

wget --post-data 'Bonjour le monde.' 'localhost:9000/?properties={"parse.model":"edu/stanford/nlp/models/parser/nndep/UD_French.gz", "annotators": "parse", "outputFormat": "json"}' -O -

但我得到以下日志+错误:

 [pool-1-thread-1] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP  
 Adding annotator tokenize
 [pool-1-thread-1] INFO edu.stanford.nlp.pipeline.TokenizerAnnotator - TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer.
 [pool-1-thread-1] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP -   Adding annotator ssplit
 [pool-1-thread-1] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator parse
 [pool-1-thread-1] INFO edu.stanford.nlp.parser.common.ParserGrammar - Loading parser from serialized file edu/stanford/nlp/models/parser/nndep/UD_French.gz ... 

 edu.stanford.nlp.io.RuntimeIOException: java.io.StreamCorruptedException: invalid stream header: 64696374
    at edu.stanford.nlp.parser.common.ParserGrammar.loadModel(ParserGrammar.java:188)
    at edu.stanford.nlp.pipeline.ParserAnnotator.loadModel(ParserAnnotator.java:212)
    at edu.stanford.nlp.pipeline.ParserAnnotator.<init>(ParserAnnotator.java:115)
    ...

建议的解决方案here建议代码和模型版本不同,但我已将它们从同一页面下载(并且它们的名称中都有相同的版本号),所以我很确定它们是相同的。

还有其他暗示我做错了什么?

(我还应该提到我不是Java专家,所以也许我忘记了一个愚蠢的步骤......)

2 个答案:

答案 0 :(得分:8)

好的,经过大量阅读和尝试失败后,我找到了一种方法( v3.6.0 )。以下是详细信息,如果它们可能对其他人有任何兴趣:

  1. http://stanfordnlp.github.io/CoreNLP/index.html#download下载代码和法语模型。解压缩代码.zip并将法语模型.jar复制到该目录(不要移除英语模型,无论如何它们都有不同的名称)

  2. cd到该目录,然后使用以下命令运行服务器:

    java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer
    
  3. (遗憾的是-prop标志在这里没有帮助)

    1. 调用API重复StanfordCoreNLP-french.properties

      中列出的属性
      wget --header="Content-Type: text/plain; charset=UTF-8"
           --post-data 'Bonjour le monde.' 
           'localhost:9000/?properties={
             "annotators": "tokenize,ssplit,pos,parse", 
             "parse.model":"edu/stanford/nlp/models/lexparser/frenchFactored.ser.gz", 
             "pos.model":"edu/stanford/nlp/models/pos-tagger/french/french.tagger", 
             "tokenize.language":"fr", 
             "outputFormat": "json"}' 
        -O -
      

      最终使用法国模特给出了200响应!

    2. (注意:不知道如何使用它(与utf-8支持相同))

答案 1 :(得分:0)

对于某些人来说,这可能是有用的补充,这是德语的完整属性文件的样子:

# annotators
annotators = tokenize, ssplit, mwt, pos, ner, depparse

# tokenize
tokenize.language = de
tokenize.postProcessor = edu.stanford.nlp.international.german.process.GermanTokenizerPostProcessor

# mwt
mwt.mappingFile = edu/stanford/nlp/models/mwt/german/german-mwt.tsv

# pos
pos.model = edu/stanford/nlp/models/pos-tagger/german-ud.tagger

# ner
ner.model = edu/stanford/nlp/models/ner/german.distsim.crf.ser.gz
ner.applyNumericClassifiers = false
ner.applyFineGrained = false
ner.useSUTime = false

# parse
parse.model = edu/stanford/nlp/models/srparser/germanSR.beam.ser.gz

# depparse
depparse.model = edu/stanford/nlp/models/parser/nndep/UD_German.gz

ArabicChineseFrenchGermanSpanish的完整属性文件都可以在CoreNLP github repository中找到。 / p>

相关问题