R中的CoreNLP在RStudio中不起作用,但在shell

时间:2016-06-22 22:36:13

标签: r rjava rstudio-server stanford-nlp

我在Ubuntu上使用R,我想使用CoreNLP包,我有一个奇怪的行为。当我使用shell时,一切都很好,例如我可以运行:

$ R

R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> library(rjava)
Error in library(rjava) : there is no package called ‘rjava’
> library(rJava)
> library(coreNLP)
> 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 [2.4 sec].
Adding annotator lemma
Adding annotator ner
Loading classifier from edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz ... done [6.1 sec].
Loading classifier from edu/stanford/nlp/models/ner/english.muc.7class.distsim.crf.ser.gz ... done [4.1 sec].
Loading classifier from edu/stanford/nlp/models/ner/english.conll.4class.distsim.crf.ser.gz ... done [3.3 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 [4.1 sec].
Adding annotator dcoref
Adding annotator sentiment
> library(rJava)
> .jinit()
[1] 0
> .jcall("java/lang/System","S","getProperty","java.version")
[1] "1.8.0_91"
> 

但如果我在同一台计算机上使用RStudio Server,使用相同的用户,我会得到:

> library(rJava)
> library(coreNLP)
> initCoreNLP()
Error in rJava::.jnew("edu.stanford.nlp.pipeline.StanfordCoreNLP", basename(path)) : 
  java.lang.UnsupportedClassVersionError: edu/stanford/nlp/pipeline/StanfordCoreNLP : Unsupported major.minor version 52.0
> .jinit()
[1] 0
> .jcall("java/lang/System","S","getProperty","java.version")
[1] "1.7.0_67"

首先,这在终端或RStudio Server中都无效。为了使它在终端中工作,我按照以下步骤操作:

  1. 我从http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html下载了Java,即jdk-8u91-linux-x64.tar.gz文件。
  2. 在/usr/lib/jvm/jdk1.8.0_91中解压缩
  3. 最后运行sudo JAVA_HOME=/usr/lib/jvm/jdk1.8.0_91 R CMD javareconf
  4. 所以,我无法理解为什么它在终端中工作但在RStudio Server中不起作用。似乎RStudio Server无法加载正确的Java,有谁知道为什么?

    非常感谢您的宝贵意见。

    一切顺利

    奥古斯丁

1 个答案:

答案 0 :(得分:1)

您可能想要询问RStudio支持。 R脚本正在为Java设置环境,所以我的猜测是RStudio服务器无法做到这一点。我不知道你是如何开始的,但你可以通过引导R脚本获得更多运气,例如

R CMD <command to start the server>