楼主: Limdep
1135 8

Text Mining Infrastructure in R [推广有奖]

  • 0关注
  • 2粉丝

已卖:117份资源

本科生

98%

还不是VIP/贵宾

-

TA的文库  其他...

Java资源全汇

Data Science NewOccidental

Database NewOccidental

威望
0
论坛币
4718 个
通用积分
4.2550
学术水平
8 点
热心指数
3 点
信用等级
3 点
经验
1089 点
帖子
133
精华
0
在线时间
20 小时
注册时间
2006-5-15
最后登录
2017-10-27

楼主
Limdep 发表于 2016-8-3 10:41:31 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币

thors:

Ingo Feinerer, Kurt Hornik, David Meyer

Title:

Text Mining Infrastructure in R

Abstract:

During the last decade text mining has become a widely used discipline utilizing statistical and machine learning methods. We present the tmpackage which provides a framework for text mining applications within R. We give a survey on text mining facilities in R and explain how typical application tasks can be carried out using our framework. We present techniques for count-based analysis methods, text clustering, text classification and string kernels.

Page views:: 105581. Submitted: 2007-09-05. Published: 2008-03-31.

Paper:

Text Mining Infrastructure in R     [size=1em]Download PDF (Downloads: 105019)

Supplements:

tm_0.3.tar.gz: R source package

[size=1em]Download(Downloads: 5677; 569KB)

v25i05.R: R example code from the paper

[size=1em]Download(Downloads: 10196; 25KB)


DOI:

10.18637/jss.v025.i05

二维码

扫码加我 拉你入群

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

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

关键词:Text Mining Structure INFRAS struct ning discipline facilities techniques framework learning

沙发
Limdep 发表于 2016-8-3 10:43:19
  1. ###################################################
  2. ### chunk number 1: Preliminaries
  3. ###################################################
  4. library("clue")
  5. library("tm")


  6. ###################################################
  7. ### chunk number 2: NewCorpus eval=FALSE
  8. ###################################################
  9. ## new("Corpus", .Data = ..., DMetaData = ..., CMetaData = ..., DBControl = ...)


  10. ###################################################
  11. ### chunk number 3: CorpusConstructor eval=FALSE
  12. ###################################################
  13. ## Corpus(object = ...,
  14. ##            readerControl = list(reader = object@DefaultReader,
  15. ##                            language = "en_US",
  16. ##                            load = FALSE),
  17. ##            dbControl = list(useDb = TRUE,
  18. ##                             dbName = "texts.db",
  19. ##                             dbType = "DB1"))


  20. ###################################################
  21. ### chunk number 4: NewPlainTextDocument eval=FALSE
  22. ###################################################
  23. ## new("PlainTextDocument", .Data = "Some text.", URI = uri, Cached = TRUE,
  24. ##     Author = "Mr. Nobody", DateTimeStamp = Sys.time(),
  25. ##     Description = "Example", ID = "ID1", Origin = "Custom",
  26. ##     Heading = "Ex. 1", Language = "en_US")


  27. ###################################################
  28. ### chunk number 5: NewTextRepository eval=FALSE
  29. ###################################################
  30. ## new("TextRepository",
  31. ##     .Data = list(Col1, Col2), RepoMetaData = list(created = "now"))
复制代码

藤椅
Limdep 发表于 2016-8-3 10:44:41
  1. ###################################################
  2. ### chunk number 6: NewTermDocMatrix eval=FALSE
  3. ###################################################
  4. ## new("TermDocMatrix", Data = tdm, Weighting = weightTf)


  5. ###################################################
  6. ### chunk number 7: WekaTokenizer eval=FALSE
  7. ###################################################
  8. ## TermDocMatrix(col, control = list(tokenize = NGramTokenizer))


  9. ###################################################
  10. ### chunk number 8: openNLPTokenizer eval=FALSE
  11. ###################################################
  12. ## TermDocMatrix(col, control = list(tokenize = tokenize))


  13. ###################################################
  14. ### chunk number 9: SentenceDetection eval=FALSE
  15. ###################################################
  16. ## TermDocMatrix(col, control = list(tokenize = sentDetect))


  17. ###################################################
  18. ### chunk number 10: NewDirSource eval=FALSE
  19. ###################################################
  20. ## new("DirSource", LoDSupport = TRUE, FileList = dir(),
  21. ##     Position = 0, DefaultReader = readPlain, Encoding = "latin1")
