Skip to content

API Reference parrot_tools.legal.boe.queries

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.legal.boe.queries

View source

Typed wrappers around the declarative traversal patterns (article_in_force, search_articles).

The resolution logic — which wording was in force on a given date, and the lexical-candidate BM25 search — lives entirely in the AQL query_templates declared in legal.ontology.yaml (TASK-2371, TASK-2494). This module is pure ergonomics: binding, calling ArangoOntologyGraphStore.execute_pattern, and deserialising the result. It does not re-implement version selection in Python — that would duplicate the pattern and violate spec goal G4 (declarative-first temporal resolution). search_articles additionally applies a Python-side token-containment guard (FEAT-449 §3 M5) — NOT a re-selection of versions, only a check that the query is actually about the in-force wording the AQL already selected.

Alias ArticleHit

Re-exported from parrot_tools.legal.boe.models.ArticleHit.

Alias ArticleVersion

Re-exported from parrot_tools.legal.boe.models.ArticleVersion.

Function article_in_force

Resolve the wording of an article in force on a given date.

Reads the article_in_force AQL template from ctx.ontology.traversal_patterns (never inlined here), binds articulo_key, as_of and the @articulo collection, and deserialises the single matching version.

article_in_force(store: ArangoOntologyGraphStore, ctx: TenantContext, articulo_key: str, as_of: date) -> ArticleVersion | None

Parameter Type Default Description
store ArangoOntologyGraphStore The ArangoOntologyGraphStore to execute the traversal against.
ctx TenantContext Tenant context carrying the merged ontology and its traversal patterns.
articulo_key str The composite articulo key ({boe_id}:{numero}) to resolve.
as_of date The date to resolve the wording for.

Returns: ArticleVersion | None — The ArticleVersion in force on as_of, or None when no version was in force on that date (e.g. as_of precedes the article's earliest version) — a legitimate "no law applied on that date" answer, not an error.

Raises:

  • KeyError — If the article_in_force traversal pattern is not declared in ctx.ontology — a configuration bug worth failing loudly on.

Function passes_token_guard

The load-bearing temporal check applied AFTER the AQL (spec §3 M5).

SEARCH matches at DOCUMENT level (any version's text can match); this guard drops a candidate whose lexical match lives only in a superseded wording by checking that at least one query token is a substring of the FOLDED in-force version's text. If the query yields zero tokens of length >= 4 (short/stopword-only query), the guard is skipped (every candidate passes).

passes_token_guard(query: str, text: str | None) -> bool

Parameter Type Default Description
query str The raw user query.
text str | None The in-force version's text to check against (may be None for a supresion version).

Returns: bool — True when the candidate should be kept.

Function search_articles

Lexical candidate search over article wordings + in-force resolution.

Reads the search_articles AQL template from ctx.ontology.traversal_patterns (never inlined here), executes it via store.execute_pattern (no collection_binds — the view name is a literal in the template, never a bind var), then applies the token-containment guard in Python to drop any hit whose lexical match lives only in a superseded wording (the AQL's temporal FILTER already selects the in-force version; the guard only checks that the query is actually about THAT wording, not a repealed one that happened to match at the SEARCH stage).

search_articles(store: ArangoOntologyGraphStore, ctx: TenantContext, query: str, as_of: date, limit: int = 20) -> list[ArticleHit]

Parameter Type Default Description
store ArangoOntologyGraphStore The ArangoOntologyGraphStore to execute the traversal against.
ctx TenantContext Tenant context carrying the merged ontology and its traversal patterns.
query str The user's lexical query.
as_of date The date to resolve in-force versions for.
limit int 20 Maximum number of BM25 candidates to fetch.

Returns: list[ArticleHit] — Hits in the AQL's BM25 order (never re-sorted in Python), filtered by the token-containment guard.

Raises:

  • KeyError — If the search_articles traversal pattern is not declared in ctx.ontology — a configuration bug worth failing loudly on.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally