ontocast.tool.ontology_validation.consolidate¶
Compile term actions into a graph patch, deterministically.
Consolidation (per document) and curation (per catalog) ask a model for one action per minted term; this module is the only place those actions become triples. A model never writes a triple here, so a bad answer can at worst be ignored, and every action is checked before it is applied:
- the term must be a minted term the caller listed -- a catalog term's own axioms are never edited;
- a
merge_into/generalise_totarget must be a listed minted term, a catalog term or a well-known term of compatible role, and a merge chain must end at a term that survives; demote_to_property_valueapplies to classes only.
An invalid action falls back to the term's default: keep, or drop for a
candidate (a term the document plan did not name).
Attributes¶
TermFlags = dict[str, dict[str, tuple[str, ...]]]
module-attribute
¶
__all__ = ['CompiledActions', 'ResolvedAction', 'compile_actions', 'resolve_actions', 'TermFlags', 'add_flag', 'structural_flags']
module-attribute
¶
Classes¶
CompiledActions
¶
Bases: BaseModel
What a set of term actions does to one graph.
Source code in ontocast/tool/ontology_validation/consolidate.py
Attributes¶
decided = Field(default_factory=dict)
class-attribute
instance-attribute
¶
deletes = Field(default_factory=RDFGraph)
class-attribute
instance-attribute
¶
ignored = Field(default_factory=list)
class-attribute
instance-attribute
¶
inserts = Field(default_factory=RDFGraph)
class-attribute
instance-attribute
¶
model_config = ConfigDict(arbitrary_types_allowed=True)
class-attribute
instance-attribute
¶
Methods:¶
apply_to(graph)
¶
Apply in place, deletes first; returns the triples changed.
Source code in ontocast/tool/ontology_validation/consolidate.py
counts()
¶
to_graph_update()
¶
The patch as a delete-then-insert :class:GraphUpdate.
Source code in ontocast/tool/ontology_validation/consolidate.py
ResolvedAction
¶
Bases: BaseModel
An action after validation: the term and target as IRIs.
Source code in ontocast/tool/ontology_validation/consolidate.py
Functions:¶
add_flag(flags, iri, reason, targets=())
¶
Add reason to iri's flags, with the terms it points at.
Source code in ontocast/tool/ontology_validation/consolidate.py
compile_actions(decided, graph, *, minted)
¶
The deletes and inserts the decided actions make on graph.
merge_into T: the term's own triples go (Tcarries its definition); every other triple naming it namesTinstead.generalise_to T: its named parents are replaced byT.demote_to_property_value: its class typing and named superclasses go; it becomes askos:Conceptindividual whose former parents areskos:broader. Subclasses and domain/range uses move to its former parent, or go when it had none.drop: every triple naming it goes.
Source code in ontocast/tool/ontology_validation/consolidate.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
resolve_actions(actions, *, minted, candidates, catalog_index, prefixes, reviewed=None)
¶
Validate model actions and fill in defaults for every minted term.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actions
|
Iterable[OntologyTermAction]
|
The model's actions, first one per term wins. |
required |
minted
|
Mapping[str, str]
|
Every minted term the actions may name, with its role. |
required |
candidates
|
set[str]
|
Minted terms the plan did not name; their default is drop. |
required |
catalog_index
|
CatalogSurfaceIndex
|
Names and roles of every catalog term. |
required |
prefixes
|
Mapping[str, str]
|
CURIE prefixes the prompt used. |
required |
reviewed
|
Iterable[str] | None
|
The terms the model was asked about; an action on any other
minted term is ignored. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ResolvedAction]
|
The decided action per minted term, and the refused actions with a |
list[tuple[str, str]]
|
reason. |
Source code in ontocast/tool/ontology_validation/consolidate.py
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
structural_flags(minted, graphs, catalog_index)
¶
Minted terms whose shape says a decision is needed, with the reasons.
variant: its name is another term's with one modifier added, or the same words, among minted and catalog terms of the same role; the target is the other term;value_set: one of three or more minted sibling classes whose labels differ in one word;catalog_duplicate: its label or local name names exactly one catalog term of compatible role, the target;well_known_duplicate: a term of the same role in a well-known vocabulary has its local name, ignoring case; those terms are the targets.
Model-free; a term with no flag needs no model call.