Skip to content

meronrudy/openlaw

Repository files navigation

OpenLaw Legal Reasoning (Native Engine — Default)

This repository provides a production-ready, legal reasoning stack centered on a deterministic Native Engine. It includes a native adapter/bridge for legal workloads, a jurisdiction-aware rule builder, authority multipliers, a document-to-graph ingestion CLI, GraphML fixtures, configuration bundles, CI with coverage gating, and comprehensive docs.

What’s new

Core implementation files

  1. Installation (Python 3.10 recommended)
python -m venv .venv
source .venv/bin/activate

# Core deps for native engine path
pip install -r requirements.txt

Optional (dev)

  • Parity tools and heavy extras are not required; the project operates native-first.
  • Add pytest-cov locally if you want coverage reports that match CI:
    • pip install pytest-cov
  1. Configuration (Native)

Primary config files:

Bridge constructor (strict mode)

from core.adapters.native_bridge import NativeLegalBridge

bridge = NativeLegalBridge(
    courts_cfg_path="config/courts.yaml",
    precedent_weights_cfg_path="config/precedent_weights.yaml",
    statutory_prefs_cfg_path="config/statutory_prefs.yaml",
    redaction_cfg_path="config/compliance/redaction_rules.yml",
    privacy_defaults=True,
    strict_mode=True,  # raise on invalid config
)
  1. Quick start (GraphML → reasoning → export)

Using example fixtures in examples/graphs:

  • friends_graph.graphml
  • group_chat_graph.graphml
from core.adapters.native_bridge import NativeLegalBridge

b = NativeLegalBridge(
    courts_cfg_path="config/courts.yaml",
    precedent_weights_cfg_path="config/precedent_weights.yaml",
    statutory_prefs_cfg_path="config/statutory_prefs.yaml",
    redaction_cfg_path="config/compliance/redaction_rules.yml",
    privacy_defaults=True,
)

g = b.load_graphml("examples/graphs/friends_graph.graphml", reverse=False)
facts_node, facts_edge, _, _ = b.parse_graph_attributes(static_facts=True)

rules = b.build_rules_for_claim(
    claim="breach_of_contract",
    jurisdiction="US-CA",
    use_conservative=False,
)

interp = b.run_reasoning(
    graph=g, facts_node=facts_node, facts_edge=facts_edge, rules=rules, tmax=1
)

# Privacy-aware export (facts only by default profile)
out = b.export_interpretation(interp, profile="default_profile")
print(out["facts"])
  1. Document ingestion CLI (doc → GraphML)

Convert raw text to a GraphML legal graph using NLP (auto) or regex-only (no NLP):

# Auto mode (NER + citations if available)
python -m scripts.ingest.doc_to_graph_cli ./my_case.txt -o examples/graphs/generated_case.graphml --mode auto --jurisdiction US-CA --default-year 2020

# Regex-only mode (always available)
python -m scripts.ingest.doc_to_graph_cli ./my_case.txt -o examples/graphs/generated_case.graphml --mode regex

Key ingestion functions:

  1. Authority multipliers (how it works)

At build-time, if you do not explicitly pass clause weights, the bridge computes multipliers:

  • _compute_authority_multipliers():
    • Treatment modifier: e.g., followed/criticized/overruled weights
    • Recency decay: exponential half-life with a floor
    • Jurisdiction alignment: exact/ancestor/sibling/foreign
    • Court level weights: e.g., US_SCOTUS=1.0, STATE_TRIAL ~0.78
  • Applied to the top-level support rule weights in:

You can still pass explicit weights to override.

  1. Aggregators and legal styles

Aggregators (registered in ANNOTATION_REGISTRY):

Interpretation styles (weight tuning):

  1. Privacy and compliance
  1. CI (coverage gating, native-first)
  1. Examples and benchmarks
  1. Troubleshooting and docs

License

  • OpenLaw code under repository license terms.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published