1
特定のWebページに基づいて少なくとも2回出現する単語のリストを作成したいと思います。 データを取得し、各単語ごとにカウントを持つリストを取得することに成功しましたが、 この方法をとどめるために大文字の単語を保持する必要があります。今度は、小文字だけの単語リストが生成されます。 たとえば、「マイアミ」という言葉は「マイアミ」に変わり、「マイアミ」として必要になります。テキストマイニング中に単語の元の構造を保持する方法
どのようにして元の構造で単語を取得できますか?
コードが取り付けられている。
library(XML)
web_page <- htmlTreeParse("http://www.larryslist.com/artmarket/the-talks/dennis-scholls-multiple-roles-from-collecting-art-to-winning-emmy-awards/"
,useInternal = TRUE)
doctext = unlist(xpathApply(web_page, '//p', xmlValue))
doctext = gsub('\\n', ' ', doctext)
doctext = paste(doctext, collapse = ' ')
library(tm)
SampCrps<- Corpus(VectorSource(doctext))
corp <- tm_map(SampCrps, PlainTextDocument)
oz <- tm_map(corp, removePunctuation, preserve_intra_word_dashes = FALSE) # remove punctuation
oz <- tm_map(corp, removeWords, stopwords("english")) # remove stopwords
dtm <-DocumentTermMatrix(oz)
findFreqTerms(dtm,2) # words that apear at least 2 times
dtmMatrix <- as.matrix(dtm)
wordsFreq <- colSums(dtmMatrix)
wordsFreq <- sort(wordsFreq, decreasing=TRUE)
head(wordsFreq)
wordsFreq <- as.data.frame(wordsFreq)
wordsFreq <- data.frame(word = rownames(wordsFreq), count = wordsFreq, row.names = NULL)
head(wordsFreq,50)
私は3つのワードnグラムを取得するには、コードのこの行を使用する場合、同じ問題が発生します。
library(RWeka)
BigramTokenizer <- function(x) NGramTokenizer(x, Weka_control(min = 3, max = 3))
tdm <- TermDocumentMatrix(oz, control = list(tokenize = BigramTokenizer))
inspect(tdm)
@Ken Benoitありがとうございました。パッケージのquantedaは素晴らしいようです。 – mql4beginner