stanfordnlp / CoreNLP

CoreNLP: A Java suite of core NLP tools for tokenization, sentence segmentation, NER, parsing, coreference, sentiment analysis, etc.
http://stanfordnlp.github.io/CoreNLP/
GNU General Public License v3.0
9.71k stars 2.7k forks source link

An exception occurred: Expecting value: line 1 column 1 (char 0) #1402

Closed heguyu closed 11 months ago

heguyu commented 11 months ago

使用默认的en语言包执行nlp.coref是可以运行的

代码 `from stanfordcorenlp import StanfordCoreNLP

nlp = StanfordCoreNLP("D:\stanford-corenlp-4.5.5",quiet=False) sentence = "Xiaoming is at the intersection. Who is he waiting for?" try: print('Tokenize:', nlp.coref(sentence)) except Exception as e: print('An exception occurred:', e) nlp.close()`

结果 Tokenize: [[(1, 1, 2, 'Xiaoming'), (2, 3, 4, 'he')]]

但使用其他语言包会出现异常,比如

`from stanfordcorenlp import StanfordCoreNLP

nlp = StanfordCoreNLP("D:\stanford-corenlp-4.5.5", lang="zh",quiet=False) sentence = "小明在路口,他但等谁?" try: print('Tokenize:', nlp.coref(sentence)) except Exception as e: print('An exception occurred:', e) nlp.close() `

结果

java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122) java.base/java.util.concurrent.FutureTask.get(FutureTask.java:205) edu.stanford.nlp.pipeline.StanfordCoreNLPServer$CoreNLPHandler.handle(StanfordCoreNLPServer.java:1008) jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:98) jdk.httpserver/sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:82) jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:101) jdk.httpserver/sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:871) jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:98) jdk.httpserver/sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:847) java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) java.base/java.lang.Thread.run(Thread.java:1583) Caused by: class java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because "tokens" is null edu.stanford.nlp.pipeline.CorefAnnotator.setNamedEntityTagGranularity(CorefAnnotator.java:93) edu.stanford.nlp.pipeline.CorefAnnotator.annotate(CorefAnnotator.java:149) edu.stanford.nlp.pipeline.AnnotationPipeline.annotate(AnnotationPipeline.java:76) edu.stanford.nlp.pipeline.StanfordCoreNLP.annotate(StanfordCoreNLP.java:744) edu.stanford.nlp.pipeline.StanfordCoreNLPServer$CoreNLPHandler.lambda$handle$0(StanfordCoreNLPServer.java:1003) java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) java.base/java.lang.Thread.run(Thread.java:1583) An exception occurred: Expecting value: line 1 column 1 (char 0)

zh的与语言包也按照文档指示放在了目标文件夹下 image

如果你有任何的解决方法,请告知我,谢谢

AngledLuffa commented 11 months ago

You should post that here:

https://github.com/Lynten/stanford-corenlp

That particular wrapper is not our tool. AFAIK it has not been updated for anything 4.0 or later.

I could instead point you to Stanza, which also has a CoreNLP wrapper and is frequently updated