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

77
LINES

< > BotCompany Repo | #1020206 // LL to NL Spike 1

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

Libraryless. Click here for Pure Java version (15163L/107K).

!7

module LLtoNL > DynRecordingTextArea {
  S output;
  transient S calcedInput;
  transient ReliableSingleThread rstCalc;
  
  visualize {
    ret jvsplit(
      jSection("INPUT (LL)", super.visualize()),
      jSection("OUTPUT (NL)", dm_fieldTextArea('output)));
  }
  
  start {
    doEvery(0.5, rstCalc = dm_rst(this, r calc));
  }
  
  void calc enter {
    if (neq(text, calcedInput)) {
      calcedInput = text;
      new LS out;
      final new MultiMap<S, LS> definitions;
      for (S s : tlft(text)) {
        LS tok = javaTokWithAllBrackets(s);
        continue unless isSquareBracketed(second(tok));
        S id = second(tok);
        tok = subList(tok, 2);
        if (eq(":", second(tok))) tok = subList(tok, 2);
        clearToken(tok, 0);
        definitions.put(id, tok);
        //out.add(join(tok));
      }
      //out.add("Keys: " + keys(definitions));
      out.addAll(map joinIfStringList(getEmits(r { render(definitions) })));
      setField(output := lines(out));
    }
  }
  
  void render(MultiMap<S, LS> definitions) {
    definitions = mapMultiMapValues(definitions, func(LS tok) -> LS {
      new Matches m;
      if (matchStart("there is", tok, m))
        ret javaTokWithAllBrackets(m.rest());
      ret tok;
    });

    LL<S> bla = definitions.get("[1]");
    if (l(bla) < 2) ret;
    
    // Make the first line
    
    LS line = concatLists(
      ll(dropSuffixICTrim("(definition)", join(first(bla))),
        " means: "), second(bla));
    emit(join(line));
    
    for i to 10: {
      LS line2 = expandLine(line, definitions);
      if (line2 == null) break;
      emit(join(line2));
      line = line2;
    }
  }
  
  // Expand [2] etc. in the line
  LS expandLine(LS line, MultiMap<S, LS> definitions) {
    new LS line2;
    for (S s : line) {
      LS def = last(definitions.get(s));
      if (def != null)
        line2.addAll(def);
      else
        line2.add(s);
    }
    ret eq(join(line), join(line2)) ? null : line2;
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1020206
Snippet name: LL to NL Spike 1
Eternal ID of this version: #1020206/32
Text MD5: 5f6f1cd013a1ee225130a0e8ff3ae4e0
Transpilation MD5: 68a9a702b694156732f1d765fa6e966b
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: 2018-12-10 20:56:44
Source code size: 2055 bytes / 77 lines
Pitched / IR pitched: No / No
Views / Downloads: 440 / 1103
Version history: 31 change(s)
Referenced in: [show references]