0

我正在从泰米尔语(印度当地语言)语言的 .pdf 文件中提取数据,从 pdf 文件中提取 R 中的文本后,我得到了一些垃圾或 unicode 字符格式的文本。我无法将其映射到正确的文本或与 pdf 文件中相同的文本,这是代码

library(tm)
library(pdftools)
library(qdapRegex)
library(stringr)
library(textreadr)

if(!require("ghit")){
  install.packages("ghit")
}
# on 64-bit Windows
ghit::install_github(c("ropenscilabs/tabulizerjars", "ropenscilabs/tabulizer"), INSTALL_opts = "--no-multiarch")
# elsewhere
ghit::install_github(c("ropenscilabs/tabulizerjars", "ropenscilabs/tabulizer"))
text <- extract_tables("D:/first.pdf")
 text[[1]][,2][3]

这给了我一些垃圾字符,比如

"«îù£ñ¢«ð좬ì  , âô¢ì£ñ¢ú¢ «ó£ Ì"

我尝试更改 unicode 类型

library(stringi)
stri_trans_toupper("ê¶ó®", locale = "Tamil")

但虽然没有成功。任何建议都将是可观的。

谢谢。

4

1 回答 1

2

如果您的文本已成功提取并且这是转换编码的唯一问题,我认为iconv函数有效。我提供了一个由“cp932”(东亚语言)编码的文本示例。

# text file written in cp932
x <- readLines("test-cp932.txt", encoding="utf-8")  

x
## [1] "\x82\xa0\x82肪\x82Ƃ\xa4"
# this is garbled because the file has been read
# in a wrong encoding

iconv(x, "cp932", "utf-8")
## [1] "ありがとう"
# this means 'thank you'

如果这不起作用,那么您的文本可能在解析过程中被污染了。

另一种可能性是将您的字符串变成原始对象(代码)并使用这样的代码映射重新格式化原始文本。

charToRaw(x)
##  [1] 82 a0 82 e8 82 aa 82 c6 82 a4
于 2017-09-16T13:32:33.137 回答