//! demo: token attribute extraction and parser state machine transitions. const std = @import("std"); const spacez = @import("spacez"); pub fn main() !void { const print = std.debug.print; // demo: extract token attributes const tokens = [_][]const u8{ "Barack", "Obama", "visited", "Paris" }; print("spacez token attributes:\n", .{}); for (tokens) |token| { const attrs = spacez.extractAttrs(token); var shape_buf: [64]u8 = undefined; const shape = spacez.computeShape(token, &shape_buf); print(" {s:>10} norm={x:0>16} shape={s}\n", .{ token, attrs.norm, shape, }); } // demo: parser state machine (without model weights, just show transitions) print("\nparser state machine demo:\n", .{}); var state = spacez.parser.State.init(4); const actions = [_]struct { a: spacez.parser.Action, l: ?spacez.Label }{ .{ .a = .BEGIN, .l = .PERSON }, .{ .a = .LAST, .l = .PERSON }, .{ .a = .OUT, .l = null }, .{ .a = .UNIT, .l = .GPE }, }; for (actions, 0..) |act, i| { const valid = state.isValid(act.a, act.l); print(" step {d}: {s}-{s} valid={}\n", .{ i, @tagName(act.a), if (act.l) |l| @tagName(l) else "(none)", valid, }); if (valid) state.apply(act.a, act.l); } print("\nentities found:\n", .{}); for (state.entities()) |e| { print(" [{d}..{d}) {s}\n", .{ e.start, e.end, @tagName(e.label) }); } }