pinglun1=read.table("1.txt",sep="|")
# == 文本预处理
res=pinglun1[pinglun1!=" "];
#剔除通用标题
res=gsub(pattern="[專賣店【未拆封順豐】||]+"," ",res);
#剔除特殊词
res=gsub(pattern="[我|你|的|了|是]"," ",res);
#清理文本里的回车!否则每个回车就会被识别成一段文本
res=gsub("\n","",res)
###############
library(rJava);
library(Rwordseg);
# == 分词+频数统计
words=unlist(lapply(X=res, FUN=segmentCN));
word=lapply(X=words, FUN=strsplit, " ");
v=table(unlist(word));
# 降序排序
v=rev(sort(v));
d=data.frame(word=names(v), freq=v);
# 过滤掉1个字和词频小于100的记录
d=subset(d, nchar(as.character(d$word))>1 & d$freq>=100)
# == 输出结果
write.table(d, file="E: \\worldcup_keyword.txt", row.names=FALSE)
#############绘制词汇图####################3
library("wordcloud")
mycolors <- brewer.pal(8,"Dark2")#设置一个颜色系:
wordcloud(d[1:30,]$word,d[1:30,]$freq,random.order=FALSE,random.color=FALSE,colors=mycolors,family="myFont3")
write.csv(d[1:30,], file="E:\\ 30个keyword.csv", row.names=FALSE)
# == 文本预处理
res=pinglun1[pinglun1!=" "];
#剔除通用标题
res=gsub(pattern="[專賣店【未拆封順豐】||]+"," ",res);
#剔除特殊词
res=gsub(pattern="[我|你|的|了|是]"," ",res);
#清理文本里的回车!否则每个回车就会被识别成一段文本
res=gsub("\n","",res)
###############
library(rJava);
library(Rwordseg);
# == 分词+频数统计
words=unlist(lapply(X=res, FUN=segmentCN));
word=lapply(X=words, FUN=strsplit, " ");
v=table(unlist(word));
# 降序排序
v=rev(sort(v));
d=data.frame(word=names(v), freq=v);
# 过滤掉1个字和词频小于100的记录
d=subset(d, nchar(as.character(d$word))>1 & d$freq>=100)
# == 输出结果
write.table(d, file="E: \\worldcup_keyword.txt", row.names=FALSE)
#############绘制词汇图####################3
library("wordcloud")
mycolors <- brewer.pal(8,"Dark2")#设置一个颜色系:
wordcloud(d[1:30,]$word,d[1:30,]$freq,random.order=FALSE,random.color=FALSE,colors=mycolors,family="myFont3")
write.csv(d[1:30,], file="E:\\ 30个keyword.csv", row.names=FALSE)