ontocast.tool.facts_validation.unit_findings¶
Deterministic per-unit findings on a rendered facts graph.
Only unresolved, machine-verified issues go back to the LLM, as MANDATORY fix instructions that must be resolved by rewriting — never by deleting the statement.
Attributes¶
CoverageMode = TypingLiteral['off', 'measurements', 'all']
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
Functions:¶
collect_unit_findings(*, graph, ontology_graph, quarantined, extraction_text, fact_namespaces, coverage_limit=30, coverage_mandatory='off', policy=None, is_citation_metadata=False, is_non_content=False, full_catalog_terms=None)
¶
Assemble all deterministic findings for one rendered unit graph.
Mandatory: quarantined literals (with closed-range individual
suggestions), forbidden-namespace terms (example.org), doc-namespace
predicates, unresolved catalog near-misses, predicates asserted on a
subject whose type contradicts their rdfs:domain, and value nodes
whose only numeric content sits in a label. Advisory by default: numeric
mentions of the source text absent from the graph, as two findings --
measurements (a number with its unit, in text order with context) and
bare numbers -- whose mandatory flag coverage_mandatory sets
(off | measurements | all; the booleans are off/all).
The policy's exempt terms (the sanctioned fallback vocabulary the facts prompt itself names, plus code predicates) never raise UNKNOWN_TERM: flagging the vocabulary the prompt recommends produced mandatory findings that repair renders obeyed by deleting correct data.
A citation-metadata unit is rendered with the bibliographic vocabulary
and told to keep away from the domain ontology, so its catalog share is
zero by instruction; DOMAIN_ADHERENCE is not judged there, nor on a
non-content unit (front matter, author notes, identifiers), which has no
domain facts for the catalog to describe.
full_catalog_terms is the whole catalog's inventory, as opposed to
the unit's retrieved snapshot in ontology_graph. A term the snapshot
did not retrieve is still a term, so it is never reported as unknown --
and, for a term that is genuinely unknown, replacement candidates are
offered only under token containment, never on similarity alone.
Source code in ontocast/tool/facts_validation/unit_findings.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | |
coverage_mode(value)
¶
Normalise the coverage-mandatory knob, boolean form included.
True is the setting's old spelling of all and False of
off; anything unrecognised is off, the advisory default.
Source code in ontocast/tool/facts_validation/unit_findings.py
domain_violation_findings(graph, ontology_graph)
¶
Report subjects whose asserted type contradicts a predicate's domain.
Asserting a triple whose predicate declares an rdfs:domain entails
that the subject belongs to that domain, so an untyped subject is never a
violation -- the type is simply left to inference. It becomes one when the
subject carries an asserted type that is unrelated to the declared domain:
inference then adds the domain class on top of an incompatible one, and
the contradiction surfaces later as a confusing failure somewhere else
(SHACL reporting a missing property on a class the graph never meant to
assert) rather than at the triple that caused it.
Conservative by construction, since a false accusation costs a render pass.
A subject is reported only when it has at least one asserted type and every
asserted type is unrelated to every declared domain -- neither a subtype
nor a supertype of it, following rdfs:subClassOf and
owl:equivalentClass intersections in both directions. Typing a subject
with a supertype of the domain (sosa:Observation where the domain is
obs:QuantitativeObservation) is consistent: inference specializes it,
it contradicts nothing, and flagging it would bury the real violations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
RDFGraph
|
Rendered facts graph for one unit. |
required |
ontology_graph
|
RDFGraph | None
|
Ontology context the renderer was given. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list[FactsUnitFinding]
|
One mandatory finding per offending (subject, predicate) pair, |
list[FactsUnitFinding]
|
ordered by subject then predicate. |
Source code in ontocast/tool/facts_validation/unit_findings.py
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 | |
domain_vocabulary_share(graph, catalog_terms, fact_namespaces)
¶
Count distinct schema terms drawn from the catalog, and the total.
Schema position only -- predicates and rdf:type objects. Instances in
the fact namespaces are excluded (they are supposed to be minted, not
looked up), and so are the RDF/RDFS/OWL/XSD/SKOS/DC/PROV plumbing
namespaces, which every graph uses regardless of which catalog it was
given and would otherwise float the ratio for free. Generic content
vocabularies such as schema.org deliberately stay in the denominator:
reaching for them instead of the catalog is exactly what this measures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
RDFGraph
|
The rendered unit graph. |
required |
catalog_terms
|
set[str]
|
Terms declared by the unit's ontology context. |
required |
fact_namespaces
|
Sequence[str]
|
Namespaces holding minted instances. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
tuple[int, int]: |
Source code in ontocast/tool/facts_validation/unit_findings.py
unit_numeric_inventory(*, graph, ontology_graph, extraction_text, policy=None, limit=30)
¶
Numbers of the unit text absent from its graph, measurements first.
The unit surfaces come from the unit individuals of the ontology context
(found through the configured unit-role property), so a catalog-specific
unit counts as a measurement once the catalog declares it. Measurements
are judged against structured (number, unit) pairs in the graph —
a bare numeric literal does not clear a unit-adjacent mention. Shared by
the coverage findings and the completion pass, which must agree on what
is missing.