kibi-core 0.17.1 → 0.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kibi-core",
3
- "version": "0.17.1",
3
+ "version": "0.17.3",
4
4
  "private": false,
5
5
  "description": "Core Prolog modules and RDF graph logic for Kibi",
6
6
  "type": "module",
package/src/checks.pl CHANGED
@@ -2766,7 +2766,7 @@ strict_req_fact_pairing_violation(violation(
2766
2766
  strict_req_fact_pairing_issue(
2767
2767
  ReqId,
2768
2768
  Description,
2769
- "Add a property_value fact via requires_property for the same subject_key, or link requires_predicate to a fact_kind: predicate fact whose first argument is that subject_key"
2769
+ "Add a property_value fact via requires_property for the same subject_key, or link requires_predicate to a fact_kind: predicate fact about that subject_key (its subject argument or its subject_key)"
2770
2770
  ) :-
2771
2771
  kb:current_req(ReqId),
2772
2772
  kb_relationship(constrains, ReqId, SubjectFactId),
@@ -2874,15 +2874,34 @@ strict_req_fact_pairing_fact_kind(FactId, Kind) :-
2874
2874
  %% strict_req_predicate_grounds_subject(+ReqId, +SubjectKey)
2875
2875
  % A requirement that constrains a subject fact may ground its claim through
2876
2876
  % requires_predicate instead of requires_property (kb_model's replacementPlan
2877
- % swaps one for the other). The predicate pairs with the subject when its
2878
- % first argument is the subject_key, the argument position built-in and
2879
- % project-local schemas use for the governed subject.
2880
- % implements REQ-check-strict-pairing-predicate-grounding
2877
+ % swaps one for the other). The predicate pairs with the subject when it is
2878
+ % about that subject_key: its own subject_key names it (kb_model sets it for
2879
+ % schemas whose arguments name no subject), or the argument its schema names
2880
+ % `subject` holds it, wherever that argument sits. A predicate without a
2881
+ % project-local schema and without subject_key keeps the catalog convention
2882
+ % of the subject as its first argument.
2883
+ % implements REQ-check-strict-pairing-predicate-grounding-v2
2881
2884
  strict_req_predicate_grounds_subject(ReqId, SubjectKey) :-
2882
- kb:effective_req_predicate(ReqId, _FactId, _Namespace, _Name, [First|_], _Polarity),
2883
- First == SubjectKey,
2885
+ kb:effective_req_predicate(ReqId, FactId, Namespace, Name, Args, _Polarity),
2886
+ predicate_fact_subject_key(FactId, Namespace, Name, Args, PredicateSubject),
2887
+ PredicateSubject == SubjectKey,
2884
2888
  !.
2885
2889
 
2890
+ %% predicate_fact_subject_key(+FactId, +Namespace, +Name, +Args, -SubjectKey)
2891
+ % The subject a predicate fact is about; at most one answer per fact.
2892
+ predicate_fact_subject_key(FactId, _Namespace, _Name, _Args, SubjectKey) :-
2893
+ kb_entity(FactId, fact, Props),
2894
+ memberchk(subject_key=Raw, Props),
2895
+ !,
2896
+ normalize_term_atom(Raw, SubjectKey).
2897
+ predicate_fact_subject_key(_FactId, Namespace, Name, Args, SubjectKey) :-
2898
+ length(Args, Arity),
2899
+ kb:predicate_schema(_SchemaId, Namespace, Name, Arity, ArgumentNames, _Types),
2900
+ !,
2901
+ nth1(Position, ArgumentNames, subject),
2902
+ nth1(Position, Args, SubjectKey).
2903
+ predicate_fact_subject_key(_FactId, _Namespace, _Name, [SubjectKey|_], SubjectKey).
2904
+
2886
2905
  strict_req_fact_pairing_kind_label(legacy, "a legacy fact without fact_kind").
2887
2906
  strict_req_fact_pairing_kind_label(Kind, Label) :-
2888
2907
  format(string(Label), "a fact_kind=~w fact", [Kind]).
@@ -2932,7 +2951,7 @@ strict_readiness_issue(
2932
2951
  strict_readiness_issue(
2933
2952
  ReqId,
2934
2953
  Description,
2935
- "Add a matching property_value fact via requires_property for the same subject_key, or link requires_predicate to a predicate fact whose first argument is that subject_key"
2954
+ "Add a matching property_value fact via requires_property for the same subject_key, or link requires_predicate to a predicate fact about that subject_key (its subject argument or its subject_key)"
2936
2955
  ) :-
2937
2956
  kb_entity(ReqId, req, _),
2938
2957
  strict_readiness_level(ReqId, Level),
package/src/discovery.pl CHANGED
@@ -461,6 +461,7 @@ matching_gap_row(TypeFilter, MissingRelationships, PresentRelationships, Tags, S
461
461
  kb_entity(Id, Type, Props),
462
462
  matches_type(TypeFilter, Type),
463
463
  matches_tags(Tags, Props),
464
+ \+ hidden_provenance_stub(Tags, Type, Props),
464
465
  matches_source(SourceFilter, Props),
465
466
  relationships_missing(Id, MissingRelationships),
466
467
  relationships_present(Id, PresentRelationships),
@@ -477,6 +478,22 @@ matching_gap_row(TypeFilter, MissingRelationships, PresentRelationships, Tags, S
477
478
  source: Source
478
479
  }.
479
480
 
481
+ %% provenance_stub_props(+Type, +Props)
482
+ % A bootstrap provider fact that records only where an entry came from
483
+ % (tagged bootstrap:provenance-stub). It is not knowledge: gap rows and
484
+ % type coverage counts leave it out unless the caller asks for the tag.
485
+ % implements REQ-bootstrap-provenance-stubs
486
+ provenance_stub_props(fact, Props) :-
487
+ memberchk(tags=Tags, Props),
488
+ is_list(Tags),
489
+ member(Tag, Tags),
490
+ kb:normalize_term_atom(Tag, 'bootstrap:provenance-stub'),
491
+ !.
492
+
493
+ hidden_provenance_stub(RequestedTags, Type, Props) :-
494
+ \+ memberchk('bootstrap:provenance-stub', RequestedTags),
495
+ provenance_stub_props(Type, Props).
496
+
480
497
  relationships_missing(_Id, []).
481
498
  relationships_missing(Id, [Relationship|Rest]) :-
482
499
  relationship_count(Id, Relationship, 0),
@@ -537,7 +554,8 @@ coverage_rows(type, _Tags, _IncludePassing, _IncludeTransitive, _VerificationSna
537
554
  Pairs),
538
555
  maplist(type_pair_row, Pairs, Rows),
539
556
  length(Rows, Total),
540
- Summary = _{total: Total}.
557
+ aggregate_all(count, provenance_stub_entity(_), StubCount),
558
+ Summary = _{total: Total, provenanceStubs: StubCount}.
541
559
 
542
560
  coverage_rows(req, Tags, IncludePassing, IncludeTransitive, VerificationSnapshot, CheckedAt, MaxAgeSeconds, Rows, Summary) :-
543
561
  !,
@@ -890,10 +908,16 @@ must_priority(Priority) :-
890
908
  downcase_atom(Priority, Lowercase),
891
909
  sub_atom(Lowercase, _, 4, 0, must).
892
910
 
911
+ % Provenance stubs are counted apart (summary.provenanceStubs), never as facts.
912
+ % implements REQ-bootstrap-provenance-stubs
893
913
  type_entity_count(Type, Count) :-
894
- setof(Id, Props^kb_entity(Id, Type, Props), Ids),
914
+ setof(Id, Props^(kb_entity(Id, Type, Props), \+ provenance_stub_props(Type, Props)), Ids),
895
915
  length(Ids, Count).
896
916
 
917
+ provenance_stub_entity(Id) :-
918
+ kb_entity(Id, fact, Props),
919
+ provenance_stub_props(fact, Props).
920
+
897
921
  type_pair_row(Type-Count, _{id: Type, type: Type, count: Count}).
898
922
 
899
923
  bfs_layers(_Frontier, SeenNodes, SeenEdges, _Relationships, _Direction, 0, _MaxNodes, _MaxEdges, SeenNodes, SeenEdges, false) :- !.