[英]Phrase match in a sentence using R
我需要使用 R 匹配句子中的多个短语并将其保存在旁边的列中。 示例:
sentence <- c("My CPU is working but keyboard is not working", "unable
access printer", "unable access printer and keyboard is not working")
phrase <- c("unable access printer", "keyboard is not working")
我希望我的输出采用以下数据帧格式:
sentence phrase1 phrase2
My CPU is working but keyboard is not working keyboard is not working NA
unable access printer NA NA
unable access printer and keyboard is not working unable access printer keyboard is not working
请您指导我使用方法或 R 代码。 谢谢!
library(quanteda)
library(foreach)
library(data.table)
corp = corpus(sentence)
find.phrases = foreach(i = 1:length(phrase)) %do% {
kwic(corp, phrase[i])
}
find.df = rbindlist(find.phrases)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.