复制代码

板凳
Limdep 发表于 2016-8-3 10:45:40
  1. ###################################################
  2. ### chunk number 11: Ovid
  3. ###################################################
  4. txt <- system.file("texts", "txt", package = "tm")
  5. (ovid <- Corpus(DirSource(txt),
  6.                     readerControl = list(reader = readPlain,
  7.                                          language = "la",
  8.                                          load = TRUE)))


  9. ###################################################
  10. ### chunk number 12: CorpusDBSupport eval=FALSE
  11. ###################################################
  12. ## Corpus(DirSource(txt),
  13. ##            readerControl = list(reader = readPlain,
  14. ##                                 language = "la", load = TRUE),
  15. ##            dbControl = list(useDb = TRUE,
  16. ##                             dbName = "/home/user/oviddb",
  17. ##                             dbType = "DB1"))


  18. ###################################################
  19. ### chunk number 13: IDOvid
  20. ###################################################
  21. ID(ovid[[1]])


  22. ###################################################
  23. ### chunk number 14: AuthorOvid
  24. ###################################################
  25. Author(ovid[[1]]) <- "Publius Ovidius Naso"


  26. ###################################################
  27. ### chunk number 15:
  28. ###################################################
  29. meta(ovid[[1]])
复制代码

报纸
Limdep 发表于 2016-8-3 10:48:55
  1. ###################################################
  2. ### chunk number 11: Ovid
  3. ###################################################
  4. txt <- system.file("texts", "txt", package = "tm")
  5. (ovid <- Corpus(DirSource(txt),
  6.                     readerControl = list(reader = readPlain,
  7.                                          language = "la",
  8.                                          load = TRUE)))


  9. ###################################################
  10. ### chunk number 12: CorpusDBSupport eval=FALSE
  11. ###################################################
  12. ## Corpus(DirSource(txt),
  13. ##            readerControl = list(reader = readPlain,
  14. ##                                 language = "la", load = TRUE),
  15. ##            dbControl = list(useDb = TRUE,
  16. ##                             dbName = "/home/user/oviddb",
  17. ##                             dbType = "DB1"))


  18. ###################################################
  19. ### chunk number 13: IDOvid
  20. ###################################################
  21. ID(ovid[[1]])


  22. ###################################################
  23. ### chunk number 14: AuthorOvid
  24. ###################################################
  25. Author(ovid[[1]]) <- "Publius Ovidius Naso"


  26. ###################################################
  27. ### chunk number 15:
  28. ###################################################
  29. meta(ovid[[1]])


  30. ###################################################
  31. ### chunk number 16: OvidSubset
  32. ###################################################
  33. ovid[1:3]


  34. ###################################################
  35. ### chunk number 17: OvidDocument
  36. ###################################################
  37. ovid[[1]]


  38. ###################################################
  39. ### chunk number 18: Concatenation
  40. ###################################################
  41. c(ovid[1:2], ovid[3:4])


  42. ###################################################
  43. ### chunk number 19: LengthOvid
  44. ###################################################
  45. length(ovid)


  46. ###################################################
  47. ### chunk number 20: SummaryOvid
  48. ###################################################
  49. summary(ovid)


  50. ###################################################
  51. ### chunk number 21: tmUpdate
  52. ###################################################
  53. tmUpdate(ovid, DirSource(txt))


  54. ###################################################
  55. ### chunk number 22: OvidMeta
  56. ###################################################
  57. ovid <- appendMeta(ovid,
  58.                    cmeta = list(test = c(1,2,3)),
  59.                    dmeta = list(clust = c(1,1,2,2,2)))
  60. summary(ovid)
  61. CMetaData(ovid)
  62. DMetaData(ovid)


  63. ###################################################
  64. ### chunk number 23: OvidAppendElem
  65. ###################################################
  66. (ovid <- appendElem(ovid, data = ovid[[1]], list(clust = 1)))


  67. ###################################################
  68. ### chunk number 24: TextRepo
  69. ###################################################
  70. (repo <- TextRepository(ovid))


  71. ###################################################
  72. ### chunk number 25: TextRepoMeta
  73. ###################################################
  74. repo <- appendElem(repo, ovid, list(modified = date()))
  75. repo <- appendMeta(repo, list(moremeta = 5:10))
  76. summary(repo)
  77. RepoMetaData(repo)


  78. ###################################################
  79. ### chunk number 26:
  80. ###################################################
  81. meta(ovid, type = "corpus", "foo") <- "bar"
  82. meta(ovid, type = "corpus")
  83. meta(ovid, "someTag") <- 6:11
  84. meta(ovid)


  85. ###################################################
  86. ### chunk number 27: tmMap
  87. ###################################################
  88. tmMap(ovid, FUN = tmTolower)


  89. ###################################################
  90. ### chunk number 28: tmFilter
  91. ###################################################
  92. tmFilter(ovid, FUN = searchFullText, "Venus", doclevel = TRUE)


  93. ###################################################
  94. ### chunk number 29: tmIndex
  95. ###################################################
  96. tmIndex(ovid, "identifier == '2'")


  97. ###################################################
  98. ### chunk number 30: GmaneSource eval=FALSE
  99. ###################################################
  100. ## setClass("GmaneSource",
  101. ##          representation(URI = "ANY", Content = "list"),
  102. ##          contains = c("Source"))


  103. ###################################################
  104. ### chunk number 31: GmaneSourceConstructor eval=FALSE
  105. ###################################################
  106. ## setMethod("GmaneSource",
  107. ##           signature(object = "ANY"),
  108. ##           function(object, encoding = "UTF-8") {
  109. ##               ## ---code chunk---
  110. ##               new("GmaneSource", LoDSupport = FALSE, URI = object,
  111. ##                   Content = content, Position = 0, Encoding = encoding)
  112. ##           })


  113. ###################################################
  114. ### chunk number 32: stepNext eval=FALSE
  115. ###################################################
  116. ## setMethod("stepNext",
  117. ##           signature(object = "GmaneSource"),
  118. ##           function(object) {
  119. ##               object@Position <- object@Position + 1
  120. ##               object
  121. ##           })


  122. ###################################################
  123. ### chunk number 33: getElem eval=FALSE
  124. ###################################################
  125. ## setMethod("getElem",
  126. ##           signature(object = "GmaneSource"),
  127. ##           function(object) {
  128. ##               ## ---code chunk---
  129. ##               list(content = content, uri = object@URI)
  130. ##           })


  131. ###################################################
  132. ### chunk number 34: eoi eval=FALSE
  133. ###################################################
  134. ## setMethod("eoi",
  135. ##           signature(object = "GmaneSource"),
  136. ##           function(object) {
  137. ##               length(object@Content) <= object@Position
  138. ##           })


  139. ###################################################
  140. ### chunk number 35: readGmane eval=FALSE
  141. ###################################################
  142. ## readGmane <- FunctionGenerator(function(...) {
  143. ##     function(elem, load, language, id) {
  144. ##         ## ---code chunk---
  145. ##         new("NewsgroupDocument", .Data = content, URI = elem$uri,
  146. ##             Cached = TRUE, Author = author, DateTimeStamp = datetimestamp,
  147. ##             Description = "", ID = id, Origin = origin, Heading = heading,
  148. ##             Language = language, Newsgroup = newsgroup)
  149. ##     }
  150. ## })


  151. ###################################################
  152. ### chunk number 36: GmaneCorpus
  153. ###################################################
  154. rss <- system.file("texts", "gmane.comp.lang.r.gr.rdf", package = "tm")
  155. Corpus(GmaneSource(rss), readerControl = list(reader = readGmane, language = "en_US", load = TRUE))


  156. ###################################################
  157. ### chunk number 37: readPDF eval=FALSE
  158. ###################################################
  159. ## readPDF <- FunctionGenerator(function(...) {
  160. ##   function(elem, load, language, id) {
  161. ##     ## get metadata
  162. ##     meta <- system(paste("pdfinfo", as.character(elem$uri[2])),
  163. ##                    intern = TRUE)
  164. ##
  165. ##     ## extract and store main information, e.g.:
  166. ##     heading <- gsub("Title:[[:space:]]*", "",
  167. ##                     grep("Title:", meta, value = TRUE))
  168. ##
  169. ##     ## [... similar for other metadata ...]
  170. ##
  171. ##     ## extract text from PDF using the external pdftotext utility:
  172. ##     corpus <- paste(system(paste("pdftotext", as.character(elem$uri[2]), "-"),
  173. ##                            intern = TRUE),
  174. ##                     sep = "\n", collapse = "")
  175. ##
  176. ##     ## create new text document object:
  177. ##     new("PlainTextDocument", .Data = corpus, URI = elem$uri, Cached = TRUE,
  178. ##         Author = author, DateTimeStamp = datetimestamp,
  179. ##         Description = description, ID = id, Origin = origin,
  180. ##         Heading = heading, Language = language)
  181. ##     }
  182. ## })


  183. ###################################################
  184. ### chunk number 38: TransformExtension eval=FALSE
  185. ###################################################
  186. ## setGeneric("myTransform", function(object, ...) standardGeneric("myTransform"))
  187. ## setMethod("myTransform",
  188. ##           signature(object = "PlainTextDocument"),
  189. ##           function(object, ..., DMetaData) {
  190. ##               Content(object) <- doSomeThing(object, DMetaData)
  191. ##               return(object)
  192. ##           })


  193. ###################################################
  194. ### chunk number 39: Reuters
  195. ###################################################
  196. reut21578XMLgz <- system.file("texts", "reut21578.xml.gz", package = "tm")
  197. (Reuters <- Corpus(ReutersSource(gzfile(reut21578XMLgz)),
  198.                        readerControl = list(reader = readReut21578XML,
  199.                                             language = "en_US",
  200.                                             load = TRUE)))


  201. ###################################################
  202. ### chunk number 40:
  203. ###################################################
  204. tmMap(Reuters, asPlain)
