From febc14be32cc7d0dec328fffc395c71858aee203 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Mon, 22 Sep 2025 15:55:30 -0700 Subject: [PATCH] add comments on what we should be doing --- src/main.zig | 17 +++++++++++++++++ src/root.zig | 5 +++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 87f19e1..fcebca0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -321,6 +321,23 @@ fn processCommand(allocator: std.mem.Allocator, sentence: [:0]const u8, parser: }; defer tree.deinit(); + // Bracketed words are "null" + // words with [?] are "unknown" + // If we have unknowns, I think we want to replace (or if no replacement + // is available, strip) them. Then re-parse immediately, because we're + // in a bad enough state that we might screw something else up + // + // If there are nulls, then we should walk those nulls and look for + // replacement values. If any replacements have been performed, then + // try re-parsing at that point. + // + // This might all be best done in the library itself. Pass in the + // map of replacement words and let it churn. + // + // For null words, I think we can use this replacement loop + // if (tree.hasUnknowns()) // then what? + // {} + const action_words = tree.sentenceAction() catch |err| { if (!builtin.is_test) std.log.err("Failed to extract action: {}\nParse tree: {f}", .{ err, tree }); diff --git a/src/root.zig b/src/root.zig index f9c98aa..960b5f7 100644 --- a/src/root.zig +++ b/src/root.zig @@ -151,8 +151,9 @@ pub const ParseTree = struct { node = node.child.?; // We need the next node, which should be our PP node - if (node.next == null) @panic("VP node must have a child with two members"); - node = node.next.?; + if (node.next == null) @panic("VP node must have a child with at least two members"); + while (node.next != null) // fast forward to the very last node at this level + node = node.next.?; // https://opencog.github.io/link-grammar-website/dict/section-PP.html if (!std.mem.startsWith(u8, node.label, "PP"))