【发布时间】:2020-05-02 12:30:06
【问题描述】:
我有一个语料库。我想从这个语料库中随机提取段落。但是,随机化练习必须确保不能对具有特定字词的段落进行抽样。
这是一个例子:
txt <- c("PAGE 1. A single sentence. Short sentence. Three word sentence. \n\n Quarentine is hard",
"PAGE 2. Very short! Shorter.\n\n quarantine is very very hard",
"Very long sentence, with three parts, separated by commas. PAGE 3.\n\n quarantine it's good tough to focus on paper.",
"Fiscal policy is a bad thing. \n\n SO is a great place where skilled people solve coding problems.",
"Fiscal policy is not as good as people may think",
"Economics is fun. \n\n I prefer Macro.")
corp <- corpus(txt, docvars = data.frame(serial = 1:6))
没有任何限制地做它是直截了当的:
reshape = corpus_reshape(corp, "paragraphs")
sample = corpus_sample(reshape, 4)
# Result
[1] "Economics is fun." "Fiscal policy is not as good as people may think"
[3] "Fiscal policy is a bad thing." "Quarentine is hard"
如您所见,随机选择了包含财政政策的“段落”。我希望通过排除出现财政政策的段落/句子来对语料库进行抽样。
我可以在采样之前删除原始数据集中与这个词相关的句子吗?你会怎么做?
请注意,在真实数据集中,我需要排除包含不止一个或两个关键字的句子。所以,请提出一些可以轻松扩展为多个单词的内容。
非常感谢!
【问题讨论】:
标签: r dataframe dictionary corpus quanteda