请选择 进入手机版 | 继续访问电脑版
楼主: fantuanxiaot
11700 80

[源码分享] 基于R语言的文本挖掘tm和Rwordseg包的说明资料分享   [推广有奖]

Ψ▄┳一大卫卍卐席尔瓦

大师

8%

还不是VIP/贵宾

-

威望
7
论坛币
-234475 个
通用积分
124.0224
学术水平
3783 点
热心指数
3819 点
信用等级
3454 点
经验
150207 点
帖子
7546
精华
32
在线时间
1327 小时
注册时间
2013-2-3
最后登录
2022-2-24

初级学术勋章 初级热心勋章 中级热心勋章 中级学术勋章 初级信用勋章 中级信用勋章 高级热心勋章 高级学术勋章 特级学术勋章 特级热心勋章 高级信用勋章 特级信用勋章

fantuanxiaot 发表于 2015-1-23 11:08:52 |显示全部楼层 |坛友微信交流群
相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币


资料如下


本帖隐藏的内容

extensions.pdf (153.94 KB)
tm.pdf (168.46 KB)
Rwordseg_Vignette_CN.pdf (315.88 KB)







代码诸如:


本帖隐藏的内容


  1. ### R code from vignette source 'tm.Rnw'
  2. ### Encoding: UTF-8

  3. ###################################################
  4. ### code chunk number 1: Init
  5. ###################################################
  6. library("tm")
  7. data("crude")


  8. ###################################################
  9. ### code chunk number 2: Ovid
  10. ###################################################
  11. txt <- system.file("texts", "txt", package = "tm")
  12. (ovid <- Corpus(DirSource(txt, encoding = "UTF-8"),
  13.                 readerControl = list(language = "lat")))


  14. ###################################################
  15. ### code chunk number 3: VectorSource
  16. ###################################################
  17. docs <- c("This is a text.", "This another one.")
  18. Corpus(VectorSource(docs))


  19. ###################################################
  20. ### code chunk number 4: Reuters
  21. ###################################################
  22. reut21578 <- system.file("texts", "crude", package = "tm")
  23. reuters <- Corpus(DirSource(reut21578),
  24.                   readerControl = list(reader = readReut21578XML))


  25. ###################################################
  26. ### code chunk number 5: tm.Rnw:120-121 (eval = FALSE)
  27. ###################################################
  28. ## writeCorpus(ovid)


  29. ###################################################
  30. ### code chunk number 6: tm.Rnw:132-133
  31. ###################################################
  32. inspect(ovid[1:2])


  33. ###################################################
  34. ### code chunk number 7: tm.Rnw:137-138
  35. ###################################################
  36. identical(ovid[[2]], ovid[["ovid_2.txt"]])


  37. ###################################################
  38. ### code chunk number 8: tm.Rnw:156-157
  39. ###################################################
  40. reuters <- tm_map(reuters, as.PlainTextDocument)


  41. ###################################################
  42. ### code chunk number 9: tm.Rnw:165-166
  43. ###################################################
  44. reuters <- tm_map(reuters, stripWhitespace)


  45. ###################################################
  46. ### code chunk number 10: tm.Rnw:171-172
  47. ###################################################
  48. reuters <- tm_map(reuters, tolower)


  49. ###################################################
  50. ### code chunk number 11: Stopwords
  51. ###################################################
  52. reuters <- tm_map(reuters, removeWords, stopwords("english"))


  53. ###################################################
  54. ### code chunk number 12: Stemming
  55. ###################################################
  56. tm_map(reuters, stemDocument)


  57. ###################################################
  58. ### code chunk number 13: tm.Rnw:204-206
  59. ###################################################
  60. query <- "id == '237' & heading == 'INDONESIA SEEN AT CROSSROADS OVER ECONOMIC CHANGE'"
  61. tm_filter(reuters, FUN = sFilter, query)


  62. ###################################################
  63. ### code chunk number 14: DublinCore
  64. ###################################################
  65. DublinCore(crude[[1]], "Creator") <- "Ano Nymous"
  66. meta(crude[[1]])


  67. ###################################################
  68. ### code chunk number 15: tm.Rnw:237-241
  69. ###################################################
  70. meta(crude, tag = "test", type = "corpus") <- "test meta"
  71. meta(crude, type = "corpus")
  72. meta(crude, "foo") <- letters[1:20]
  73. meta(crude)


  74. ###################################################
  75. ### code chunk number 16: tm.Rnw:258-260
  76. ###################################################
  77. dtm <- DocumentTermMatrix(reuters)
  78. inspect(dtm[1:5,100:105])


  79. ###################################################
  80. ### code chunk number 17: tm.Rnw:269-270
  81. ###################################################
  82. findFreqTerms(dtm, 5)


  83. ###################################################
  84. ### code chunk number 18: tm.Rnw:275-276
  85. ###################################################
  86. findAssocs(dtm, "opec", 0.8)


  87. ###################################################
  88. ### code chunk number 19: tm.Rnw:288-289
  89. ###################################################
  90. inspect(removeSparseTerms(dtm, 0.4))


  91. ###################################################
  92. ### code chunk number 20: tm.Rnw:303-305
  93. ###################################################
  94. inspect(DocumentTermMatrix(reuters,
  95.                            list(dictionary = c("prices", "crude", "oil"))))