复制代码

地板
Limdep 发表于 2016-8-3 10:50:35
  1. ###################################################
  2. ### chunk number 41:  eval=FALSE
  3. ###################################################
  4. ## tmFilter(crude, "Topics == 'crude'")


  5. ###################################################
  6. ### chunk number 42: AcqCrude
  7. ###################################################
  8. data("acq")
  9. data("crude")


  10. ###################################################
  11. ### chunk number 43:  eval=FALSE
  12. ###################################################
  13. ## acq[[10]]


  14. ###################################################
  15. ### chunk number 44:
  16. ###################################################
  17. strwrap(acq[[10]])


  18. ###################################################
  19. ### chunk number 45:  eval=FALSE
  20. ###################################################
  21. ## stemDoc(acq[[10]])


  22. ###################################################
  23. ### chunk number 46:
  24. ###################################################
  25. strwrap(stemDoc(acq[[10]]))


  26. ###################################################
  27. ### chunk number 47:
  28. ###################################################
  29. tmMap(acq, stemDoc)


  30. ###################################################
  31. ### chunk number 48:  eval=FALSE
  32. ###################################################
  33. ## stripWhitespace(acq[[10]])


  34. ###################################################
  35. ### chunk number 49:
  36. ###################################################
  37. strwrap(stripWhitespace(acq[[10]]))


  38. ###################################################
  39. ### chunk number 50:  eval=FALSE
  40. ###################################################
  41. ## tmTolower(acq[[10]])


  42. ###################################################
  43. ### chunk number 51:
  44. ###################################################
  45. strwrap(tmTolower(acq[[10]]))


  46. ###################################################
  47. ### chunk number 52: stopwords
  48. ###################################################
  49. mystopwords <- c("and", "for", "in", "is", "it", "not", "the", "to")


  50. ###################################################
  51. ### chunk number 53:  eval=FALSE
  52. ###################################################
  53. ## removeWords(acq[[10]], mystopwords)


  54. ###################################################
  55. ### chunk number 54:
  56. ###################################################
  57. strwrap(removeWords(acq[[10]], mystopwords))


  58. ###################################################
  59. ### chunk number 55:  eval=FALSE
  60. ###################################################
  61. ## tmMap(acq, removeWords, mystopwords)


  62. ###################################################
  63. ### chunk number 56:  eval=FALSE
  64. ###################################################
  65. ## stopwords(language = ...)


  66. ###################################################
  67. ### chunk number 57:
  68. ###################################################
  69. library("wordnet")


  70. ###################################################
  71. ### chunk number 58:
  72. ###################################################
  73. synonyms("company")


  74. ###################################################
  75. ### chunk number 59:  eval=FALSE
  76. ###################################################
  77. ## replaceWords(acq[[10]], synonyms(dict, "company"), by = "company")


  78. ###################################################
  79. ### chunk number 60:  eval=FALSE
  80. ###################################################
  81. ## tmMap(acq, replaceWords, synonyms(dict, "company"), by = "company")


  82. ###################################################
  83. ### chunk number 61:  eval=FALSE
  84. ###################################################
  85. ## library("openNLP")
  86. ## tagPOS(acq[[10]])


  87. ###################################################
  88. ### chunk number 62:
  89. ###################################################
  90. library("openNLP")
  91. strwrap(tagPOS(acq[[10]]))


  92. ###################################################
  93. ### chunk number 63:
  94. ###################################################
  95. # Creates the term-document matrix for our crude data set
  96. crudeTDM <- TermDocMatrix(crude, control = list(stopwords = TRUE))


  97. ###################################################
  98. ### chunk number 64:
  99. ###################################################
  100. # Terms with more than 10 occurrences
  101. (crudeTDMHighFreq <- findFreqTerms(crudeTDM, 10, Inf))


  102. ###################################################
  103. ### chunk number 65:
  104. ###################################################
  105. # Frequencies for high frequency terms
  106. Data(crudeTDM)[1:10,crudeTDMHighFreq]


  107. ###################################################
  108. ### chunk number 66:
  109. ###################################################
  110. findAssocs(crudeTDM, "oil", 0.85)


  111. ###################################################
  112. ### chunk number 67:
  113. ###################################################
  114. plot(crudeTDM, corThreshold = 0.5, terms = findFreqTerms(crudeTDM, 6, Inf))


  115. ###################################################
  116. ### chunk number 68:
  117. ###################################################
  118. ws <- c(acq, crude)
  119. summary(ws)


  120. ###################################################
  121. ### chunk number 69: dissimilarityTermDocMatrix eval=FALSE
  122. ###################################################
  123. ## dissimilarity(crudeTDM, method = "cosine")


  124. ###################################################
  125. ### chunk number 70: dissimilarityTwoDocs
  126. ###################################################
  127. dissimilarity(crude[[1]], crude[[2]], "cosine")


  128. ###################################################
  129. ### chunk number 71: wsTermDocMatrix
  130. ###################################################
  131. wsTDM <- Data(TermDocMatrix(ws))


  132. ###################################################
  133. ### chunk number 72:
  134. ###################################################
  135. wsHClust <- hclust(dist(wsTDM), method = "ward")


  136. ###################################################
  137. ### chunk number 73:
  138. ###################################################
  139. plot(wsHClust, labels = c(rep("acq",50), rep("crude",20)))


  140. ###################################################
  141. ### chunk number 74: kmeans
  142. ###################################################
  143. wsKMeans <- kmeans(wsTDM, 2)


  144. ###################################################
  145. ### chunk number 75:
  146. ###################################################
  147. wsReutersCluster <- c(rep("acq",50), rep("crude",20))


  148. ###################################################
  149. ### chunk number 76:
  150. ###################################################
  151. cl_agreement(wsKMeans, as.cl_partition(wsReutersCluster), "diag")


  152. ###################################################
  153. ### chunk number 77:
  154. ###################################################
  155. library("class")
  156. library("kernlab")
  157. data(spam)


  158. ###################################################
  159. ### chunk number 78:
  160. ###################################################
  161. train <- rbind(spam[1:1360, ], spam[1814:3905, ])


  162. ###################################################
  163. ### chunk number 79:
  164. ###################################################
  165. trainCl <- train[,"type"]


  166. ###################################################
  167. ### chunk number 80:
  168. ###################################################
  169. test <- rbind(spam[1361:1813, ], spam[3906:4601, ])


  170. ###################################################
  171. ### chunk number 81:
  172. ###################################################
  173. trueCl <- test[,"type"]


  174. ###################################################
  175. ### chunk number 82: knn
  176. ###################################################
  177. knnCl <- knn(train[,-58], test[,-58], trainCl)


  178. ###################################################
  179. ### chunk number 83:
  180. ###################################################
  181. (nnTable <- table("1-NN" = knnCl, "Reuters" = trueCl))


  182. ###################################################
  183. ### chunk number 84:
  184. ###################################################
  185. sum(diag(nnTable))/nrow(test)


  186. ###################################################
  187. ### chunk number 85: ksvm
  188. ###################################################
  189. ksvmTrain <- ksvm(type ~ ., data = train)


  190. ###################################################
  191. ### chunk number 86:
  192. ###################################################
  193. svmCl <- predict(ksvmTrain, test[,-58])


  194. ###################################################
  195. ### chunk number 87:
  196. ###################################################
  197. (svmTable <- table("SVM" = svmCl, "Reuters" = trueCl))


  198. ###################################################
  199. ### chunk number 88:
  200. ###################################################
  201. sum(diag(svmTable))/nrow(test)


  202. ###################################################
  203. ### chunk number 89:
  204. ###################################################
  205. # Instantiate both string kernels
  206. stringkern <- stringdot(type = "string")


  207. ###################################################
  208. ### chunk number 90:  eval=FALSE
  209. ###################################################
  210. ## # Perform spectral clustering with string kernels
  211. ## stringCl <- specc(ws, 2, kernel = stringkern)


  212. ###################################################
  213. ### chunk number 91: specc
  214. ###################################################
  215. set.seed(1234)
  216. stringkern
  217. stringCl <- as.vector(specc(ws, 2, kernel = stringkern))


  218. ###################################################
  219. ### chunk number 92:
  220. ###################################################
  221. table("String Kernel" = stringCl, "Reuters" = wsReutersCluster)


  222. ###################################################
  223. ### chunk number 93:  eval=FALSE
  224. ###################################################
  225. ## convertMboxEml("2006.txt", "2006/")


  226. ###################################################
  227. ### chunk number 94: Rdevel eval=FALSE
  228. ###################################################
  229. ## rdevel <- Corpus(DirSource("2006/"),
  230. ##                      readerControl = list(reader = readNewsgroup,
  231. ##                                           language = "en_US",
  232. ##                                           load = TRUE))


  233. ###################################################
  234. ### chunk number 95:  eval=FALSE
  235. ###################################################
  236. ## rdevel <- tmMap(rdevel, asPlain)


  237. ###################################################
  238. ### chunk number 96:  eval=FALSE
  239. ###################################################
  240. ## rdevel <- tmMap(rdevel, stripWhitespace)
  241. ## rdevel <- tmMap(rdevel, tmTolower)


  242. ###################################################
  243. ### chunk number 97:  eval=FALSE
  244. ###################################################
  245. ## summary(rdevel)


  246. ###################################################
  247. ### chunk number 98:  eval=FALSE
  248. ###################################################
  249. ## tdm <- TermDocMatrix(rdevel, list(stemming = TRUE, stopwords = TRUE))


  250. ###################################################
  251. ### chunk number 99:  eval=FALSE
  252. ###################################################
  253. ## authors <- lapply(rdevel, Author)
  254. ## authors <- sapply(authors, paste, collapse = " ")


  255. ###################################################
  256. ### chunk number 100:  eval=FALSE
  257. ###################################################
  258. ## sort(table(authors), decreasing = TRUE)[1:3]
