【发布时间】:2019-05-07 16:40:38
【问题描述】:
我有一些经过 OCR 处理的文本。 OCR 放置了很多换行符 (\n),它们不应该是。但也错过了很多应该在那里的新线路。
我想删除现有的换行符并用空格替换它们。然后用原始文本中的换行符替换特定字符。然后将文档转换为 quanteda 中的语料库。
我可以创建一个基本的语料库。但问题是我不能把它分成几段。如果我使用
corpus_reshape(corps, to ="paragraphs", use_docvars = TRUE)
它不会分解文档。
如果我使用 corpus_segment(corps, pattern = "\n")
我收到一个错误。
rm(list=ls(all=TRUE))
library(quanteda)
library(readtext)
# Here is a sample Text
sample <- "Hello my name is Christ-
ina. 50 Sometimes we get some we-
irdness
Hello my name is Michael,
sometimes we get some weird,
and odd, results-- 50 I want to replace the
50s
"
# Removing the existing breaks
sample <- gsub("\n", " ", sample)
sample <- gsub(" {2,}", " ", sample)
# Adding new breaks
sample <- gsub("50", "\n", sample)
# I can create a corpus
corps <- corpus(sample, compress = FALSE)
summary(corps, 1)
# But I can't change to paragraphs
corp_para <- corpus_reshape(corps, to ="paragraphs", use_docvars = TRUE)
summary(corp_para, 1)
# But I can't change to paragraphs
corp_para <- corpus_reshape(corps, to ="paragraphs", use_docvars = TRUE)
summary(corp_para, 1)
corp_segmented <- corpus_segment(corps, pattern = "\n")
# The \n characters are in both documents....
corp_para$documents$texts
sample
【问题讨论】: