kibi-core 0.1.4 → 0.1.5

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 +44 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kibi-core",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
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
@@ -59,6 +59,7 @@ kb_uri('urn-kibi:').
59
59
  :- dynamic kb_attached/1.
60
60
  :- dynamic kb_audit_db/1.
61
61
  :- dynamic kb_graph/1.
62
+ :- dynamic entity/4. % Support legacy .pl file format (Type, Id, Title, Props)
62
63
 
63
64
  %% kb_attach(+Directory)
64
65
  % Attach to a KB directory with RDF persistence and file locking.
@@ -97,7 +98,11 @@ kb_attach(Directory) :-
97
98
  % Track attachment state
98
99
  assert(kb_attached(Directory)),
99
100
  assert(kb_audit_db(AuditLog)),
100
- assert(kb_graph(GraphURI)).
101
+ assert(kb_graph(GraphURI)),
102
+
103
+ % Load legacy .pl entity files if present
104
+ load_kb_pl_files(Directory).
105
+
101
106
 
102
107
  %% kb_detach
103
108
  % Safely detach from KB, flushing journals and closing audit log.
@@ -142,6 +147,25 @@ kb_save :-
142
147
  with_kb_mutex(Goal) :-
143
148
  with_mutex(kb_lock, Goal).
144
149
 
150
+ %% load_kb_pl_files(+Directory)
151
+ % Load legacy .pl entity files from the KB directory.
152
+ % These files use entity/4 format: entity(Type, Id, Title, Props).
153
+ load_kb_pl_files(Directory) :-
154
+ retractall(entity(_, _, _, _)),
155
+ directory_files(Directory, Files),
156
+ forall(
157
+ (
158
+ member(File, Files),
159
+ sub_atom(File, _, 3, 0, '.pl'),
160
+ \+ memberchk(File, ['entities.pl', 'relationships.pl', 'validation.pl'])
161
+ ),
162
+ (
163
+ atom_concat(Directory, '/', Prefix),
164
+ atom_concat(Prefix, File, FullPath),
165
+ catch(consult(FullPath), Error, (print_message(warning, Error), fail))
166
+ )
167
+ ).
168
+
145
169
  %% kb_assert_entity(+Type, +Properties)
146
170
  % Assert an entity into the KB with validation and audit logging.
147
171
  % Properties is a list of Key=Value pairs.
@@ -209,7 +233,25 @@ kb_entity(Id, Type, Props) :-
209
233
  PropURI \= TypeURI,
210
234
  uri_to_key(PropURI, Key),
211
235
  literal_to_value(ValueLiteral, Value)
212
- ), Props).
236
+ ), Props).
237
+
238
+ % Fallback: read from legacy entity/4 facts loaded from .pl files
239
+ kb_entity(Id, Type, Props) :-
240
+ entity(Type, Id, _Title, PropList),
241
+ convert_legacy_props(PropList, Props).
242
+
243
+ % Convert legacy property list format to Key=Value pairs
244
+ convert_legacy_props([], []).
245
+ convert_legacy_props([Prop|Rest], [Key=Value|OutRest]) :-
246
+ convert_legacy_prop(Prop, Key, Value),
247
+ convert_legacy_props(Rest, OutRest).
248
+
249
+ convert_legacy_prop(Prop, Key, Value) :-
250
+ functor(Prop, Key, 1), !,
251
+ arg(1, Prop, Value).
252
+ convert_legacy_prop(Key-Value, Key, Value) :- !.
253
+ convert_legacy_prop(Key=Value, Key, Value) :- !.
254
+ convert_legacy_prop(Prop, Prop, true).
213
255
 
214
256
  %% kb_entities_by_source(+SourcePath, -Ids)
215
257
  % Returns all entity IDs whose source property matches SourcePath (substring match).