复制代码


  1. ### R code from vignette source 'extensions.Rnw'

  2. ###################################################
  3. ### code chunk number 1: Init
  4. ###################################################
  5. library("tm")
  6. library("XML")


  7. ###################################################
  8. ### code chunk number 2: extensions.Rnw:71-76
  9. ###################################################
  10. VecSource <- function(x) {
  11.     s <- Source(length = length(x), names = names(x), class = "VectorSource")
  12.     s$Content <- as.character(x)
  13.     s
  14. }


  15. ###################################################
  16. ### code chunk number 3: extensions.Rnw:85-89
  17. ###################################################
  18. getElem.VectorSource <-
  19. function(x) list(content = x$Content[x$Position], uri = NA)
  20. pGetElem.VectorSource <-
  21. function(x) lapply(x$Content, function(y) list(content = y, uri = NA))


  22. ###################################################
  23. ### code chunk number 4: extensions.Rnw:114-117
  24. ###################################################
  25. readPlain <-
  26. function(elem, language, id)
  27.     PlainTextDocument(elem$content, id = id, language = language)


  28. ###################################################
  29. ### code chunk number 5: extensions.Rnw:145-150
  30. ###################################################
  31. df <- data.frame(contents = c("content 1", "content 2", "content 3"),
  32.                  title    = c("title 1"  , "title 2"  , "title 3"  ),
  33.                  authors  = c("author 1" , "author 2" , "author 3" ),
  34.                  topics   = c("topic 1"  , "topic 2"  , "topic 3"  ),
  35.                  stringsAsFactors = FALSE)


  36. ###################################################
  37. ### code chunk number 6: extensions.Rnw:156-157
  38. ###################################################
  39. names(attributes(PlainTextDocument()))


  40. ###################################################
  41. ### code chunk number 7: Mapping
  42. ###################################################
  43. m <- list(Content = "contents", Heading = "title",
  44.           Author = "authors", Topic = "topics")


  45. ###################################################
  46. ### code chunk number 8: myReader
  47. ###################################################
  48. myReader <- readTabular(mapping = m)


  49. ###################################################
  50. ### code chunk number 9: extensions.Rnw:180-181
  51. ###################################################
  52. (corpus <- Corpus(DataframeSource(df), readerControl = list(reader = myReader)))


  53. ###################################################
  54. ### code chunk number 10: extensions.Rnw:186-188
  55. ###################################################
  56. corpus[[1]]
  57. meta(corpus[[1]])


  58. ###################################################
  59. ### code chunk number 11: CustomXMLFile
  60. ###################################################
  61. custom.xml <- system.file("texts", "custom.xml", package = "tm")
  62. print(readLines(custom.xml), quote = FALSE)


  63. ###################################################
  64. ### code chunk number 12: mySource
  65. ###################################################
  66. mySource <- function(x, encoding = "UTF-8")
  67.     XMLSource(x, function(tree) XML::xmlChildren(XML::xmlRoot(tree)), myXMLReader, encoding)


  68. ###################################################
  69. ### code chunk number 13: myXMLReader
  70. ###################################################
  71. myXMLReader <- readXML(
  72.     spec = list(Author = list("node", "/document/writer"),
  73.                 Content = list("node", "/document/description"),
  74.                 DateTimeStamp = list("function",
  75.                                      function(x) as.POSIXlt(Sys.time(), tz = "GMT")),
  76.                 Description = list("attribute", "/document/@short"),
  77.                 Heading = list("node", "/document/caption"),
  78.                 ID = list("function", function(x) tempfile()),
  79.                 Origin = list("unevaluated", "My private bibliography"),
  80.                 Type = list("node", "/document/type")),
  81.     doc = PlainTextDocument())


  82. ###################################################
  83. ### code chunk number 14: extensions.Rnw:301-302
  84. ###################################################
  85. corpus <- Corpus(mySource(custom.xml))


  86. ###################################################
  87. ### code chunk number 15: extensions.Rnw:306-308
  88. ###################################################
  89. corpus[[1]]
  90. meta(corpus[[1]])
复制代码




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:words 资料分享 文本挖掘 word R语言 资料

已有 3 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
jerker + 60 + 60 + 2 + 2 + 2 精彩帖子
chenyi112982 + 100 + 5 + 5 热心帮助其他会员
zhuosn + 5 补偿 (ZF规模越大GDP的增长越缓 )

总评分: 经验 + 160  论坛币 + 65  学术水平 + 7  热心指数 + 7  信用等级 + 2   查看全部评分

本帖被以下文库推荐

fantuanxiaot 发表于 2015-1-23 11:12:04 |显示全部楼层 |坛友微信交流群
先自己顶一个

使用道具

tt_abc 发表于 2015-1-23 11:21:00 |显示全部楼层 |坛友微信交流群

回帖奖励 +3

学习一下

使用道具

nndbc 发表于 2015-1-23 11:21:56 |显示全部楼层 |坛友微信交流群

使用道具

nndbc 发表于 2015-1-23 11:23:25 |显示全部楼层 |坛友微信交流群
R语言确实强大
已有 1 人评分论坛币 收起 理由
fantuanxiaot + 3 精彩帖子

总评分: 论坛币 + 3   查看全部评分

使用道具

fengyg 企业认证  发表于 2015-1-23 11:47:53 |显示全部楼层 |坛友微信交流群

回帖奖励 +3

kankan

使用道具

mike68097 发表于 2015-1-23 12:11:22 |显示全部楼层 |坛友微信交流群
支持!!!!

使用道具

Crsky7 发表于 2015-1-23 12:43:41 |显示全部楼层 |坛友微信交流群
文本挖掘技术哪家强?

使用道具

Crsky7 发表于 2015-1-23 12:44:39 |显示全部楼层 |坛友微信交流群

回帖奖励 +3

R语言还是Python

使用道具

mathoufei 发表于 2015-1-23 12:47:20 |显示全部楼层 |坛友微信交流群

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jr
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-16 16:16