Я работаю над набором данных, которые мне нужно токенизировать для обучения. Прежде чем выполнять токенизацию, я создал словарь, поэтому мне нужно извлечь те слова, которые присутствуют в словаре как таковые.
Мой текстовый файл приведен ниже:
t <- "In order to perform operations inside the abdomen, surgeons must make an incision large enough to offer adequate visibility, provide access to the abdominal organs and allow the use of hand-held surgical instruments. These incisions may be placed in different parts of the abdominal wall. Depending on the size of the patient and the type of operation, the incision may be 6 to 12 inches in length. There is a significant amount of discomfort associated with these incisions that can prolong the time spent in the hospital after surgery and can limit how quickly a patient can resume normal daily activities. Because traditional techniques have long been used and taught to generations of surgeons, they are widely available and are considered the standard treatment to which newer techniques must be compared."
В мой словарь входят слова:
dict <- c("hand-held surgical instruments", "intensive care unit", "traditional techniques")
Теперь я применил токенизацию биграмм для слов в документе. Для этого я использовал следующий код:
#Preprocessing of data
corpus <- Corpus(VectorSource(t))
corpus <- tm_map(corpus,content_transformer(tolower))
corpus <- tm_map(corpus,removePunctuation)
corpus <- tm_map(corpus,PlainTextDocument)
#Bigram Tokenization
BigramTokenizer <- function(x) NGramTokenizer(x, Weka_control(min = 2, max = 2))
dtm <- TermDocumentMatrix(corpus,control=list(tokenize=BigramTokenizer, dictionary=dict))
Но я получаю вывод следующим образом:
<<TermDocumentMatrix (terms: 3, documents: 1)>>
Non-/sparse entries: 1/2
Sparsity : 67%
Maximal term length: 30
Weighting : term frequency (tf)
Docs
Terms character(0)
hand-held surgical instruments 0
intensive care unit 0
traditional techniques 1
Но мне нужно токенизировать слова, которых нет в словаре, с помощью биграмм. Кто-нибудь может мне помочь?