匹配R/nlp/spacyr中的多个字符串



我有一个数据帧

myDataframe <- data.frame(keyword = c(c("meeting", "laptop"),c("attend a meeting", "fan")))
description <- "I have to attend a meeting."

我必须将描述与数据框架中的column关键字匹配,并返回"出席会议"。有没有办法得到一个特定的输出

使用grepl将返回myDataframe中包含description的关键字

myDataframe <- data.frame(keyword = c(c("meeting", "laptop"),c("attend a meeting", "fan")))
description <- "I have to attend a meeting."
found <- as.logical(lapply(myDataframe$keyword ,
function(x) grepl(x , description)))
myDataframe[found , ]
#> [1] "meeting"          "attend a meeting"

由reprex包(v2.0.1)创建于2022-06-02

相关内容

  • 没有找到相关文章

最新更新