Reads a corpus object ({schema_version, id, records}) into a named
list. The file extension sets the format: JSON for .json and YAML
otherwise. The file is read by the rules that tf_read() follows, so an
unquoted keyword such as y or n stays a string, and a repeated
key, a YAML alias that names no node, an anchor given twice, a value tagged
!expr, which runs no code, a YAML document whose aliases expand it past
1,000,000 values and a document nested more than 64 levels deep are refused,
the first in the order tf_read() gives. A document that is not a mapping
stops with Corpus data must be a mapping. The records themselves are
checked by tf_litmap() and tf_landscape().
Examples
corpus <- list(
schema_version = "1.0", id = "demo-corpus",
records = list(
list(id = "w1", keywords = list("arousal", "threat")),
list(id = "w2", keywords = list("arousal", "threat"))
)
)
path <- tempfile(fileext = ".json")
jsonlite::write_json(corpus, path, auto_unbox = TRUE)
tf_read_corpus(path)
#> $schema_version
#> [1] "1.0"
#>
#> $id
#> [1] "demo-corpus"
#>
#> $records
#> $records[[1]]
#> $records[[1]]$id
#> [1] "w1"
#>
#> $records[[1]]$keywords
#> $records[[1]]$keywords[[1]]
#> [1] "arousal"
#>
#> $records[[1]]$keywords[[2]]
#> [1] "threat"
#>
#>
#>
#> $records[[2]]
#> $records[[2]]$id
#> [1] "w2"
#>
#> $records[[2]]$keywords
#> $records[[2]]$keywords[[1]]
#> [1] "arousal"
#>
#> $records[[2]]$keywords[[2]]
#> [1] "threat"
#>
#>
#>
#>