xanstorm
xanstorm

Reputation: 33

Error in RWeka in R package

I have searched SO and everywhere else and nothing works to fix the unsupported major.minor version 51 error. I uninstalled Java 8 and installed Java 7. No luck. Thank you for your help. I am using: R 3.3.1 Java 8.91 OSX, el capitan library(NLP) library(tm) library(RWeka) library(rJava) library((RWekajars)) library(parallel) options(mc.cores=1) Here is the R code causing the error:

trigram <- function(x){NGramTokenizer(x,control=Weka_control(min=3,max=3))}
tdm <- TermDocumentMatrix(corpus2,control=list(tokenize=trigram))

Here is the error I get.
 Error in .jnew(name) : 
  java.lang.UnsupportedClassVersionError: weka/core/tokenizers/NGramTokenizer : Unsupported major.minor version 51.0 
9 stop(structure(list(message = "java.lang.UnsupportedClassVersionError: weka/core/tokenizers/NGramTokenizer : Unsupported major.minor version 51.0", 
    call = .jnew(name), jobj = <S4 object of class structure("jobjRef", package = "rJava")>), .Names = c("message", 
"call", "jobj"), class = c("UnsupportedClassVersionError", "ClassFormatError", 
"LinkageError", "Error", "Throwable", "Object", "Exception",  ... 
8 .jnew(name) 
7 NGramTokenizer(x, control = Weka_control(min = 3, max = 3)) 
6 .tokenize(doc) 
5 FUN(X[[i]], ...) 
4 lapply(X = X, FUN = FUN, ...) 
3 mclapply(unname(content(x)), termFreq, control) 
2 TermDocumentMatrix.VCorpus(corpus2, control = list(tokenize = trigram)) 
1 TermDocumentMatrix(corpus2, control = list(tokenize = trigram)) 

Upvotes: 1

Views: 3320

Answers (2)

JRHami
JRHami

Reputation: 21

I was also using NGramTokenizer(x, control = Weka_control(min = 3, max = 3))

and it was creating errors for me. I came across this tokenizer and it fixed the issue for me.

TrigramTokenizer <-
  function(x)
    unlist(lapply(ngrams(words(x), 3), paste, collapse = " "), use.names = FALSE)

please see: https://rpubs.com/hokumski/capstone-milestone-week2 for more information

Upvotes: 2

pheeper
pheeper

Reputation: 1527

I've been trying to solve this same issue all week. I've been using Java 1.8 which I read is fine. However the problem seems to be in the rJava package that's installing inside of R. Once I installed from rforge.net using the following line everything worked.

install.packages("rJava","http://rforge.net/",type="source")

Upvotes: 0

Related Questions