@@ -18,7 +18,6 @@ pub fn main() !void {
1818 var gpa = std .heap .DebugAllocator (.{}){};
1919 defer _ = gpa .deinit ();
2020 const allocator = gpa .allocator ();
21- var ctx = zodd .ExecutionContext .init (allocator );
2221
2322 std .debug .print ("Zodd Datalog Engine - Knowledge Graph Reasoning\n " , .{});
2423 std .debug .print ("================================================\n\n " , .{});
@@ -117,24 +116,24 @@ pub fn main() !void {
117116
118117 // -- Build relations --
119118
120- var is_a_rel = try zodd .Relation (Pair ).fromSlice (& ctx , & is_a_data );
119+ var is_a_rel = try zodd .Relation (Pair ).fromSlice (allocator , & is_a_data );
121120 defer is_a_rel .deinit ();
122121
123- var symptom_rel = try zodd .Relation (Pair ).fromSlice (& ctx , & symptom_data );
122+ var symptom_rel = try zodd .Relation (Pair ).fromSlice (allocator , & symptom_data );
124123 defer symptom_rel .deinit ();
125124
126- var targets_rel = try zodd .Relation (Pair ).fromSlice (& ctx , & targets_data );
125+ var targets_rel = try zodd .Relation (Pair ).fromSlice (allocator , & targets_data );
127126 defer targets_rel .deinit ();
128127
129- var assoc_rel = try zodd .Relation (Pair ).fromSlice (& ctx , & assoc_data );
128+ var assoc_rel = try zodd .Relation (Pair ).fromSlice (allocator , & assoc_data );
130129 defer assoc_rel .deinit ();
131130
132131 // -- Step 1: Compute transitive type hierarchy --
133132 // is_a(X, Z) :- is_a(X, Y), is_a(Y, Z).
134133
135- var is_a = zodd .Variable (Pair ).init (& ctx );
134+ var is_a = zodd .Variable (Pair ).init (allocator );
136135 defer is_a .deinit ();
137- try is_a .insertSlice (& ctx , is_a_rel .elements );
136+ try is_a .insertSlice (is_a_rel .elements );
138137
139138 std .debug .print ("\n Computing transitive type hierarchy...\n " , .{});
140139
@@ -153,7 +152,7 @@ pub fn main() !void {
153152 }
154153
155154 if (results .items .len > 0 ) {
156- const rel = try zodd .Relation (Pair ).fromSlice (& ctx , results .items );
155+ const rel = try zodd .Relation (Pair ).fromSlice (allocator , results .items );
157156 try is_a .insert (rel );
158157 }
159158 if (iter > 50 ) break ;
@@ -170,9 +169,9 @@ pub fn main() !void {
170169 // -- Step 2: Inherit symptoms through type hierarchy --
171170 // has_symptom(D, S) :- is_a(D, D2), has_symptom(D2, S).
172171
173- var has_symptom = zodd .Variable (Pair ).init (& ctx );
172+ var has_symptom = zodd .Variable (Pair ).init (allocator );
174173 defer has_symptom .deinit ();
175- try has_symptom .insertSlice (& ctx , symptom_rel .elements );
174+ try has_symptom .insertSlice (symptom_rel .elements );
176175
177176 // For each is_a(D, D2), propagate symptoms from D2 to D
178177 {
@@ -198,7 +197,7 @@ pub fn main() !void {
198197 }
199198
200199 if (inherited .items .len > 0 ) {
201- try has_symptom .insertSlice (& ctx , inherited .items );
200+ try has_symptom .insertSlice (inherited .items );
202201 }
203202 }
204203 _ = try has_symptom .changed ();
@@ -217,29 +216,29 @@ pub fn main() !void {
217216 // Join key = Protein. targets is (Drug, Protein), assoc is (Protein, Disease).
218217 // Rekey targets as (Protein, Drug) to align the join key.
219218
220- var targets_by_protein = zodd .Variable (Pair ).init (& ctx );
219+ var targets_by_protein = zodd .Variable (Pair ).init (allocator );
221220 defer targets_by_protein .deinit ();
222221 {
223222 var flipped = PairList .empty ;
224223 defer flipped .deinit (allocator );
225224 for (targets_rel .elements ) | t | {
226225 try flipped .append (allocator , .{ t [1 ], t [0 ] }); // (Protein, Drug)
227226 }
228- try targets_by_protein .insertSlice (& ctx , flipped .items );
227+ try targets_by_protein .insertSlice (flipped .items );
229228 _ = try targets_by_protein .changed ();
230229 }
231230
232- var assoc_var = zodd .Variable (Pair ).init (& ctx );
231+ var assoc_var = zodd .Variable (Pair ).init (allocator );
233232 defer assoc_var .deinit ();
234- try assoc_var .insertSlice (& ctx , assoc_rel .elements );
233+ try assoc_var .insertSlice (assoc_rel .elements );
235234 _ = try assoc_var .changed ();
236235
237236 const Triple = struct { u32 , u32 , u32 };
238- var treats_triple = zodd .Variable (Triple ).init (& ctx );
237+ var treats_triple = zodd .Variable (Triple ).init (allocator );
239238 defer treats_triple .deinit ();
240239
241240 // joinInto: key=Protein, val1=Drug, val2=Disease
242- try zodd .joinInto (u32 , u32 , u32 , Triple , & ctx , & targets_by_protein , & assoc_var , & treats_triple , struct {
241+ try zodd .joinInto (u32 , u32 , u32 , Triple , & targets_by_protein , & assoc_var , & treats_triple , struct {
243242 fn logic (_ : * const u32 , drug : * const u32 , disease : * const u32 ) Triple {
244243 return .{ drug .* , disease .* , 0 };
245244 }
0 commit comments