【问题标题】:Identifying synonymous rows of a text column in a dataframe using R使用 R 识别数据框中文本列的同义行
【发布时间】:2021-01-12 16:16:29
【问题描述】:

假设 ABC 是如下所示的数据框:

ABC <- data.frame(Column1 = c(1.222, 3.445, 5.621, 8.501, 9.302), 
                  Column2 = c(654231, 12347, -2365, 90000, 12897), 
                  Column3 = c('A1', 'B2', 'E3', 'C1', 'F5'), 
                  Column4 = c('I bought it', 'The flower has a beautiful fragrance', 'It was bought by me', 'I have bought it', 'The flower smells good'), 
                  Column5 = c('Good', 'Bad', 'Ok', 'Moderate', 'Perfect'))

我的目的是在 Column4 中找到同义字符串。在这种情况下,我买了它它是我买的我买了它是同义词或相似的字符串和花有一种美丽的香味花香传达相似的意思。

我在下面的帖子中尝试了IVR的方法,卡住了:Find similar texts based on paraphrase detection

当我运行 HLS.Extract 代码块时,我收到以下错误消息:

Error in strsplit(PlainTextDocument(synonyms(word)), ",") : non-character Argument

使用 as.character 也不能解决问题:

Syns = function(word){  
    word <- as.character(word) ###
    wl    =   gsub("(.*[[:space:]].*)","",      
                   gsub("^c\\(|[[:punct:]]+|^[[:space:]]+|[[:space:]]+$","",  
                        unlist(strsplit(PlainTextDocument(synonyms(word)),","))))
    wl = wl[wl!=""] 
    return(wl)     
  }  
  1. 出了什么问题?

  2. 有没有更好的方法使用 R 对其进行编码,并另外创建一个新列,例如数字 1 作为第一个同义字符串的条目,数字 2 作为下一组同义字符串的条目?

  3. 它是否适用于德语文本?

【问题讨论】:

    标签: r nlp text-mining sentence-similarity pattern-synonyms


    【解决方案1】:

    通过将PlainTextDocument(synonyms(word))设置为字符解决了问题,如下图:

    Syns = function(word){ 
        wl    =   gsub("(.*[[:space:]].*)","",      
                       gsub("^c\\(|[[:punct:]]+|^[[:space:]]+|[[:space:]]+$","",  
                            unlist(strsplit(as.character(PlainTextDocument(synonyms(word))),",")))) 
        wl = wl[wl!=""] 
        return(wl)     
      } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多