【问题标题】:Marking or Tagging Non-structured Data (Text data) with combination of words使用单词组合标记或标记非结构化数据(文本数据)
【发布时间】:2014-06-03 11:50:08
【问题描述】:

我正在处理非结构化数据(文本)。 我想用一些关键词和关键词组合标记数据。

我无法使用单词组合标记数据。我想知道“欺诈”和“误卖”发生在哪里。

我尝试使用 qdap 包 我能够用 OR 条件而不是 AND 条件标记这两个词

下面是我使用的代码

library (qdap)

df<- read.csv (file.choose(),header=T) 

####cleaning of text
df$Comment<- strip(df$Comment)##remove capitalization and punctuation

df$Comment<- clean (df$Comment)
df$Comment<- scrubber(df$Comment)
df$Comment<- qprep(df$Comment)

df$Comment<-replace_abbreviation(df$Comment)

terms <- list(
    " fraud ",
    " refund "," cheat ", " cancellation ", "missold", "delay",
      combo1= qcv(fraud,missold) )

df2<-with (df, termco(df$Comment, df$Comment, terms))[["raw"]]###tagging of data with key words
df3<- merge (df, df2, by="Comment")

我正在使用保险公司的投诉数据 我的变量是

  1. 投诉日期
  2. 品牌反对者抱怨
  3. 评论(投诉)

【问题讨论】:

  • grep(paste(terms, collapse="|"), df$Comment) 中的正则表达式呢?
  • 嗨,lukeA,我想将这些关键词和组合(所有这些都说欺诈和错售一起)标记回数据文件,以便我可以分析这些案例的概况
  • 对不起,我不明白。请提供示例数据并显示结果应该是什么样子。
  • 并且在示例输出中,我想要新列,其中包含发生这些组合的每一行的标签dl.dropboxusercontent.com/u/46021747/sample%20output.xlsx

标签: r text mining


【解决方案1】:

根据您的示例 xlsx:

library(xlsx)
df <- read.xlsx(file="sample output.xlsx", sheetIndex=1)
library(tm)
terms <- stemDocument(c("fraud","refund","cheat", "cancellation", "misselling", "delay"))
mat <- DocumentTermMatrix(x=Corpus(VectorSource(df$Comment)), 
                          control=list(removePunctuation = TRUE,
                                       dictionary = terms, 
                                       stemming = TRUE,
                                       weighting = weightBin))
df2 <- as.data.frame(as.matrix(mat)) 
(df2 <- transform(df2, combo = fraud + missel))
df2
#   cancel cheat delay fraud missel refund combo
# 1      1     0     0     1      1      0     2
# 2      1     0     0     1      1      0     2
# 3      0     0     0     1      1      0     2
df3 <- cbind(df, df2)
df3

【讨论】:

  • 感谢lukeA,但我得到了相同的结果。数据再次被标记为 OR 条件,我希望所有那些欺诈和误卖都出现在同一文本中的案例
  • ...这就是combo 列的内容。您还可以使用嵌套的正则表达式搜索,例如 grep("mis.?sel", grep("fraud", df$Comment, ignore.case=T, value=T), ignore.case=T)
猜你喜欢
  • 1970-01-01
  • 2021-12-02
  • 2011-06-26
  • 2017-09-02
  • 2015-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多