【发布时间】:2021-05-31 06:52:24
【问题描述】:
我正在从大约 1000 个 pdf 文件中抓取文本数据。我设法将它们全部导入 R-studio,使用 str_subset 和 str_extract_all 获取我需要的较小属性。该项目的主要目标是抓取案例历史叙述数据。这些是自然语言的段落,以在所有单个文档中标准化的独特单词为界。请参阅下面的复制示例。
有没有一种方法可以使用这两个独特的词(“CASE HISTORY & INVESTIGATOR:”)来绑定我要提取的文本?如果不是,我可以采取哪种方法从每份报告中提取我需要的叙述性数据?
text_data <- list("ES SPRINGFEILD POLICE DE FARRELL #789\n NOTIFIED DATE TIME OFFICER\nMARITAL STATUS: UNKNOWN\nIDENTIFIED BY: H. POIROT AT: SCENE DATE: 01/02/1895\nFINGERPRINTS TAKEN BY DATE\n YES NO OBIWAN KENOBI 01/02/1895\n
SPRINGFEILD\n CASE#: 012-345-678\n ABC NOTIFIED: ABC DATE:\n ABC OFFICER: NATURE:\nCASE HISTORY\n This is a string. There are many strings like it, but this one is mine. To be more specific, this is string 456 out of 5000 strings. It’s a case narrative string and\n Case#: 012-345-678\n EXAMINER / INVESTIGATOR'S REPORT\n CITY AND COUNTY OF SPRINGFEILD - RECORD OF CASE\nit continues on another page. It’s 1 page but mostly but often more than 1, 2 even\n the next capitalized word, investigator with a colon, is a unique word where the string stops.\nINVESTIGATOR: HERCULE POIROT \n")
这是预期的输出。
output <- list("This is a string. There are many strings like it, but this one is mine. To be more specific, this is string 456 out of 5000 strings. It’s a case narrative string and\n Case#: 012-345-678\n EXAMINER / INVESTIGATOR'S REPORT\n CITY AND COUNTY OF SPRINGFEILD - RECORD OF CASE\nit continues on another page. It’s 1 page but mostly but often more than 1, 2 even\n the next capitalized word, investigator with a colon, is a unique word where the string stops.")
非常感谢您的帮助!
【问题讨论】:
-
请显示预期输出
-
@akrun - 编辑了帖子,但这是我需要的: output
标签: r text nlp tidyverse pdf-scraping