// expects a "good tree" now abstract sclass DialogBot { sbool debug, repeat = true; OccTree2 tree, node; *(OccTree2 *tree) { node = tree; } void take(E e) { selectMatching(e); } E getSingleOutput() { E e = nextBotOutput(); if (e != null) select(node, e); ret e; } void rewind() { node = node.parent; } E findMatch(OccTree2 node, E in) { for (E e : node.followUpKeys()) if (matchE(e, in)) ret e; null; } bool selectMatching(E in) { E e = findMatch(node, in); bool rep = false; if (repeat && e == null && node != tree) { e = findMatch(tree, in); rep = true; } if (e != null) { if (debug) { if (rep) print("Repeat!"); print("Selecting " + struct(e) + " matching " + struct(in)); } select(rep ? tree : node, e); true; } if (debug) print("No match for " + structure(in) + " in " + structure(node.followUpKeys())); false; } abstract bool matchE(E a, E b); E nextBotOutput() { new L<E> l; Collection<E> follows = node.followUpKeys(); for (E e : follows) if (e.a() || isCommand(e)) l.add(e); if (empty(l)) null; // fail("no good bot output: " + struct(node.followUpKeys())); if (l(l) > 1) fail("unclear bot output: " + struct(follows)); ret first(l); } void select(OccTree2 n, E e) { node = n.followUp(e); if (node == null) fail("can't select " + structure(e)); } bool isCommand(E e) { ret e.state() && matchStart("bot", e.state); } } sclass LooseBot extends DialogBot { *(OccTree2 node) { super(node); } bool matchE(E a, E b) { // standard NL matching ret eq(a.type(), b.type()) && match(a.text(), b.text()); } }
Began life as a copy of #1003405
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1003410 |
Snippet name: | Tree-Walking DialogBot + LooseBot v3 (dev.) |
Eternal ID of this version: | #1003410/1 |
Text MD5: | 8013207cee28c1f382222dea9b8a4535 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-06-30 21:11:45 |
Source code size: | 1878 bytes / 82 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 633 / 603 |
Referenced in: | #1003412 - Tree-Walking DialogBot + LooseBot v4 (parallel walk) |