复制代码

7
Limdep 发表于 2016-8-3 10:51:36
  1. ###################################################
  2. ### chunk number 101:  eval=FALSE
  3. ###################################################
  4. ## headings <- lapply(rdevel, Heading)
  5. ## headings <- sapply(headings, paste, collapse = " ")


  6. ###################################################
  7. ### chunk number 102:  eval=FALSE
  8. ###################################################
  9. ## (bigTopicsTable <- sort(table(headings), decreasing = TRUE)[1:3])
  10. ## bigTopics <- names(bigTopicsTable)


  11. ###################################################
  12. ### chunk number 103:  eval=FALSE
  13. ###################################################
  14. ## topicCol <- rdevel[headings == bigTopics[1]]
  15. ## unique(sapply(topicCol, Author))


  16. ###################################################
  17. ### chunk number 104:  eval=FALSE
  18. ###################################################
  19. ## topicCol <- rdevel[headings == bigTopics[2]]
  20. ## unique(sapply(topicCol, Author))


  21. ###################################################
  22. ### chunk number 105: bugCol eval=FALSE
  23. ###################################################
  24. ## (bugCol <- tmFilter(rdevel,
  25. ##                     FUN = searchFullText, "[^[:alpha:]]+bug[^[:alpha:]]+",
  26. ##                     doclevel = TRUE))


  27. ###################################################
  28. ### chunk number 106:  eval=FALSE
  29. ###################################################
  30. ## bugColAuthors <- lapply(bugCol, Author)
  31. ## bugColAuthors <- sapply(bugColAuthors, paste, collapse = " ")
  32. ## sort(table(bugColAuthors), decreasing = TRUE)[1:3]


  33. ###################################################
  34. ### chunk number 107: findFreqTermsTDM eval=FALSE
  35. ###################################################
  36. ## f <- findFreqTerms(tdm, 30, 31)
  37. ## sort(f[-grep("[0-9]", f)])


  38. ###################################################
  39. ### chunk number 108: removeCitationSignature
  40. ###################################################
  41. setGeneric("removeCitationSignature",
  42.            function(object, ...) standardGeneric("removeCitationSignature"))
  43. setMethod("removeCitationSignature",
  44.           signature(object = "PlainTextDocument"),
  45.           function(object, ...) {
  46.               c <- Content(object)

  47.               ## Remove citations starting with '>'
  48.               citations <- grep("^[[:blank:]]*>.*", c)
  49.               if (length(citations) > 0)
  50.                   c <- c[-citations]

  51.               ## Remove signatures starting with '-- '
  52.               signatureStart <- grep("^-- $", c)
  53.               if (length(signatureStart) > 0)
  54.                   c <- c[-(signatureStart:length(c))]

  55.               Content(object) <- c
  56.               return(object)
  57.           })


  58. ###################################################
  59. ### chunk number 109:  eval=FALSE
  60. ###################################################
  61. ## rdevelInc <- tmMap(rdevel, removeCitationSignature)


  62. ###################################################
  63. ### chunk number 110:  eval=FALSE
  64. ###################################################
  65. ## tdmInc <- TermDocMatrix(rdevelInc, list(stemming = TRUE, stopwords = TRUE))


  66. ###################################################
  67. ### chunk number 111: findFreqTermsTDMInc eval=FALSE
  68. ###################################################
  69. ## f <- findFreqTerms(tdmInc, 30, 31)
  70. ## sort(f[-grep("[0-9]", f)])


  71. ###################################################
  72. ### chunk number 112: subjectCounts eval=FALSE
  73. ###################################################
  74. ## subjectCounts <- 0
  75. ## for (r in rdevelInc) {
  76. ##     ## Get single characters from subject
  77. ##     h <- unlist(strsplit(Heading(r), " "))
  78. ##
  79. ##     ## Count unique matches of subject strings within document
  80. ##     len <- length(unique(unlist(lapply(h, grep, r, fixed = TRUE))))
  81. ##
  82. ##     ## Update counter
  83. ##     subjectCounts <- c(subjectCounts, len)
  84. ## }
  85. ## summary(subjectCounts)
复制代码

8
szrjshen 发表于 2016-8-3 16:27:01
高大上

9
RichardBrown 发表于 2016-8-7 11:39:49
弱弱的问一声,在什么地方下载啊?

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-2 10:57