古希臘文翻譯[問題類型]:
程式諮詢
[軟體熟習度]:
入門(寫過其他程式,只是對語法不熟習)
[問題論述]:
各人好,比來剛接觸文字探勘
參考了陳嘉葳大大 翻譯文章:用R進行中文 text Mining
(http://goo.gl/3mTrDg)
我也照做了一番,有些處所因為有更新所以有本身修改 翻譯社
問題1:
在輸出TermDocumentMatrix時,出現了以下的樣子
不知道怎麼把
弄掉,原本的文章也沒有長這樣。
Docs
Terms 1 2 3 4 5
平生
自願 0 0 0 0 0
一生
味道 0 0 0 0 0
一家
嘴
罐子 1 0 0 0 0
一連串 0 0 0 0 0
人
0 0 0 0 0
人
人
人
強者
同窗 0 0 0 0 0
人
人
小學 0 0 0 0 0
人
人
事
課
精力 0 0 0 0 0
人
人
工具 0 0 0 0 0
人
山
雙手 0 0 0 0 0
問題2:
輸出 翻譯文字雲長如許
http://i.imgur.com/W6Bo2Tk.png
明明程式碼一樣,不知為何我的倒是方的,並且沒有很密集。
想知道問題出在哪。
問題3:
由於原文章只鎖命名詞
d.corpus <- tm_map(d.corpus[1:100] 翻譯公司 segmentCN 翻譯公司 nature = TRUE)
d.corpus <- tm_map(d.corpus 翻譯公司 function(sentence) {
noun <- lapply(sentence 翻譯公司 function(w) {
w[names(w) == "n"]
})
unlist(noun)
})
若所有詞性都想要,該怎麼做呢?
我有試做看看,卻在輸出tdm時獲得error
Error in `[.simple_triplet_matrix`(tdm 翻譯公司 1:10 翻譯公司 1:5) :
subscript out of bounds
[程式範例]:
大要的程式碼如下:
d.corpus0 <- Corpus(DirSource('doc'), list(language = NA)) #語料庫
d.corpus_clean <- tm_map(d.corpus0, removePunctuation)
d.corpus_clean <- tm_map(d.corpus_clean, removeNumbers)
d.corpus_clean <- tm_map(d.corpus_clean 翻譯公司 function(word) {
gsub("[A-Za-z0-9]", "", word)
})
d.corpus_seg <- tm_map(d.corpus_clean[1:100] 翻譯公司 segmentCN, nature = TRUE)
d.corpus_seg2 <- tm_map(d.corpus_seg, function(sentence) {
noun <- lapply(sentence, function(w) {
w[names(w) == "n"]
})
unlist(noun)
})
#d.corpus_vec <- Corpus(VectorSource(d.corpus_seg)) #沒法run
d.corpus_stop <- tm_map(d.corpus_seg2, removeWords, myStopWords)
#確立TermDocumentMatrix(本身修改過)
corpus_clean <- tm_map(d.corpus_stop, PlainTextDocument)
d.corpus_vec <- Corpus(VectorSource(corpus_clean))
tdm <- TermDocumentMatrix(d.corpus_vec, control = list(wordLengths = c(2,
Inf)))
#文字雲
m1 <- as.matrix(tdm)
v <- sort(rowSums(m1), decreasing = TRUE)
d <- data.frame(word = names(v), freq = v)
wordcloud(d$word, d$freq, min.freq = 2, random.order = F, ordered.colors = F,
colors = rainbow(length(row.names(m1))))
這個問題已困擾我好幾天,想了很久也找良多資料照樣無解,才想說上來請列位高手解
答
小妹第一次在本版發文,若有任何不當請多多原諒:)
[要害字]:
文字探勘,text mining。-> 翻譯社|,-> 翻譯公司|的-> 翻譯
文章來自: https://www.ptt.cc/bbs/R_Language/M.1439908857.A.A29.html有關翻譯的問題歡迎諮詢天成翻譯社
- Dec 04 Mon 2017 15:21
[問題] 關於文字探勘
close
文章標籤
全站熱搜
留言列表