在 R 中安装 coreNLP [英] Installing coreNLP in R

查看:15
本文介绍了在 R 中安装 coreNLP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照此链接上的说明使用 coreNLPhttps://github.com/statsmaths/coreNLP

I'm following the instructions on this link to use coreNLP https://github.com/statsmaths/coreNLP

但是,我发现了这个错误

However, I found this error

> 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

只需使用更新替代品.

这篇关于在 R 中安装 coreNLP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