ontometer_corpus.steps.structural_metrics¶
Per-ontology hierarchy metrics from the structural sidecars.
Taxonomic depth, branching factor and the depth-distribution shape all need
the full subsumption hierarchy, which lives in the per-ontology structural
sidecars ($ONTOMETER_STORE/cache/structure/v<N>/<hh>/<file_hash>.parquet, the
subclass_edge and entity records written by the parse phase). Some
hierarchies are very large, so this script computes the metrics once, in
parallel, and writes a compact per-ontology table; consumers load that small
table instead of re-reading sidecars.
<corpus>/corpus.db (the latest-version, parsed rows) and the
sidecars under $ONTOMETER_STORE/cache/structure/v<N>/; never the raw files.
Runs after: ontometer-corpus process (parse and dedup phases).
Needs --store (or $ONTOMETER_STORE).
Keyed by raw-byte file_hash (matching the sidecar store and term_coupling.parquet), so distinct files cannot inherit one another's hierarchy merely because they declare the same class/property IRIs.
Depth model
- The hierarchy is a DAG (multiple inheritance is real). A node's parents are the targets of its subclass_edges; a "local root" is a node that never appears as a child within this ontology's own edges (its parent is external/imported or owl:Thing — depth 0).
- An explicit
rdfs:subClassOf owl:Thingis not an edge, and owl:Thing is not a class: whether a file writes that line depends on the tool that saved it, not on the hierarchy, so keeping it would give the same hierarchy different depth, size and branching. The line still counts as an asserted parent for multiple inheritance, as OQuaRE's TMOnto does. - Depth is computed by Kahn topological relaxation from the roots, which is exact for both the longest path (max over parents + 1) and the shortest path (min over parents + 1); both are kept, as separate columns. Nodes trapped in a cycle never reach in-degree 0; they are counted (n_cyclic) and excluded from the depth statistics rather than looping forever.
Metrics per ontology (all over the subclass-edge node set): n_nodes, n_roots, n_cyclic; n_classes, n_multiple_inheritance, multiple_inheritance_rate; n_orphans, orphan_rate; mean/max/std of longest-path depth, mean/std of shortest-path depth; branching = mean distinct-children fan-out over non-leaf nodes; depth_hist = node counts per longest-path depth level (list; index = depth), from which the shape of the depth distribution can be read.
Usage
ontometer-corpus structural-metrics --store /path/to/ontologies ontometer-corpus structural-metrics --store /path/to/ontologies --limit 50
Classes¶
Functions:¶
build(paths, limit=None, workers=8)
¶
Source code in ontometer_corpus/steps/structural_metrics.py
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 322 323 324 325 326 327 328 329 330 331 332 333 | |
main(limit, workers, paths)
¶
Per-ontology hierarchy metrics from the structural sidecars. Needs the object store.