Coder Social home page Coder Social logo

4ndygu / capstone Goto Github PK

View Code? Open in Web Editor NEW

This project forked from harvard-lil/capstone

0.0 2.0 0.0 236.69 MB

CAP database scripts.

License: MIT License

Python 46.08% HTML 5.62% CSS 0.31% PLpgSQL 0.40% JavaScript 33.03% Dockerfile 0.17% Vue 8.31% SCSS 6.08%

capstone's Introduction

Capstone

test status codecov

This is the source code for case.law, a website written by the Harvard Law School Library Innovation Lab to manage and serve court opinions. Other than several cases used for our automated testing, this repository does not contain case data. Case data may be obtained through the website.

Project Background

The Caselaw Access Project is a large-scale digitization project hosted by the Harvard Law School Library Innovation Lab. Visit case.law for more details.

The Data

  1. Format Documentation and Samples
  2. Obtaining Real Data
  3. Reporting Data Errors
  4. Errata

Format Documentation and Samples

The output of the project consists of page images, marked up case XML files, ALTO XML files, and METS XML files. This repository has a more detailed explanation of the format, and two volumes worth of sample data:

CAP Samples and Format Documentation

Obtaining Real Data

This data, with some temporary restrictions, is available to all. Please see our project site with more information about how to access the API, or get bulk access to the data:

https://case.law/

Reporting Data Errors

This is a living, breathing corpus of data. While we've taken great pains to ensure its accuracy and integrity, two large components of this project, namely OCR and human review, are utterly fallible. When we were designing Capstone, we knew that one of its primary functions would be to facilitate safe, accountable updates. If you find any errors in the data, we would be extraordinarily grateful for your taking a moment to create an issue in this GitHub repository's issue tracker to report it. If you notice a large pattern of problems that would be better fixed programmatically, or have a very large number of modifications, describe it in an issue. If we need more information, we'll ask. We'll close the issue when the issue has been corrected.

Errata

These are known issues โ€” there's no need to file an issue if you come across one of these.

  • Missing Judges Tag: In many volumes, elements which should have the tag name <judges> instead have the tag name <p>. We're working on this one.
  • Nominative Case Citations: In many cases that come from nominative volumes, the citation format is wrong. We hope to have this corrected soon.
  • Jurisdictions: Though the jurisdiction values in our API metadata entries are normalized, we have not propagated those changes to the XML.
  • Court Name: We've seen some inconsistencies in the court name. We're trying to get this normalized in the data, and we'll also publish a complete court name list when we're done.
  • OCR errors: There will be OCR errors on nearly every page. We're still trying to figure out how best to address this. If you've got some killer OCR correction strategies, get at us.

The Capstone Application

Capstone is a Django application with a PostgreSQL database which stores and manages the non-image data output of the CAP project. This includes:

  • Original XML data
  • Normalized metadata extracted from the XML
  • External metadata, such as the Reporter database
  • Changelog data, tracking changes and corrections

Installing Capstone and CAPAPI

Hosts Setup

Add the following to /etc/hosts:

127.0.0.1       case.test
127.0.0.1       api.case.test
127.0.0.1       cite.case.test

Docker Setup

We support local development via docker compose. Docker setup looks like this:

Using pull first will avoid rebuilding images locally:

$ docker-compose pull

Start docker:

$ docker-compose up -d

Set up databases:

$ docker-compose exec db psql --user=postgres -c "CREATE DATABASE capdb;"
$ docker-compose exec db psql --user=postgres -c "CREATE DATABASE capapi;"
$ docker-compose exec db psql --user=postgres -c "CREATE DATABASE cap_user_data;"

Log into web container:

$ docker-compose exec web bash
# 

From now on all commands starting with # are assumed to be run from within docker-compose exec web bash.

Load dev data:

# fab init_dev_db
# fab ingest_fixtures
# fab import_web_volumes

Run the dev server:

# fab run

Capstone should now be running at 127.0.0.1:8000.

If you are working on javascript files, frontend, use fab run_frontend:

# fab run_frontend

Administering and Developing Capstone

Testing

We use pytest for tests. Some notable flags:

Run all tests:

# pytest

Run one test:

# pytest -k test_name

Drop into pdb on test failure:

# pytest --pdb

Run tests in parallel for speed:

# pytest -n 2

Requirements

Top-level requirements are stored in requirements.in. After updating that file, you should run

# fab pip_compile

to freeze all subdependencies into requirements.txt.

To upgrade a single requirement to the latest version:

# fab pip_compile:"-P package_name"

Applying model changes

Use Django to apply migrations. After you change models.py:

# ./manage.py makemigrations

This will write a migration script to cap/migrations. Then apply:

# fab migrate

Stored Postgres functions

Some Capstone features depend on stored functions. See set_up_postgres.py for documentation.

Running Command Line Scripts

Command line scripts are defined in fabfile.py. You can list all available commands using fab -l, and run a command with fab command_name.

Local debugging tools

django-extensions is enabled by default, including the very handy ./manage.py shell_plus command.

django-debug-toolbar is not automatically enabled, but if you run pip install django-debug-toolbar it will be detected and enabled by settings_dev.py.

Model versioning

For database versioning we use the Postgres temporal tables approach inspired by SQL:2011's temporal databases.

See this blog post for an explanation of temporal tables and how to use them in Postgres.

We use django-simple-history to manage creation, migration, and querying of the historical tables.

Data is kept in sync through the temporal_tables Postgres extension and the triggers created in our scripts/set_up_postgres.py file.

Download real data locally

We store complete fixtures for about 1,000 cases in the case.law downloads section.

You can download and ingest all volume fixtures from that section with the command fab import_web_volumes, or ingest a single volume downloaded from that section with the command fab import_volume:some.zip.

Working with javascript

We use Vue CLI 3 to compile javascript files, so you can use modern javascript and it will be transpiled to support the browsers listed in package.json. New javascript entrypoints can be added to vue.config.js and included in templates with {% render_bundle %}.

To see javascript changes live, run the dev server with

# fab run_frontend

This will start yarn serve behind the scenes before calling fab run.

Elasticsearch

For local dev, Elasticsearch will automatically be started by docker-compose up -d. You can then run fab refresh_case_body_cache to populate CaseBodyCache for all cases, and fab rebuild_search_index to populate the search index.

For debugging, see settings.py.example for an example of how to log all requests to and from Elasticsearch.

It may also be useful to run Kibana to directly query Elasticsearch from a browser GUI:

$ brew install kibana
$ kibana -e http://127.0.0.1:9200

You can then go to Kibana -> Dev Tools to run any of the logged queries, or GET /_mapping to see the search indexes.

Code examples

We maintain a separate CAP examples repo for some ideas about using code to interact with CAP data.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.