提取两个变量之间的完整文本

尼尚

我有一个包含 3 列的数据框,第一列包含两个人之间的聊天,第二列包含 agent_name,第三列包含客户名称。

第一列数据示例:

在此处输入图片说明

我已经提取了代理名称和客户名称并将其分配给变量,我想提取位于这两个变量之间的任何文本,可能有多个空格或不同的模式我想提取变量之间的完整文本。例如,在附加图像中,我有变量 a="armando r" 和变量 b="jane"

文本:

armando r armando r: hello im armando how can i help you today jane: hi i had a question about parental leave jane: can you tell me an overview of time we can take off and if we want to extend that time armando r: partner physicians may take up to days of parenting leave you are eligible to begin the leave days prior to your expected due date and then would have days left for bondingparenting leave if you would like to take additional time off then either vacation or leave without pay can be applied jane: got it during the days is that when we apply for disability with the state jane: or how do we get our salary armando r: typically partner physicians are not eligible for sdi benefits but you would be eligible for the compensation continuance program covers of monthly covered earnings prorated to work schedule armando r: there is a day waiting period as well during the first days partners may use accrued sick leave vacation or lwop jane: ok thank you how do we apply for that and when should we apply for the compensation continuance program jane: also do we have to use accrued sick leave vacation lwop during the day waiting period armando r: when is the expected due date jane: end of april armando r: i would recommend contacting the phr shared services department days prior to the expected due date and you can be connected to a leave coordinator jane: ok thank you armando r: your leave coordinator can provide a detailed overview of how the parenting leave program works armando r: is there anything else i can help you with armando r: thank you for your time today good bye
克里斯·鲁勒曼

使用面试伙伴的姓名作为模式输入并使用环视,您可以执行以下操作:

library(stringr)
names <- c("armando r", "jane")
str_extract_all(str, 
            paste("(?<=: )[\\w\\s]+(?= ", paste0("\\b(", paste(names, collapse = "|"), ")\\b|$"), ")", sep = ""))
[[1]]
 [1] "hello im armando how can i help you today"                                                                                                                                                                                                                                                         
 [2] "hi i had a question about parental leave"                                                                                                                                                                                                                                                          
 [3] "can you tell me an overview of time we can take off and if we want to extend that time"                                                                                                                                                                                                            
 [4] "partner physicians may take up to days of parenting leave you are eligible to begin the leave days prior to your expected due date and then would have days left for bondingparenting leave if you would like to take additional time off then either vacation or leave without pay can be applied"
 [5] "got it during the days is that when we apply for disability with the state"                                                                                                                                                                                                                        
 [6] "or how do we get our salary"                                                                                                                                                                                                                                                                       
 [7] "typically partner physicians are not eligible for sdi benefits but you would be eligible for the compensation continuance program covers of monthly covered earnings prorated to work schedule"                                                                                                    
 [8] "there is a day waiting period as well during the first days partners may use accrued sick leave vacation or lwop"                                                                                                                                                                                  
 [9] "ok thank you how do we apply for that and when should we apply for the compensation continuance program"                                                                                                                                                                                           
[10] "also do we have to use accrued sick leave vacation lwop during the day waiting period"                                                                                                                                                                                                             
[11] "when is the expected due date"                                                                                                                                                                                                                                                                     
[12] "end of april"                                                                                                                                                                                                                                                                                      
[13] "i would recommend contacting the phr shared services department days prior to the expected due date and you can be connected to a leave coordinator"                                                                                                                                               
[14] "ok thank you"                                                                                                                                                                                                                                                                                      
[15] "your leave coordinator can provide a detailed overview of how the parenting leave program works"                                                                                                                                                                                                   
[16] "is there anything else i can help you with"                                                                                                                                                                                                                                                        
[17] "thank you for your time today good bye"

编辑

如果您想分别拥有每个人的话语,您可以names使用其索引向量进行子集化例如,names[1]匹配armando r因此,以下摘录armando r的演讲:

str_extract_all(str, paste0("(?<=", names[1], ":\\s).*?(?=\\s*(?:", paste(names, collapse="|"), "):|$)"))
[[1]]
[1] "hello im armando how can i help you today"                                                                                                                                                                                                                                                         
[2] "partner physicians may take up to days of parenting leave you are eligible to begin the leave days prior to your expected due date and then would have days left for bondingparenting leave if you would like to take additional time off then either vacation or leave without pay can be applied"
[3] "typically partner physicians are not eligible for sdi benefits but you would be eligible for the compensation continuance program covers of monthly covered earnings prorated to work schedule"                                                                                                    
[4] "there is a day waiting period as well during the first days partners may use accrued sick leave vacation or lwop"                                                                                                                                                                                  
[5] "when is the expected due date"                                                                                                                                                                                                                                                                     
[6] "i would recommend contacting the phr shared services department days prior to the expected due date and you can be connected to a leave coordinator"                                                                                                                                               
[7] "your leave coordinator can provide a detailed overview of how the parenting leave program works"                                                                                                                                                                                                   
[8] "is there anything else i can help you with"                                                                                                                                                                                                                                                        
[9] "thank you for your time today good bye"

数据:

str <- "armando r armando r: hello im armando how can i help you today jane: hi i had a question about parental leave jane: can you tell me an overview of time we can take off and if we want to extend that time armando r: partner physicians may take up to days of parenting leave you are eligible to begin the leave days prior to your expected due date and then would have days left for bondingparenting leave if you would like to take additional time off then either vacation or leave without pay can be applied jane: got it during the days is that when we apply for disability with the state jane: or how do we get our salary armando r: typically partner physicians are not eligible for sdi benefits but you would be eligible for the compensation continuance program covers of monthly covered earnings prorated to work schedule armando r: there is a day waiting period as well during the first days partners may use accrued sick leave vacation or lwop jane: ok thank you how do we apply for that and when should we apply for the compensation continuance program jane: also do we have to use accrued sick leave vacation lwop during the day waiting period armando r: when is the expected due date jane: end of april armando r: i would recommend contacting the phr shared services department days prior to the expected due date and you can be connected to a leave coordinator jane: ok thank you armando r: your leave coordinator can provide a detailed overview of how the parenting leave program works armando r: is there anything else i can help you with armando r: thank you for your time today good bye"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章