Philippine statutory law pattern matching and unit retrieval.
Project description
statute-utils
Philippine statutory law pattern matching and unit retrieval; utilized in LawSQL dataset.
Documentation
See documentation.
Development
Checkout code, create a new virtual environment:
poetry add statute-utils # python -m pip install statute-utils
poetry update # install dependencies
poetry shell
Some unit patterns
{
"units": [
{
"item": "Container 1",
"content": "Appropriation laws are excluded.",
}
]
}
UNITS_NONE = [
{
"item": "Container 1",
"content": "Individual provisions not detected.",
}
]
Use in Datasette
Add units to a database from a pre-made file
Consider an example db.sqlite
:
>>> from sqlite_utils import Database
>>> from statute_utils import Statute
>>> f = Path().joinpath(path-to-file.yml)
>>> db = Database('db.sqlite')
>>> db["statutes"].insert(Statute.from_file(f).make_row())
# this will contain an 'html' column containing a semantic tree structure that can be styled via css
Copy html/css files
are found in statute_utils/templates/statute.html
.
The present module has a directory for statute_utils/templates/
:
It contains:
tree.html
- Tree-building macros (which can be used for creating an html tree to represent the statute)tree.css
- Sample css rulesets to use for the tree generated with the macros
Copy files to the Jinja environment where these can be reused:
- /app
--|
|--/static
|--tree.css # copy it here
|--/templates
|--tree.html # copy it here
|--db.sqlite
When datasette is served with:
datasette serve db.sqlite --template-dir=app/templates/ --static static:app/static
It becomes possible to import the macros file into a future files:
{% from 'tree.html' import create_branches %}
{{ create_branches(units|from_json) }} {# note that from_json is custom filter added in the Datasette environment as a one-off plugin}
Add filters / custom functions
Create a file in the plugins directory:
- /app
- /app
--|
|--/static
|--tree.css
|--/templates
|--tree.html
|--/plugins
|--tree.py # new
|--db.sqlite
When datasette is served with:
datasette serve db.sqlite --plugins-dir=app/plugins/ {# plus the other arguments #}...
It becomes possible to use custom functions and filters found in tree.py
likeso:
from datasette import hookimpl
from statute_utils.display import from_json, is_hidden, is_excluded, from_mp, try_short, set_mp_slug, is_par, md_to_html, build_branch, crumb, tree_helpers
@hookimpl
def prepare_jinja2_environment(env): # custom filters can be used in datasette pages
env.filters["from_json"] = from_json
env.filters["is_hidden"] = is_hidden
env.filters["is_excluded"] = is_excluded
env.filters["from_mp"] = from_mp
env.filters["try_short"] = try_short
env.filters["set_mp_slug"] = set_mp_slug
env.filters["is_par"] = is_par
env.filters["md_to_html"] = md_to_html
env.filters["crumb"] = crumb
@hookimpl
def prepare_connection(conn): # custom function can be used in sqlite
conn.create_function("build_branch", 1, build_branch)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for statute_utils-0.5.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88b51c47c737156e8c64b88106e1ff5d2d427e42fe6b69d82052a7dbcae97792 |
|
MD5 | d9d5e9ac061692b89f023b9c13f4d336 |
|
BLAKE2b-256 | 34a2544123927f8dc5bb7a7ed83442d09a5aa06adffd6aa5bcc9f8a481e81adc |