This commit is contained in:
25
docs/snippets/r/plugins/plugin_extractor.md
Normal file
25
docs/snippets/r/plugins/plugin_extractor.md
Normal file
@@ -0,0 +1,25 @@
|
||||
<!-- snippet:syntax-only -->
|
||||
|
||||
```r title="R"
|
||||
library(kreuzberg)
|
||||
|
||||
custom_json_extractor <- function(path, mime_type) {
|
||||
raw <- readLines(path, warn = FALSE)
|
||||
parsed <- jsonlite::fromJSON(paste(raw, collapse = "\n"))
|
||||
|
||||
text <- paste(unlist(parsed), collapse = "\n")
|
||||
|
||||
return(list(
|
||||
content = text,
|
||||
mime_type = "application/json",
|
||||
pages = 1L,
|
||||
metadata = list(extractor = "custom-json-extractor")
|
||||
))
|
||||
}
|
||||
|
||||
register_document_extractor("custom-json-extractor", custom_json_extractor)
|
||||
|
||||
result <- extract_file_sync("data.json", "application/json", NULL)
|
||||
|
||||
cat(sprintf("Extracted %d characters from JSON\n", nchar(result$content)))
|
||||
```
|
||||
Reference in New Issue
Block a user