Database and search service for copyright records and renewals
 
 
Go to file
Mike Benowitz d8f676c88f SFR-479 Add Basic API
Add a basic `Flask` API that responds to queries for copyright data. This includes 5 basic endpoints:

- `/search/fulltext`: queries all text fields in the Registration and Renewal records
- `/search/registration/<regnum>`: queries the collection for a specific copyright registration by registration number
- `/search/renewal/<rennum>`: queries the collection for a specific copyright renewal by renewal number
- `/registration/<uuid>`: fetches a single registration record by internally assigned UUID
- `/registration/<uuid?`: fetches a single renewal record by internally assigned UUID

The api can be run with the standard `python -m flask run` from the root of the project and by default will run in `production` mode. To set `development` run `export FLASK_ENV=development` before starting the application.
2019-06-04 16:43:08 -04:00
api SFR-479 Add Basic API 2019-06-04 16:43:08 -04:00
helpers SFR-453 Initial Commit 2019-05-29 12:47:03 -04:00
model SFR-479 Update import structure to improve loading 2019-06-04 16:42:04 -04:00
.gitignore SFR-453 Initial Commit 2019-05-29 12:47:03 -04:00
README.md SFR-453 Initial Commit 2019-05-29 12:47:03 -04:00
builder.py SFR-453 Initial Commit 2019-05-29 12:47:03 -04:00
config.yaml-dist SFR-453 Initial Commit 2019-05-29 12:47:03 -04:00
esIndexer.py SFR-479 Add Claimants to ElasticSearch index 2019-06-04 16:40:22 -04:00
main.py SFR-453 Initial Commit 2019-05-29 12:47:03 -04:00
renBuilder.py SFR-453 Initial Commit 2019-05-29 12:47:03 -04:00
requirements.txt SFR-479 Add Basic API 2019-06-04 16:43:08 -04:00
sessionManager.py SFR-453 Initial Commit 2019-05-29 12:47:03 -04:00

README.md

Copyright Registrations and Renewals DB Maintenance Script

Introduction

This script creates and updates a database of copyright records, both original registrations and renewals, drawn from two projects supported by the NYPL to digitize and gather this source data. The goal of this project is to create a single source for all copyright information for works registered after 1922 and renewed before 1978 (see Duration of Copyright for more information). This should provide the connections between registrations and renewals and allow users to see the connections between related registrations and renewals.

The two projects that this data is drawn from are hosted on GitHub, more information about the source of data for these projects can be found in each repository:

Database

This script generates and updates a Postgresql database and ElasticSearch search layer. It scans the above repository for updated source files and inserts/updates the appropriate records, ensuring that the search layer is kept up to date following these changes.

Structure

The database is relatively simple but contains some complexities to describe the range of conditions that exist in the copyright data. The tables currently are:

  • cce The core table that contains one copyright entry per row, identified by a UUIDv4. This includes a title and other descriptive information
  • renewal The core table that contains one copyright renewal per row, identified by a UUIDv4 and a renewal number.
  • registration This table contains copyright registration numbers (e.g. A999999) and registration dates. There can be multiple registration numbers per entry and renewal.
  • volume Contains information describing the CCE volume that specific records were drawn from, including a URL where a digitized version of the volume can be found. This can be used to locate the original text of a copyright entry.
  • author The authors associated with a copyright entry. For each entry one author is designated as the primary author, generally drawn from the entry heading and used for lookup and sorting purposes
  • publisher The publishers associated with a copyright entry. Each entry is tagged with a boolean claimant field that designates if the publisher was the copyright claimant. These entries can overlap with the author table due to discrepancies in how data was entered.
  • lccn Normalized LCCN numbers associated with a copyright entry
  • renewal_claimant Claimants who have created a renewal record
  • xml The source XML string for copyright entries. This is stored in an XML field and can be queried with xpath. This table also stores successive versions of the source XML for each entry, allowing changes to be found./visualized.
  • error_cce Contains copyright entries that could not be properly parsed. These are stored to see if the issue lies in the parser or the source data.

Relationships

The primary relationships are between the registration table, entries and renewals. Through registration numbers and dates, connections can be found between entries and renewals. It should be noted that an individual entry can have multiple renewals and vice-versa, related through multiple registration numbers

ElasticSearch

The ElasticSearch instance is designed to provide a simple, lightweight search layer. The documents in the ElasticSearch do not contain a full set of metadata, simply enough to return results that can be fully realized with an additional query to the database.

The ES instance is comprised of two indexes. cce for entries and ccr for renewals. These indexes can be queried separately or together

Configuration

This script can be configured to run locally using the NYPL data sources or your own forks of these sources. A config.yaml-dist file is included here that contains the structure for the necessary environment variables. The following will need to be supplied:

  • Connection details for a PostgreSQL database
  • Connection details for an ElasticSearch instance
  • A GitHub Personal Access Token for interacting with the GitHub API
  • Repository names for the entry and renewal repositories

Setup

This script requires Python 3.6+

To create a local instance it is recommended to create a virtualenv and install dependencies with pip install -r requirements.txt

Running

The utility script can be invoked simply with python main.py to initialize the database and pull down the full set of source data. Please note that this will take 2-4 hours to fully download, parse and index the source data.

Several command-line arguments control the options for the execution of this script

  • --REINITIALIZE Will drop the existing database and rebuild it from scratch. WARNING THIS WILL DELETE ALL CURRENT DATA
  • -t or --time The time ago in seconds to check for updated records in the GitHub repositories. This allows for only updating changed records
  • -y or --year A specific year to load from either the entries or renewals
  • -x or --exclude Set to exclude either the entries (with cce) or the renewals (with ccr) from the current execution. Useful when used in conjunction with the year parameter to control what records are updated.