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

ste*_*sia 5 stanford-nlp stanford-nlp-server

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

为此,我已经下载了v3.6.0 jar和相应的法语模型.

然后我运行服务器:

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer
Run Code Online (Sandbox Code Playgroud)

如本回答所述,我将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 -
Run Code Online (Sandbox Code Playgroud)

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

 [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)
    ...
Run Code Online (Sandbox Code Playgroud)

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

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

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

ste*_*sia 9

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

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

  2. cd到该目录,然后运行服务器:

    java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer
    
    Run Code Online (Sandbox Code Playgroud)

(遗憾的是,-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 -
    
    Run Code Online (Sandbox Code Playgroud)

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

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