ontocast.onto.graph_prune¶
Seed-free graph pruning shared by induced-subgraph retrieval and prompt condensing.
These pruners and predicate vocabularies were written for the vector-retrieval
induced-subgraph builder in :mod:ontocast.tool.sparql, which is the only place
in the pipeline that ever bounded how much ontology reached the LLM. The prompt
condenser (:mod:ontocast.onto.ontology_condense) needs the same judgements
about which triples carry the schema and which are scaffolding, so they live
here rather than being duplicated: two copies of "what is safe to drop" would
drift, and the drift would be invisible until an extraction quietly lost a term.
Everything here operates on a materialized graph with no seed list, no relevance scores and no triple store, which is what makes it reusable outside retrieval.
bfs_triple_rank(triple)
¶
Sort key admitting defining triples before incidental ones, ties lexicographic.
Source code in ontocast/onto/graph_prune.py
count_meaningful_restriction_predicates(graph, bnode)
¶
How many predicates of a restriction bnode actually constrain anything.
Source code in ontocast/onto/graph_prune.py
prune_degenerate_restriction_bnodes(result)
¶
Remove stub restriction blank nodes and subClassOf edges pointing to them.
Source code in ontocast/onto/graph_prune.py
prune_orphaned_bnode_subjects(graph)
¶
Remove blank-node subjects that no triple in the graph references as object.
Source code in ontocast/onto/graph_prune.py
remove_bnode_subgraph(graph, bnode)
¶
Remove every triple asserted about a blank node.
remove_subclassof_to_bnode(graph, bnode)
¶
Remove the class-axiom edges pointing at a blank node.
Source code in ontocast/onto/graph_prune.py
strip_redundant_generic_types(graph)
¶
Drop generic rdf:types when the subject has informative types or URI hierarchy.