不是创建html文件的方法是,从R中的许多html文件创建一个语料库

这应该做到这一点.在这里,我的计算机上有一个HTML文件的文件夹(来自SO的随机样本),我用它们创建了一个语料库,然后是一个文档术语矩阵,然后完成了一些简单的文本挖掘任务.

# get data

setwd("C:/Downloads/html") # this folder has your HTML files

html

# load packages

library(tm)

library(RCurl)

library(XML)

# get some code from github to convert HTML to text

writeChar(con="htmlToText.R", (getURL(ssl.verifypeer = FALSE, "https://raw.github.com/tonybreyal/Blog-Reference-Functions/master/R/htmlToText/htmlToText.R")))

source("htmlToText.R")

# convert HTML to text

html2txt

# clean out non-ASCII characters

html2txtclean

# make corpus for text mining

corpus

# process text...

skipWords

funcs

a

a

a.dtm1

newstopwords

# remove most frequent words for this corpus

a.dtm2

inspect(a.dtm2)

# carry on with typical things that can now be done, ie. cluster analysis

a.dtm3

a.dtm.df

a.dtm.df.scale

d

fit

plot(fit)

# just for fun...

library(wordcloud)

library(RColorBrewer)

m = as.matrix(t(a.dtm1))

# get word counts in decreasing order

word_freqs = sort(colSums(m), decreasing=TRUE)

# create a data frame with words and their frequencies

dm = data.frame(word=names(word_freqs), freq=word_freqs)

# plot wordcloud

wordcloud(dm$word, dm$freq, random.order=FALSE, colors=brewer.pal(8, "Dark2"))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值