Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

58
LINES

< > BotCompany Repo | #1023066 // Phrase Corrector Demo

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (5586L/28K).

!7

sS phrases = [[
  United States of America
  God save the queen
  Bed and Breakfast
]];

sS inputs = [[
  United States of Incarceration
  God shave the queen
  Bed and Butter
]];

/* Gazelle-style program (just for illustration):

    $x is said
  + $y is a phrase
  + $old, $new = gazelle_singleChangedWord($y, $x)
  + $capitalized = capitalizeWord($y, $old)
  => No no no. $capitalized!
  
*/

cmodule PhraseCorrector > DynPrintLogAndEnabled {
  class Engine implements Runnable {
    S input;
    LS phrases = tlft(main.phrases);
  
    Collection<S> iterate__$x_is_said() { ret singletonUnlessNull(input); }
    Collection<S> iterate__$y_is_a_phrase() { ret phrases; }
    
    // Gazelle-style program translated to JavaX:
  
    run {
      for ping (S $x : iterate__$x_is_said()) {
        for ping (S $y : iterate__$y_is_a_phrase()) {
          for single (unpair S $old, $new : gazelle_singleChangedWord($y, $x)) {
            for single (S $capitalized : capitalizeWord($y, $old)) {
              emit("No no no. \*$capitalized*/!");
            }
          }
        }
      }
    }
  }
  
  void process(S input, bool speak) {
    temp tempSetTL(emit_print_prefix, "[Bot]  ");
    temp speak ? tempSetTL(emit_onEmit, ll(vf<S> dm_say)) : null;
    pcallF(setAll(new Engine, input := nlPrint("[User] ", input)));
  }

  start-thread {
    for (S input : tlft(inputs)) process(input, false);
    dm_onTopInput_q(voidfunc(S s) { if (enabled) process(s, true) });
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023066
Snippet name: Phrase Corrector Demo
Eternal ID of this version: #1023066/36
Text MD5: 270fc2d3ddee04184d1116ba305c7fa5
Transpilation MD5: 67f241fb3433dad8fad226ad179fbec9
Author: stefan
Category: javax / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-05-03 03:56:40
Source code size: 1538 bytes / 58 lines
Pitched / IR pitched: No / No
Views / Downloads: 274 / 904
Version history: 35 change(s)
Referenced in: [show references]