kibi-core 0.6.2 → 0.6.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/kb.pl +45 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kibi-core",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "private": false,
5
5
  "description": "Core Prolog modules and RDF graph logic for Kibi",
6
6
  "type": "module",
package/src/kb.pl CHANGED
@@ -280,14 +280,14 @@ kb_assert_entity_no_audit(Type, Props) :-
280
280
  % Execute RDF operations with mutex protection
281
281
  with_kb_mutex((
282
282
  % Create entity URI using prefix notation for namespace expansion
283
- format(atom(EntityURI), 'kb:entity/~w', [Id]),
283
+ entity_id_to_uri(Id, EntityURI),
284
284
  % Upsert semantics: remove only property triples, preserving relationships.
285
285
  % Relationship triples have entity URI objects (kb:entity/...);
286
286
  % property triples have typed literal objects (_^^xsd:...).
287
287
  forall(
288
288
  ( rdf(EntityURI, Prop, Obj, Graph),
289
289
  ( atom(Obj)
290
- -> \+ atom_concat('kb:entity/', _, Obj)
290
+ -> \+ entity_uri_to_id(Obj, _)
291
291
  ; true
292
292
  )
293
293
  ),
@@ -309,11 +309,11 @@ kb_assert_entity_no_audit(Type, Props) :-
309
309
  kb_retract_entity_relationships(Id) :-
310
310
  kb_graph(Graph),
311
311
  with_kb_mutex((
312
- format(atom(EntityURI), 'kb:entity/~w', [Id]),
312
+ entity_id_to_uri(Id, EntityURI),
313
313
  forall(
314
314
  ( rdf(EntityURI, RelURI, TargetURI, Graph),
315
315
  atom(TargetURI),
316
- atom_concat('kb:entity/', _, TargetURI)
316
+ entity_uri_to_id(TargetURI, _)
317
317
  ),
318
318
  rdf_retractall(EntityURI, RelURI, TargetURI, Graph)
319
319
  )
@@ -346,7 +346,7 @@ kb_retract_entity(Id, Type, AuditProps) :-
346
346
  kb_graph(Graph),
347
347
  with_kb_mutex((
348
348
  % Create entity URI
349
- atom_concat('kb:entity/', Id, EntityURI),
349
+ entity_id_to_uri(Id, EntityURI),
350
350
  % Remove all triples for this entity
351
351
  rdf_retractall(EntityURI, _, _, Graph),
352
352
  % Log to audit
@@ -384,8 +384,8 @@ kb_entity(Id, Type, Props) :-
384
384
  % Find entity by pattern - use unquoted namespace term kb:type
385
385
  ( var(Id)
386
386
  -> rdf(EntityURI, kb:type, TypeLiteral, Graph),
387
- atom_concat('kb:entity/', Id, EntityURI)
388
- ; atom_concat('kb:entity/', Id, EntityURI),
387
+ entity_uri_to_id(EntityURI, Id)
388
+ ; entity_id_to_uri(Id, EntityURI),
389
389
  rdf(EntityURI, kb:type, TypeLiteral, Graph)
390
390
  ),
391
391
  % Extract type - convert string literal to atom
@@ -483,8 +483,8 @@ kb_assert_relationship_no_audit(RelType, FromId, ToId, _Metadata) :-
483
483
  % Execute RDF operations with mutex protection
484
484
  with_kb_mutex((
485
485
  % Create entity URIs
486
- atom_concat('kb:entity/', FromId, FromURI),
487
- atom_concat('kb:entity/', ToId, ToURI),
486
+ entity_id_to_uri(FromId, FromURI),
487
+ entity_id_to_uri(ToId, ToURI),
488
488
  % Create relationship property URI (full URI to match saved/loaded RDF)
489
489
  kb_uri(BaseURI),
490
490
  atom_concat(BaseURI, RelType, RelURI),
@@ -567,14 +567,45 @@ kb_relationship(RelType, FromId, ToId) :-
567
567
  % Create relationship property URI (full URI to match loaded RDF)
568
568
  kb_uri(BaseURI),
569
569
  atom_concat(BaseURI, RelType, RelURI),
570
- % Find matching relationships
570
+ kb_relationship_with_reluri(RelURI, Graph, FromId, ToId).
571
+
572
+ kb_relationship_with_reluri(RelURI, Graph, FromId, ToId) :-
573
+ nonvar(FromId), nonvar(ToId), !,
574
+ entity_id_to_uri(FromId, FromURI),
575
+ entity_id_to_uri(ToId, ToURI),
576
+ rdf(FromURI, RelURI, ToURI, Graph).
577
+ kb_relationship_with_reluri(RelURI, Graph, FromId, ToId) :-
578
+ nonvar(FromId), var(ToId), !,
579
+ entity_id_to_uri(FromId, FromURI),
571
580
  rdf(FromURI, RelURI, ToURI, Graph),
572
- % Extract IDs from URIs
573
- atom_concat('kb:entity/', FromId, FromURI),
574
- atom_concat('kb:entity/', ToId, ToURI).
581
+ entity_uri_to_id(ToURI, ToId).
582
+ kb_relationship_with_reluri(RelURI, Graph, FromId, ToId) :-
583
+ var(FromId), nonvar(ToId), !,
584
+ entity_id_to_uri(ToId, ToURI),
585
+ rdf(FromURI, RelURI, ToURI, Graph),
586
+ entity_uri_to_id(FromURI, FromId).
587
+ kb_relationship_with_reluri(RelURI, Graph, FromId, ToId) :-
588
+ rdf(FromURI, RelURI, ToURI, Graph),
589
+ entity_uri_to_id(FromURI, FromId),
590
+ entity_uri_to_id(ToURI, ToId).
575
591
 
576
592
  % Helper predicates
577
593
 
594
+ %% entity_id_to_uri(+Id, -URI)
595
+ % Build the canonical entity URI used for RDF read/write.
596
+ entity_id_to_uri(Id, URI) :-
597
+ format(atom(URI), 'kb:entity/~w', [Id]).
598
+
599
+ %% entity_uri_to_id(+URI, -Id)
600
+ % Extract entity ID from canonical or legacy entity URIs.
601
+ entity_uri_to_id(URI, Id) :-
602
+ ( kb_uri(BaseURI),
603
+ atom_concat(BaseURI, 'entity/', Prefix),
604
+ atom_concat(Prefix, Id, URI)
605
+ -> true
606
+ ; atom_concat('kb:entity/', Id, URI)
607
+ ).
608
+
578
609
  %% store_property(+EntityURI, +Key, +Value, +Graph)
579
610
  % Store a property as an RDF triple with appropriate datatype.
580
611
  % All values are stored as typed string literals to avoid URI interpretation issues.
@@ -1251,8 +1282,8 @@ symbol_has_req_coverage(Symbol, Req) :-
1251
1282
  production_symbol_covered_for_requirement(Symbol, Req).
1252
1283
 
1253
1284
  test_covers_requirement(Test, Req) :-
1254
- requirement_test_fallback_allowed(Req),
1255
1285
  requirement_verified_by_test(Req, Test),
1286
+ requirement_test_fallback_allowed(Req),
1256
1287
  test_satisfies_requirement_semantics(Test, Req).
1257
1288
  test_covers_requirement(Test, Req) :-
1258
1289
  kb_relationship(specified_by, Req, Scenario),