!7 sS phrases = [[ United States of America God save the queen Bed & Breakfast ]]; sS inputs = [[ United States of Incarceration God shave the queen Bed & Butter ]]; // Gazelle-style program sS rule = [[ $x is said + $y is a phrase + $old, $new = gazelle_singleChangedWord($y, $x) + $capitalized = quote(capitalizeWord($y, $old)) => Surely you mean: $capitalized. ]]; cmodule PhraseCorrector > DynPrintLogAndEnabled { class Engine implements Runnable { S input; Set phrases = asCISet(tlft(main.phrases)); LS iterate__$x_is_said() { ret singletonUnlessNull(input); } Collection iterate__$y_is_a_phrase() { ret phrases; } // Actual program: run { for (S $x : iterate__$x_is_said()) { for (S $y : iterate__$y_is_a_phrase()) { for (PairS temp1 : singletonUnlessNull(gazelle_singleChangedWord($y, $x))) { S $old, $new = unpair temp1; for (S $capitalized : singletonUnlessNull(quote(capitalizeWord($y, $old)))) { emit(format("Surely you mean \*$capitalized*/.")); } } } } } } void process(S input) { temp tempSetTL(emit_print_prefix, "[Bot] "); pcallF(setAll(new Engine, input := nlPrint("[User] ", input))); } start-thread { for (S input : tlft(inputs)) process(input); dm_onTopInput_q(voidfunc(S s) { if (enabled) process(s) }); } }