在我们的一项数字作业中,我要求我的学生阅读一篇文章并写下他们从该文章中学到的一些东西。 学生们被告知他们应该用自己的话来写作。 我也有理由期望复制和粘贴一段文本或全部文本被禁用。 但我错了。 我收到了超过 9000 条文本,其中许多看起来像是直接从数字作业中复制和粘贴的。有些人在标点符号和大小写方面存在一些差异,但我无法想象他们真的坐在那里并打印了文章的大部分内容。
我已经阅读了许多学生的作业,并尝试从复制和粘贴的条目与诚实的条目中识别出独特的特征,希望一些 R 函数可以帮助我检测。 然而,我并没有成功。为了演示,这是我编的一个例子。这些段落通常很长,在 300-800 个单词之间,我想知道是否有一种相对简单的方法来识别两个文本之间重叠的公共单词块。
text_1 <- "She grew up in the United States. Her father was..."
text_2 <- "I learned that she grew up in the united states.Her father was ..."
期望的结果:“她在美国长大。她的父亲是……”
期望的结果应该打印两个向量之间重叠的单词序列,大小写或空格差异并不重要
感谢您的阅读以及您可以分享的任何专业知识。
{stringdist}
包 来评估两个文本之间的“距离”,通常解释为您必须在字符串中修改的字符数,以便变得等于参考字符串。所以“朋友”和“友好”的差别是 2。
通过这种方式,您可以检查哪些文本与参考文本相比差异较小,这可能意味着它们是直接从源材料中复制的。
# https://github.com/markvanderloo/stringdist
install.packages('stringdist')
library(stringdist)
base_text <- "she grew up in the united states.Her father was"
text_1 <- "She grew up in the United States. Her father was"
text_2 <- "I learned that she grew up in the united states.Her father was"
text_3 <- "The main character was born in the USA, his father being"
text_4 <- "My favourite animals are raccoons, they are so silly and cute"
text_5 <- "I didn't understand this assignment so I'm just answering gibberish"
text_6 <- "she grew up in the united states.Her father was"
test_texts <- c(text_1, text_2, text_3, text_4, text_5, text_6)
# calculate string distance using default method
distances <- stringdist(base_text, test_texts)
# texts that are only x or less edits away from the original text
possible_copied_texts <- test_texts[distances <= 25]
possible_copied_texts
#[1] "She grew up in the United States. Her father was"
#[2] "I learned that she grew up in the united states.Her father was"
#[3] "she grew up in the united states.Her father was"