Error in simple_triplet_matrix -- unable to use RWeka to count Phrases

StackOverflow https://stackoverflow.com/questions/20577040

  •  01-09-2022
  •  | 
  •  

문제

Using TM, I'm comparing a DocumentTermMatrix against a dictionary list to count totals:

totals <- inspect(DocumentTermMatrix(x, list(dictionary = d)))

This works great for single words, but I want to include double words and can't figure out how to do this.

I tried RWeka:

TrigramTokenizer <- function(x) NGramTokenizer(x, 
                                               Weka_control(min = 3, max = 3))
tdm <- TermDocumentMatrix(v.corpus, 
                          control = list(tokenize = TrigramTokenizer))

BUt get the following error message:

Error in simple_triplet_matrix(i = i, j = j, v = as.numeric(v), nrow = length(allTerms),  : 
  'i, j, v' different lengths
In addition: Warning messages:
1: In parallel::mclapply(x, termFreq, control) :
  all scheduled cores encountered errors in user code
2: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
3: In simple_triplet_matrix(i = i, j = j, v = as.numeric(v), nrow = length(allTerms),  :
  NAs introduced by coercion.

Can you help with the Error message?

Thanks!!

도움이 되었습니까?

해결책

See my answer here

Seems there are problems using RWeka with parallel package. I found workaround solution here.

1: http://r.789695.n4.nabble.com/RWeka-and-multicore-package-td4678473.html#a4678948

The most important point is not loading the RWeka package and use the namespace in a encapsulated function.

So your tokenizer should look like

BigramTokenizer <- function(x) {RWeka::NGramTokenizer(x, RWeka::Weka_control(min = 2, max = 2))}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top