Reference Resolution API
Status: Generated from current Python docstrings and type hints.
Reference extraction, resolution, loading, and collision checks.
gaia.engine.lang.refs
Gaia reference extraction, resolution, and loading.
Public API
- extract(text) -> ExtractionResult
- resolve(key, label_table, references) -> RefKind
- check_collisions(label_table, references) -> None
- validate_groups(groups, markers, label_table, references) -> None
- load_references(path) -> dict[str, dict]
- RefKind, RefMarker, BracketGroup, ExtractionResult, ReferenceError
ReferenceError
ReferenceError(message: str, *, location: str | None = None)
Bases: Exception
Base error for reference handling.
Raised from extractor, resolver, loader for any structural or semantic failure. Compile turns these into hard errors.
Create a reference error with an optional location prefix.
Source code in gaia/engine/lang/refs/errors.py
13 14 15 16 17 18 19 | |
BracketGroup
dataclass
BracketGroup(raw: str, start: int, end: int, marker_indices: tuple[int, ...])
A complete [...] Pandoc citation group containing one or more refs.
Attributes:
| Name | Type | Description |
|---|---|---|
raw |
str
|
Full bracket group text including the brackets (for error messages). |
start |
int
|
Character offset in source text (position of |
end |
int
|
Character offset (exclusive; position after |
marker_indices |
tuple[int, ...]
|
Indices into |
ExtractionResult
dataclass
ExtractionResult(markers: tuple[RefMarker, ...], groups: tuple[BracketGroup, ...])
Result of scanning a piece of text for reference markers.
Attributes:
| Name | Type | Description |
|---|---|---|
markers |
tuple[RefMarker, ...]
|
All extracted markers, in source order. Includes both bracketed (strict) and bare (opportunistic) markers. |
groups |
tuple[BracketGroup, ...]
|
All bracket groups detected, in source order. |
RefMarker
dataclass
RefMarker(key: str, start: int, end: int, strict: bool, group_index: int | None = None)
A single @key reference marker extracted from text.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
The identifier after |
start |
int
|
Character offset in source text. |
end |
int
|
Character offset (exclusive). |
strict |
bool
|
True if inside a |
group_index |
int | None
|
Index into the parent |
extract
extract(text: str) -> ExtractionResult
Scan text for reference markers, returning bracket groups and bare markers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The source text to scan for markers. |
required |
Returns:
| Type | Description |
|---|---|
ExtractionResult
|
ExtractionResult containing: |
ExtractionResult
|
|
ExtractionResult
|
|
Group membership is tracked by marker identity during Pass 1, then converted to final list indices AFTER the markers list is sorted. This makes the group indices robust to the sort step even when bare markers appear before or between bracket groups.
Source code in gaia/engine/lang/refs/extractor.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
load_references
load_references(path: Path) -> dict[str, dict[str, Any]]
Load and validate a references.json file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to references.json. If missing, returns an empty dict. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
dict mapping citation key → CSL-JSON entry. |
Raises:
| Type | Description |
|---|---|
ReferenceError
|
on invalid JSON, wrong top-level type, or any entry that fails schema validation. |
Source code in gaia/engine/lang/refs/loader.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
check_collisions
check_collisions(label_table: dict[str, Any], references: dict[str, Any]) -> None
Fail fast if any key appears in both the label table and references.
Raises:
| Type | Description |
|---|---|
ReferenceError
|
listing all colliding keys. |
Per spec §3.5, collision is a compile error — never a warning — to prevent silent semantic drift when a bibliography is imported.
Source code in gaia/engine/lang/refs/resolver.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
resolve
resolve(key: str, label_table: dict[str, Any], references: dict[str, Any]) -> RefKind
Resolve a single reference key.
Must only be called after check_collisions has passed, which guarantees
a key is in at most one table.
Source code in gaia/engine/lang/refs/resolver.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
validate_groups
validate_groups(groups: Iterable[BracketGroup], markers: tuple[RefMarker, ...] | list[RefMarker], label_table: dict[str, Any], references: dict[str, Any]) -> None
Enforce the homogeneous-group rule (spec §3.2).
A [...] group must contain only knowledge refs or only citations.
Mixing them in one group is a compile error because the rendering
pipeline cannot faithfully process mixed Pandoc groups through
citeproc-py.
Unknown keys are NOT flagged here — they have their own disposition (strict → error at marker level; opportunistic → literal). This function only fires on the specific knowledge+citation mix.
Raises:
| Type | Description |
|---|---|
ReferenceError
|
on the first mixed group encountered, listing which keys are knowledge and which are citations. |
Source code in gaia/engine/lang/refs/resolver.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |