【问题标题】:R text mining - intersection between text fields [closed]R文本挖掘 - 文本字段之间的交集[关闭]
【发布时间】:2015-01-13 19:33:46
【问题描述】:

我想知道是否有一种快速的方法可以找到 2 个文本字符串之间的定向交集,例如

 t1 <- "I have achieved my goals over the past 20 years and look forward for my next chalanges"
 t2 <- " have achieved goals and look my chalanges some other words bla bla"

t1 isContainedIn t2 将返回 7,因为在 t1 中出现的 7 个单词也在 t2 中出现。 此外,t1 和 t2 是数据框中的 2 列,因此我需要将该函数应用于整个数据框并将结果列附加到我的原始数据框。 这就是我的数据框“data.selected”的样子:

        keywords                                         title
1  Samsung UN48H6350 48" Samsung UN48H6350 48" Full 1080p Smart HDTV 120Hz with Wi-Fi +$50 Visa Gift Card
2  Samsung UN48H6350 48"     Samsung UN48H6350 48" Full HD Smart LED TV -Bundle- (See Below for Contents)
3  Samsung UN48H6350 48"      Samsung UN48H6350 48" Class Full HD Smart LED TV -BUNDLE- See below Details
4  Samsung UN48H6350 48"     Samsung UN48H6350 48" Full HD Smart LED TV With BD-H5100 Blu-ray Disc Player
5  Samsung UN48H6350 48"                 Samsung UN48H6350 48" Smart 1080p Clear Motion Rate 240 LED HDTV
6  Samsung UN48H6350 48"            Samsung UN48H6350 - 48-Inch Full HD 1080p Smart HDTV 120Hz with Wi-Fi
7  Samsung UN48H6350 48"               Samsung 6350 Series UN48H6350 48" 1080p HD LED LCD Internet TV NEW
8  Samsung UN48H6350 48"  Samsung Un48h6350af 75" 1080p Led-lcd Tv - 16:9 - Hdtv 1080p - (un75h6350afxza)
9  Samsung UN48H6350 48"                         Samsung UN48H6350 - 48" HD 1080p Smart HDTV 120Hz Bundle
10 Samsung UN48H6350 48"   Samsung UN48H6350 - 48-Inch Full HD 1080p Smart HDTV 120Hz with Wi-Fi, (R#416)

【问题讨论】:

    标签: r nlp intersection text-mining


    【解决方案1】:

    我想另一种类似的方法是使用简单的match

    string <- strsplit(c(t1, t2), "\\s+") # similar to @Richard
    length(na.omit(match(string[[2]], string[[1]])))
    ## [1] 7
    

    或者lapply

    length(unlist(lapply(string[[2]], intersect, string[[1]])))
    ## [1] 7
    

    【讨论】:

      【解决方案2】:

      我不太清楚你所说的方向很重要。除非您更改数据,否则交叉点的长度不应更改。这可能是您正在寻找的。

      length(Reduce(intersect, strsplit(c(t1, t2), "\\s+")))
      # [1] 7
      

      如果您将c(t1, t2) 切换到c(t2, t1),您可以看到Reduce 输出的差异。但正如我所说,长度仍然是一样的。只是集合的顺序不同。

      【讨论】:

      • 你是对的 - 交集不是正确的术语。我的意思是找出 t2 中包含多少 t1:在 t1 中出现了多少项,在 t2 中出现(反之亦然 - 方向很重要)
      • 另外 - t1 和 t2 是数据帧 - 我不确定这个解决方案是否支持这一点,因为当我在我的数据上运行它时,R 当前返回字符(0)
      • @user3628777 - 不,它没有。从一开始就拥有这些信息会很好。我会进行编辑,但我们需要知道:您到底在比较什么?关键字和标题?还请在问题中从更新的数据框中显示您想要的结果
      猜你喜欢
      • 2016-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-19
      • 2011-02-16
      • 2017-03-20
      • 1970-01-01
      • 2011-12-22
      相关资源
      最近更新 更多