Skip to content

stanford-policylab/blind-charging

Repository files navigation

Blind Charging

Python Tests Python Lint Python Coverage

Installation

The redaction algorithm can be installed using pip with the following command:

pip install blind_charging

Basic Usage

The simplest usage of the blind charging algorithm looks like this:

import blind_charging as bc

# Configure BlindCharging to use your locale.
bc.set_locale("Suffix County")

# Run the redaction algorithm passing in:
#   1) The input police narrative text;
#   2) A list of civilian (non-peace-officer) names referenced in the narrative;
#   3) A list of names of peace officers referenced in the narrative.
#
# This returns the redacted input narrative.
civilians = ["Sally Smith"]
officers = ["Sgt. John Jones"]
narrative = "Sgt. John Jones arrested Sally Smith (S1) in Parkside."
bc.redact(narrative, civilians, officers)
# '<Sergeant #1> arrested <(S1)> in <[neighborhood]>.'

Locales

TODO(jnu): I'll add details about how to create and deploy the app with new locales. Currently the locales for our pilot live in a separate (private) repo.

Advanced Usage

Generating annotations for custom display

The basic redact function applies redactions and returns the modified text. If you would like to apply the redactions yourself (e.g., to present the report with stylized HTML formatting), you can run:

annotations = bc.annotate(narrative, civilians, officers)

The annotations give character offsets within the text where the annotation should be applied, as well as additional semantic information you can use to annotate the text.

Development

We use:

  • Python3 -- we target compatibility for all versions of Python starting with 3.8. (If we want to support Py3.7 we will need to downgrade Pandas, and probably other things.)
  • poetry for managing packages and building the library
  • pytest for testing
  • pre-commit for running formatters and linters
  • black for code formatting
  • isort for more code formatting
  • flake8 for linting

Getting started

  • Ensure you have Python3 on your computer.
  • Install poetry if needed
  • poetry install --with dev to install dependencies
  • poetry run pre-commit install to install git pre-commit hooks

Running tests

Run all tests with pytest:

poetry run pytest

Building the library

TKTK workflow for automating this. pytest build works in the meantime.

Contributors

This project was initially developed by a team at the Stanford Computational Policy Lab, including (in alphabetical order):

  • Alex Chohlas-Wood
  • Madison Coots
  • Sharad Goel
  • Amelia Goodman
  • Zhiyuan Jerry Lin
  • Joe Nudell
  • Julian Nyarko
  • Keniel Yao

About

Public repo for race-blind charging algorithm.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages