Title: | Download and Process Public Domain Works from Project Gutenberg |
---|---|
Description: | Download and process public domain works in the Project Gutenberg collection <https://www.gutenberg.org/>. Includes metadata for all Project Gutenberg works, so that they can be searched and retrieved. |
Authors: | Jon Harmon [aut, cre] , Myfanwy Johnston [aut], Jordan Bradford [aut], David Robinson [aut, cph] |
Maintainer: | Jon Harmon <[email protected]> |
License: | GPL-2 |
Version: | 0.2.4.9000 |
Built: | 2024-11-13 20:17:14 UTC |
Source: | https://github.com/ropensci/gutenbergr |
Data frame with metadata about each author of a Project Gutenberg work. Although the Project Gutenberg raw data also includes metadata on contributors, editors, illustrators, etc., this dataset contains only people who have been the single author of at least one work.
gutenberg_authors
gutenberg_authors
A tbl_df (see tibble or dplyr) with one row for each author, with the columns
Unique identifier for the author that can be used to join with the gutenberg_metadata dataset
The agent_name
field from the original metadata
Alias
Year of birth
Year of death
Link to Wikipedia article on the author. If there are multiple, they are "|"-delimited
Character vector of aliases. If there are multiple, they are "/"-delimited
To find the date on which this metadata was last updated,
run attr(gutenberg_authors, "date_updated")
.
gutenberg_metadata, gutenberg_subjects
# date last updated attr(gutenberg_authors, "date_updated")
# date last updated attr(gutenberg_authors, "date_updated")
Download one or more works by their Project Gutenberg IDs into a data frame
with one row per line per work. This can be used to download a single work of
interest or multiple at a time. You can look up the Gutenberg IDs of a work
using gutenberg_works()
or the gutenberg_metadata dataset.
gutenberg_download( gutenberg_id, mirror = NULL, strip = TRUE, meta_fields = character(), verbose = TRUE )
gutenberg_download( gutenberg_id, mirror = NULL, strip = TRUE, meta_fields = character(), verbose = TRUE )
gutenberg_id |
A vector of Project Gutenberg IDs, or a data frame
containing a |
mirror |
A mirror URL to retrieve the books from. By default uses the
mirror from |
strip |
Whether to strip suspected headers and footers using
|
meta_fields |
Additional fields describing each book, such as |
verbose |
Whether to show messages about the Project Gutenberg mirror that was chosen |
A two column tbl_df
(see tibble::tibble()
) with one row for each
line of the text or texts, with columns
Integer column with the Project Gutenberg ID of each text
A character vector of lines of text
# download The Count of Monte Cristo gutenberg_download(1184) # download two books: Wuthering Heights and Jane Eyre books <- gutenberg_download(c(768, 1260), meta_fields = "title") books dplyr::count(books, title) # download all books from Jane Austen austen <- gutenberg_works(author == "Austen, Jane") |> gutenberg_download(meta_fields = "title") austen dplyr::count(austen, title)
# download The Count of Monte Cristo gutenberg_download(1184) # download two books: Wuthering Heights and Jane Eyre books <- gutenberg_download(c(768, 1260), meta_fields = "title") books dplyr::count(books, title) # download all books from Jane Austen austen <- gutenberg_works(author == "Austen, Jane") |> gutenberg_download(meta_fields = "title") austen dplyr::count(austen, title)
Get all mirror data from https://www.gutenberg.org/MIRRORS.ALL. This only includes mirrors reported to Project Gutenberg and verified to be relatively stable. For more information on mirroring and getting your own mirror listed, see https://www.gutenberg.org/help/mirroring.html.
gutenberg_get_all_mirrors()
gutenberg_get_all_mirrors()
A tbl_df of Project Gutenberg mirrors and related data
Continent where the mirror is located
Nation where the mirror is located
Location of the mirror
Provider of the mirror
URL of the mirror
Special notes
gutenberg_get_all_mirrors()
gutenberg_get_all_mirrors()
Get the recommended mirror for Gutenberg files and set the global
gutenberg_mirror
options.
gutenberg_get_mirror(verbose = TRUE)
gutenberg_get_mirror(verbose = TRUE)
verbose |
Whether to show messages about the Project Gutenberg mirror that was chosen |
A character vector with the url for the chosen mirror.
gutenberg_get_mirror()
gutenberg_get_mirror()
Data frame with metadata about the languages of each Project Gutenberg work.
gutenberg_languages
gutenberg_languages
A tbl_df (see tibble or dplyr) with one row for each author, with the columns
Unique identifier for the work that can be used to join with the gutenberg_metadata dataset
Language ISO 639 code. Two letter code if one exists, otherwise three letter.
Number of languages for this work.
To find the date on which this metadata was last updated,
run attr(gutenberg_languages, "date_updated")
.
gutenberg_metadata, gutenberg_subjects
# date last updated attr(gutenberg_languages, "date_updated")
# date last updated attr(gutenberg_languages, "date_updated")
Selected fields of metadata about each of the Project Gutenberg works. These
were collected using the gitenberg Python package, particularly the
pg_rdf_to_json
function.
gutenberg_metadata
gutenberg_metadata
A tbl_df (see tibble or dplyr) with one row for each work in Project Gutenberg and the following columns:
Numeric ID, used to retrieve works from Project Gutenberg
Title
Author, if a single one given. Given as last name first (e.g. "Doyle, Arthur Conan")
Project Gutenberg author ID
Language ISO 639 code, separated by / if multiple. Two letter code if one exists, otherwise three letter. See https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
Which collection or collections this is found in, separated by / if multiple
Generally one of three options: "Public domain in the USA." (the most common by far), "Copyrighted. Read the copyright notice inside this book for details.", or "None"
Whether there is a file containing digits followed by
.txt
in Project Gutenberg for this record (as opposed to, for
example, audiobooks). If not, cannot be retrieved with
gutenberg_download
To find the date on which this metadata was last updated, run
attr(gutenberg_metadata, "date_updated")
.
gutenberg_works, gutenberg_authors, gutenberg_subjects
library(dplyr) library(stringr) gutenberg_metadata gutenberg_metadata |> count(author, sort = TRUE) # look for Shakespeare, excluding collections (containing "Works") and # translations shakespeare_metadata <- gutenberg_metadata |> filter( author == "Shakespeare, William", language == "en", !str_detect(title, "Works"), has_text, !str_detect(rights, "Copyright") ) |> distinct(title) shakespeare_works <- gutenberg_download(shakespeare_metadata$gutenberg_id) # note that the gutenberg_works() function filters for English # non-copyrighted works and does de-duplication by default: shakespeare_metadata2 <- gutenberg_works( author == "Shakespeare, William", !str_detect(title, "Works") ) # date last updated attr(gutenberg_metadata, "date_updated")
library(dplyr) library(stringr) gutenberg_metadata gutenberg_metadata |> count(author, sort = TRUE) # look for Shakespeare, excluding collections (containing "Works") and # translations shakespeare_metadata <- gutenberg_metadata |> filter( author == "Shakespeare, William", language == "en", !str_detect(title, "Works"), has_text, !str_detect(rights, "Copyright") ) |> distinct(title) shakespeare_works <- gutenberg_download(shakespeare_metadata$gutenberg_id) # note that the gutenberg_works() function filters for English # non-copyrighted works and does de-duplication by default: shakespeare_metadata2 <- gutenberg_works( author == "Shakespeare, William", !str_detect(title, "Works") ) # date last updated attr(gutenberg_metadata, "date_updated")
Strip header and footer content from a Project Gutenberg book. This is based on some formatting guesses so it may not be perfect. It will also not strip tables of contents, prologues, or other text that appears at the start of a book.
gutenberg_strip(text)
gutenberg_strip(text)
text |
A character vector with lines of a book. |
A character vector with Project Gutenberg headers and footers removed
book <- gutenberg_works(title == "Pride and Prejudice") |> gutenberg_download(strip = FALSE) head(book$text, 10) tail(book$text, 10) text_stripped <- gutenberg_strip(book$text) head(text_stripped, 10) tail(text_stripped, 10)
book <- gutenberg_works(title == "Pride and Prejudice") |> gutenberg_download(strip = FALSE) head(book$text, 10) tail(book$text, 10) text_stripped <- gutenberg_strip(book$text) head(text_stripped, 10) tail(text_stripped, 10)
Gutenberg metadata about the subject of each work, particularly Library of Congress Classifications (lcc) and Library of Congress Subject Headings (lcsh).
gutenberg_subjects
gutenberg_subjects
A tbl_df (see tibble or dplyr) with one row for each pairing of work and subject, with columns:
ID describing a work that can be joined with gutenberg_metadata
Either "lcc" (Library of Congress Classification) or "lcsh" (Library of Congress Subject Headings)
Subject
Find more information about Library of Congress Categories here: https://www.loc.gov/catdir/cpso/lcco/, and about Library of Congress Subject Headings here: https://id.loc.gov/authorities/subjects.html.
To find the date on which this metadata was last updated,
run attr(gutenberg_subjects, "date_updated")
.
gutenberg_metadata, gutenberg_authors
library(dplyr) library(stringr) gutenberg_subjects |> filter(subject_type == "lcsh") |> count(subject, sort = TRUE) sherlock_holmes_subjects <- gutenberg_subjects |> filter(str_detect(subject, "Holmes, Sherlock")) sherlock_holmes_subjects sherlock_holmes_metadata <- gutenberg_works() |> filter(author == "Doyle, Arthur Conan") |> semi_join(sherlock_holmes_subjects, by = "gutenberg_id") sherlock_holmes_metadata holmes_books <- gutenberg_download(sherlock_holmes_metadata$gutenberg_id) holmes_books # date last updated attr(gutenberg_subjects, "date_updated")
library(dplyr) library(stringr) gutenberg_subjects |> filter(subject_type == "lcsh") |> count(subject, sort = TRUE) sherlock_holmes_subjects <- gutenberg_subjects |> filter(str_detect(subject, "Holmes, Sherlock")) sherlock_holmes_subjects sherlock_holmes_metadata <- gutenberg_works() |> filter(author == "Doyle, Arthur Conan") |> semi_join(sherlock_holmes_subjects, by = "gutenberg_id") sherlock_holmes_metadata holmes_books <- gutenberg_download(sherlock_holmes_metadata$gutenberg_id) holmes_books # date last updated attr(gutenberg_subjects, "date_updated")
Get a table of Gutenberg work metadata that has been filtered by some common (settable) defaults, along with the option to add additional filters. This function is for convenience when working with common conditions when pulling a set of books to analyze. For more detailed filtering of the entire Project Gutenberg metadata, use the gutenberg_metadata and related datasets.
gutenberg_works( ..., languages = "en", only_text = TRUE, rights = c("Public domain in the USA.", "None"), distinct = TRUE, all_languages = FALSE, only_languages = TRUE )
gutenberg_works( ..., languages = "en", only_text = TRUE, rights = c("Public domain in the USA.", "None"), distinct = TRUE, all_languages = FALSE, only_languages = TRUE )
... |
Additional filters, given as expressions using the variables in
the gutenberg_metadata dataset (e.g. |
languages |
Vector of languages to include |
only_text |
Whether the works must have Gutenberg text attached. Works
without text (e.g. audiobooks) cannot be downloaded with
|
rights |
Values to allow in the |
distinct |
Whether to return only one distinct combination of each title and gutenberg_author_id. If multiple occur (that fulfill the other conditions), it uses the one with the lowest ID |
all_languages |
Whether, if multiple languages are given, all of them
need to be present in a work. For example, if |
only_languages |
Whether to exclude works that have other languages
besides the ones provided. For example, whether to include |
By default, returns
English-language works
That are in text format in Gutenberg (as opposed to audio)
Whose text is not under copyright
At most one distinct field for each title/author pair
A tbl_df (see the tibble or dplyr packages) with one row for each work, in the same format as gutenberg_metadata.
library(dplyr) gutenberg_works() # filter conditions gutenberg_works(author == "Shakespeare, William") # language specifications gutenberg_works(languages = "es") |> count(language, sort = TRUE) gutenberg_works(languages = c("en", "es")) |> count(language, sort = TRUE) gutenberg_works(languages = c("en", "es"), all_languages = TRUE) |> count(language, sort = TRUE) gutenberg_works(languages = c("en", "es"), only_languages = FALSE) |> count(language, sort = TRUE)
library(dplyr) gutenberg_works() # filter conditions gutenberg_works(author == "Shakespeare, William") # language specifications gutenberg_works(languages = "es") |> count(language, sort = TRUE) gutenberg_works(languages = c("en", "es")) |> count(language, sort = TRUE) gutenberg_works(languages = c("en", "es"), all_languages = TRUE) |> count(language, sort = TRUE) gutenberg_works(languages = c("en", "es"), only_languages = FALSE) |> count(language, sort = TRUE)
A tibble of book text for two sample books, generated using
gutenberg_download()
.
sample_books
sample_books
A tbl_df (from tibble::tibble()
) with one row for each
line of text from each book, with columns:
Unique identifier for the work that can be used to join with the gutenberg_metadata dataset.
A character vector of lines of text.
The title of this work.
The author of this work.
This code was used to download the books:
gutenberg_download(c(109, 105), meta_fields = c("title", "author"))