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.
Attributes¶
BFS_PREDICATE_PRIORITY = (frozenset({RDFS.label, SKOS.prefLabel}), frozenset({RDF.type}), frozenset({RDFS.subClassOf, OWL.equivalentClass}), frozenset({RDFS.domain, RDFS.range, RDFS.subPropertyOf}), frozenset({RDFS.comment, SKOS.definition, SKOS.scopeNote, SKOS.altLabel}))
module-attribute
¶
GENERIC_INDIVIDUAL_TYPES = frozenset({OWL.NamedIndividual, OWL.Class, RDFS.Class})
module-attribute
¶
MIN_MEANINGFUL_RESTRICTION_PREDICATES = 2
module-attribute
¶
NOISY_EXPANSION_PREDICATES = frozenset({RDF.first, RDF.rest, OWL.imports, OWL.versionIRI, OWL.versionInfo, OWL.priorVersion, OWL.backwardCompatibleWith, OWL.incompatibleWith, DCTERMS.creator, DCTERMS.license, DCTERMS.created, DCTERMS.modified, DCTERMS.identifier, DCTERMS.publisher, DCTERMS.contributor})
module-attribute
¶
OWL_RESTRICTION_MEANINGFUL_PREDICATES = frozenset({OWL.onProperty, OWL.someValuesFrom, OWL.allValuesFrom, OWL.hasValue, OWL.cardinality, OWL.minCardinality, OWL.maxCardinality, OWL.qualifiedCardinality, OWL.minQualifiedCardinality, OWL.maxQualifiedCardinality, OWL.onDataRange, OWL.onClass, OWL.oneOf})
module-attribute
¶
Functions:¶
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.