ontocast.stategraph.helpers¶
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
Functions:¶
all_unit_patch_source_iris(state)
¶
Sorted unique ontology IRIs appearing in any unit's patch source list.
Source code in ontocast/stategraph/helpers.py
build_document_excerpt(state)
¶
Create a representative excerpt from sampled source units.
Samples by position among the units routed to extraction: a reference list or an author block kept under its own route would otherwise stand in for the document whenever it is the last unit. Falls back to every unit when none is plain content.
Source code in ontocast/stategraph/helpers.py
build_document_text(state, max_chars)
¶
The document's content units, in order, within max_chars.
Every unit keeps its opening: once the whole text exceeds the budget, each unit is cut to the same share of its length. Units routed away from extraction (a reference list, an author block) are left out unless no unit is plain content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
AgentState
|
The document state. |
required |
max_chars
|
int
|
Character budget for the joined text. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The units' texts joined by blank lines, or the excerpt when no unit |
str
|
has text. |
Source code in ontocast/stategraph/helpers.py
drop_all_deletes(delta)
¶
Empty the delete side of delta (ONTOLOGY_UPDATE_MODE=insert_only).
The render path already drops rendered deletes; this guards the apply step against a delete reaching it from any other path.
Returns:
| Type | Description |
|---|---|
int
|
Number of delete triples dropped. |
Source code in ontocast/stategraph/helpers.py
enforce_redeclared_deletes(delta, judged_on_partial_view)
¶
Drop deletes judged on a partial view whose subject is not redeclared.
A unit whose context was a retrieved subset of the catalog
(:attr:OntologySnapshot.partial) judged its deletes without seeing the
rest of the ontology, so such a delete is trusted only as part of a
redeclaration: the corrected statement's subject must reappear in the
document's merged inserts. A bare delete of catalog content, judged on
partial evidence, would propagate onto shared catalog terminals across
documents. Deletes from units that saw their ontologies whole are not
touched. A unit can never delete a statement it was not shown: its deletes
are the snapshot triples its updates removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta
|
OntologyDelta
|
The merged document delta, edited in place. |
required |
judged_on_partial_view
|
RDFGraph
|
The deletes proposed by units with a partial view. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of delete triples dropped. |
Source code in ontocast/stategraph/helpers.py
merge_unit_deltas(deltas)
¶
Union per-unit deltas into one document-level delta.
Delete consensus across parallel units is conservative: a triple inserted by any unit wins over another unit's delete of the same triple, so the merged delta stays monotone-safe under parallel map/reduce.
Source code in ontocast/stategraph/helpers.py
reconcile_fresh_ontologies(fresh_ontologies)
¶
Union the fresh fan-out's per-unit graphs into one root per IRI.
Every fresh unit of a document mints under the document's home ontology, so there is one IRI and the union is the ontology. A unit that minted under any other IRI is a fault in the fresh path and raises.
Returns:
| Type | Description |
|---|---|
list[Ontology]
|
The reconciled artifact list and the metrics to record |
dict[str, int]
|
( |