问题描述
我正在按照此链接上的说明使用coreNLP https://github.com/statsmaths/coreNLP
I'm following the instructions on this link to use coreNLPhttps://github.com/statsmaths/coreNLP
但是,我发现了此错误
> library(coreNLP)
Error in get(method, envir = home) :
lazy-load database '/Users/apple/Library/R/3.2/library/coreNLP/R/coreNLP.rdb is corrupt
In addition: Warning messages:
1: In .registerS3method(fin[i, 1], fin[i, 2], fin[i, 3], fin[i, 4], :
restarting interrupted promise evaluation
2: In get(method, envir = home) :
restarting interrupted promise evaluation
3: In get(method, envir = home) : internal error -3 in R_decompress1
Error: package or namespace load failed for ‘coreNLP’
推荐答案
遇到java.lang.UnsupportedClassVersionError: edu/stanford/nlp/pipeline/StanfordCoreNLP : Unsupported major.minor version 52.0
错误消息后:
After encountering the java.lang.UnsupportedClassVersionError: edu/stanford/nlp/pipeline/StanfordCoreNLP : Unsupported major.minor version 52.0
error message:
您需要
- 以超级用户身份安装Java 8,
- 将操作系统使用的默认JVM更改为此JVM(*参见下文),
- 在命令行上运行
R CMD javareconf
,然后 - 将环境变量LD_LIBRARY_PATH设置为libjvm.so的存储目录.
-
重新启动R/RStudio
- install java 8, (as superuser),
- change the default jvm the operating system uses to this jvm (* see below),
- run
R CMD javareconf
on the command line, and then - set the environment variable LD_LIBRARY_PATH to the directory where libjvm.so is stored.
restart R / RStudio
确保计算机上存在交换文件(或交换分区).调用free
来检查输出中是否存在以swap
开头的行,并且该行的值不为零.
make sure that a swap file (or swap partition) exists on your machine. call free
to check if there is a line in the output that starts with swap
and the values on that line are not zero.
我使用ubuntu,我的Java 8 libjvm.so在这里:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so
I use ubuntu, my java 8 libjvm.so is here: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so
您可以在.Rprofile文件中执行此操作.添加此行,也许在文件的底部:
You can do this in your .Rprofile file. Add this line, perhaps at the bottom of the file:
Sys.setenv(LD_LIBRARY_PATH=paste0(Sys.getenv("LD_LIBRARY_PATH"), ":", "/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/" ))
当我在R中执行此操作时:
When I do this in R:
R> Sys.getenv("LD_LIBRARY_PATH")
[1] "/usr/local/lib64/R/lib:/usr/local/lib64:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/"
R> library(coreNLP)
R> initCoreNLP()
我得到这个结果:
Searching for resource: config.properties
Adding annotator tokenize
TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer.
Adding annotator ssplit
Adding annotator pos
Reading POS tagger model from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger ... done [1.1 sec].
Adding annotator lemma
Adding annotator ner
Loading classifier from edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz ... done [5.6 sec].
Loading classifier from edu/stanford/nlp/models/ner/english.muc.7class.distsim.crf.ser.gz ... done [2.1 sec].
Loading classifier from edu/stanford/nlp/models/ner/english.conll.4class.distsim.crf.ser.gz ... done [3.8 sec].
Initializing JollyDayHoliday for SUTime from classpath: edu/stanford/nlp/models/sutime/jollyday/Holidays_sutime.xml as sutime.binder.1.
Reading TokensRegex rules from edu/stanford/nlp/models/sutime/defs.sutime.txt
Reading TokensRegex rules from edu/stanford/nlp/models/sutime/english.sutime.txt
Reading TokensRegex rules from edu/stanford/nlp/models/sutime/english.holidays.sutime.txt
Adding annotator parse
Loading parser from serialized file edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ... done [0.6 sec].
Adding annotator dcoref
Adding annotator sentiment
R> example(getSentiment)
gtSntmR> getSentiment(annoEtranger) # first Sentence of L'Etranger by A.Camus
id sentimentValue sentiment
1 1 1 Negative
2 2 2 Neutral
gtSntmR> getSentiment(annoHp) # first Sentence of Harry Potter V1
id sentimentValue sentiment
1 1 4 Verypositive
(*)如何在Linux上查看默认的jvm:
update-alternatives --display java
结果
java - auto mode
link currently points to /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
要显示所有可用的替代方法,请使用
To show all available alternatives, use
update-alternatives --list java
结果(在我的计算机上):
Result (on my machine):
/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
更改替代方法:
sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
只需使用更新替代方法即可.
Just play a bit with update-alternatives.
这篇关于在R中安装coreNLP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!