【问题标题】:Parsing XML-TEI and transform to Corpus in R在 R 中解析 XML-TEI 并转换为语料库
【发布时间】:2021-03-10 18:47:11
【问题描述】:

我有三个 XML-TEI-P5 文件要转换成语料库(styloquantedatm 语料库最好)。由于我从未使用过 XML,我无法提取文本并删除所有注释......(并保留所有特殊字母,如 ä、ü 等) 这是我迄今为止最远的一次:

library(xml2)
library(XML)
A1 <- read_xml("http://www.deutschestextarchiv.de/book/download_xml/schlegel_athenaeum_1798")
doc1 <- xmlParse(A1)
root1 <- xmlRoot(doc1)
print(root1)

另一种使用stylo 的方法(相同的文档,但将其保存在本地):

Corpus_alle <- load.corpus.and.parse(files = "all", corpus.dir = "TexteXML", markup.type= "XML",
                  corpus.lang = "German", splitting.rule = NULL,
                  sample.size = 10000, sampling = "no.sampling",
                  sample.overlap = 0, number.of.samples = 1,
                  sampling.with.replacement = FALSE, features = "w", 
                  ngram.size = 1, preserve.case = FALSE,
                  encoding = "UTF-8")

【问题讨论】:

    标签: r xml parsing corpus


    【解决方案1】:

    我建议查看包 tei2r (https://rdrr.io/github/michaelgavin/tei2r/man/)。

    我创建了这个函数来将文本语料库加载到 R 中:

    read_tei <- function(folder) {
      list.files(folder, pattern = '\\.xml$', full.names = TRUE) %>%
        map_dfr(~.x %>% parseTEI(.,node = "THE_NODE_TO_FIND") %>%tibble())
    }
    
    texts <- read_tei("PATH/TO/FILES")
    

    要使此功能起作用,您必须输入您要查找的节点。 (可能是文本)并且您必须指定文件所在的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-21
      • 2021-10-29
      • 2015-05-12
      • 2021-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多