【问题标题】:Prevent tm from removing stopwords from double words防止 tm 从双字中删除停用词
【发布时间】:2017-08-18 06:04:46
【问题描述】:

我正在尝试从字符向量中删除停用词。但我面临的问题是有一个词“king kond”。由于“king”是停用词之一,“king kong”中的“king”正在被删除。

有没有办法避免双字被删除? 我的代码是:

text <- VCorpus(VectorSource(newmnt1$form)) 
#(newmnt1$form is  chr [1:4] "king kong lives" "foot" "island" "skull")

#Normal standardization of text.
text <- tm_map(text, content_transformer(tolower))
text <- tm_map(text, removeWords, custom_stopwords)
text <- tm_map(text, stripWhitespace)
newmnt2 <- text[[1]]$content

【问题讨论】:

    标签: r tm corpus stop-words


    【解决方案1】:

    一个快速的技巧是将您的“king kong”模式转换为“king_kong”。

    a <- gsub("king kong", "king_kong", "This is a pattern with king and king kong")
    a
    [1] "This is a pattern with king and king_kong"
    
    tm::removeWords(a, "king")
    [1] "This is a pattern with  and king_kong"
    

    最好的,

    科林

    【讨论】:

      【解决方案2】:

      如果您愿意使用其他软件包,这可行:

      > text <- c("king kong lives", "foot", "island", "skull", "This is a pattern with king and king kong")
      > corpus::term_matrix(text, drop = "king", combine = "king kong", transpose = TRUE)
      11 x 5 sparse Matrix of class "dgCMatrix"
      
      a         . . . . 1
      and       . . . . 1
      foot      . 1 . . .
      is        . . . . 1
      island    . . 1 . .
      king kong 1 . . . 1
      lives     1 . . . .
      pattern   . . . . 1
      skull     . . . 1 .
      this      . . . . 1
      with      . . . . 1
      

      combine 参数指示 corpusking kong 解释为单个标记。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-16
        • 2013-05-12
        • 1970-01-01
        相关资源
        最近更新 更多