Skip to content

API Reference parrot_tools.legal.wiki_store

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

parrot_tools.legal.wiki_store

View source

OntologyLegalWikiStore — read-only FEAT-450 wiki-namespace adapter (R16).

Exposes the legal ontology tenant (BOE norms graph, FEAT-449 Sprints 1 + 1.5/2) as a read-only wiki namespace: search_fts delegates to the declarative search_articles pattern (TASK-2494/2496), neighbors walks the modifica/deroga/pertenece_a typed edges, and search_vector returns [] by design (R14 — no vectors anywhere).

Never provisions: the factory/initialize() VERIFY the database and the articulo collection exist and raise FileNotFoundError when they do not (mirrors wiki/arango_store.py's read_only no-provision connect, :282-330), so an absent tenant surfaces as an "unbuilt" namespace (federation._skip_for), never a silently-provisioned empty database on someone else's server.

Class OntologyLegalWikiStore

Read-only BaseWikiStore adapter over the legal ontology tenant.

Write methods all raise NotImplementedError — this namespace is read-only by construction, not by convention. search_vector returns [] (never raises — a combined search must degrade silently to lexical, R14).

Parameter Type Default Description
arango_params dict[str, Any] Connection params for AsyncDB("arangodb", ...).
database str Target ArangoDB database name.
wiki_name str '' Wiki name recorded/used for tenant resolution.
read_only bool True Always effectively True for this adapter; kept as a constructor param for symmetry with the other backends.
store ArangoOntologyGraphStore | None None Test-injection seam — a pre-built ArangoOntologyGraphStore (or compatible double). When provided together with ctx, initialize() is a no-op (already "initialized").
ctx TenantContext | None None Test-injection seam — a pre-built TenantContext.

Method OntologyLegalWikiStore.factory

Construct the store (registered as the "ontology_legal" backend).

Deliberately SYNCHRONOUS and non-connecting (mirrors ArangoDBWikiStore.__init__): both create_wiki_store's and federation.open_namespace_store's dispatch call this without await. Verification (database + articulo collection existence, raising FileNotFoundError when absent) happens lazily on first use, in initialize() — the same deferred-connection contract every other backend follows here (a live network probe cannot run synchronously from a caller that is itself inside a running event loop).

factory(*, storage_dir: Any = None, wiki_name: str, database: str, arango_params: dict[str, Any], read_only: bool = True, **_: Any) -> OntologyLegalWikiStore

Parameter Type Default Description
storage_dir Any None Unused (server-hosted backend, no local dir).
wiki_name str Wiki name.
database str Target ArangoDB database name.
arango_params dict[str, Any] Connection params.
read_only bool True Accepted for signature symmetry; always read-only.
**_ Any {}

Returns: OntologyLegalWikiStore — The constructed (not-yet-connected) store.

Method OntologyLegalWikiStore.initialize

Connect and verify the plane exists — NEVER provisions.

initialize() -> None

Raises:

  • FileNotFoundError — The database or its articulo collection does not exist — the legal tenant was never built (classified as "unbuilt" by federation._skip_for).

Method OntologyLegalWikiStore.close

Close the underlying ArangoDB connection, if any.

close() -> None

Method OntologyLegalWikiStore.upsert_pages

upsert_pages(pages: list[Any]) -> int

Parameter Type Default Description
pages list[Any]

Returns: int

Method OntologyLegalWikiStore.add_edges

add_edges(edges: list[tuple]) -> int

Parameter Type Default Description
edges list[tuple]

Returns: int

Method OntologyLegalWikiStore.replace_source_slice

replace_source_slice(source_id: str, pages: list[Any], edges: list[tuple[str, str, str]] | None = None) -> dict[str, Any]

Parameter Type Default Description
source_id str
pages list[Any]
edges list[tuple[str, str, str]] | None None

Returns: dict[str, Any]

Method OntologyLegalWikiStore.delete_page

delete_page(concept_id: str) -> bool

Parameter Type Default Description
concept_id str

Returns: bool

Method OntologyLegalWikiStore.upsert_embedding

upsert_embedding(concept_id: str, vector: list[float], model: str = '') -> None

Parameter Type Default Description
concept_id str
vector list[float]
model str ''

Method OntologyLegalWikiStore.get_page

Fetch one article's in-force wording as of today.

get_page(concept_id: str, include_body: bool = True) -> dict[str, Any] | None

Parameter Type Default Description
concept_id str The articulo_key.
include_body bool True When False, the body field is omitted.

Returns: dict[str, Any] | None — The page dict, or None when the article doesn't exist or has no in-force wording today (e.g. repealed).

Method OntologyLegalWikiStore.list_pages

List page stubs (no bodies), optionally filtered by category.

list_pages(category: str | None = None, limit: int = 100, origin: list[str] | None = None) -> list[dict[str, Any]]

Parameter Type Default Description
category str | None None "articulo", "norma", or None (both).
limit int 100 Maximum rows returned (applied per category).
origin list[str] | None None Unused — the BOE corpus has no origin concept.

Returns: list[dict[str, Any]] — Stub dicts (no bodies).

Method OntologyLegalWikiStore.search_fts

Lexical search — delegates to the search_articles pattern.

search_fts(query: str, category: str | None = None, limit: int = 10) -> list[dict[str, Any]]

Parameter Type Default Description
query str Free-form query text.
category str | None None Accepted for interface parity; only "articulo" results exist, so any other value yields [].
limit int 10 Maximum results.

Returns: list[dict[str, Any]] — Stub dicts with the shared {concept_id, node_id, title, category, summary, source_id, token_count, score} shape.

Method OntologyLegalWikiStore.search_vector

Always [] — no vectors anywhere (R14). Never raises.

search_vector(embedding: list[float], limit: int = 10) -> list[dict[str, Any]]

Parameter Type Default Description
embedding list[float]
limit int 10

Returns: list[dict[str, Any]]

Method OntologyLegalWikiStore.neighbors

Walk the modifica/deroga/pertenece_a typed edges.

neighbors(concept_id: str, rel: str | None = None, direction: str = 'both') -> list[dict[str, Any]]

Parameter Type Default Description
concept_id str Seed node id (articulo_key or boe_id).
rel str | None None Optional exact edge-collection filter (one of the three names above); None walks all three.
direction str 'both' "out", "in", or "both".

Returns: list[dict[str, Any]] — {concept_id, rel, direction} stubs.

Method OntologyLegalWikiStore.dump_pages

Every article's in-force page, WITH bodies (export path).

dump_pages() -> list[dict[str, Any]]

Returns: list[dict[str, Any]]

Method OntologyLegalWikiStore.dump_edges

Every edge across all three typed edge collections (export path).

dump_edges() -> list[dict[str, Any]]

Returns: list[dict[str, Any]]

Method OntologyLegalWikiStore.stats

Counts: normas, articulos, total versions, in-force versions.

stats() -> dict[str, Any]

Returns: dict[str, Any]

Method OntologyLegalWikiStore.orphan_sources

orphan_sources() -> list[str]

Returns: list[str]

Method OntologyLegalWikiStore.broken_edges

broken_edges() -> list[dict[str, Any]]

Returns: list[dict[str, Any]]

Method OntologyLegalWikiStore.missing_bodies

missing_bodies() -> list[str]

Returns: list[str]

Alias search_articles

Re-exported from parrot_tools.legal.boe.queries.search_articles.

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