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).

1  
!7
2  
3  
module LLtoNL > DynRecordingTextArea {
4  
  S output;
5  
  transient S calcedInput;
6  
  transient ReliableSingleThread rstCalc;
7  
  
8  
  visualize {
9  
    ret jvsplit(
10  
      jSection("INPUT (LL)", super.visualize()),
11  
      jSection("OUTPUT (NL)", dm_fieldTextArea('output)));
12  
  }
13  
  
14  
  start {
15  
    doEvery(0.5, rstCalc = dm_rst(this, r calc));
16  
  }
17  
  
18  
  void calc enter {
19  
    if (neq(text, calcedInput)) {
20  
      calcedInput = text;
21  
      new LS out;
22  
      final new MultiMap<S, LS> definitions;
23  
      for (S s : tlft(text)) {
24  
        LS tok = javaTokWithAllBrackets(s);
25  
        continue unless isSquareBracketed(second(tok));
26  
        S id = second(tok);
27  
        tok = subList(tok, 2);
28  
        if (eq(":", second(tok))) tok = subList(tok, 2);
29  
        clearToken(tok, 0);
30  
        definitions.put(id, tok);
31  
        //out.add(join(tok));
32  
      }
33  
      //out.add("Keys: " + keys(definitions));
34  
      out.addAll(map joinIfStringList(getEmits(r { render(definitions) })));
35  
      setField(output := lines(out));
36  
    }
37  
  }
38  
  
39  
  void render(MultiMap<S, LS> definitions) {
40  
    definitions = mapMultiMapValues(definitions, func(LS tok) -> LS {
41  
      new Matches m;
42  
      if (matchStart("there is", tok, m))
43  
        ret javaTokWithAllBrackets(m.rest());
44  
      ret tok;
45  
    });
46  
47  
    LL<S> bla = definitions.get("[1]");
48  
    if (l(bla) < 2) ret;
49  
    
50  
    // Make the first line
51  
    
52  
    LS line = concatLists(
53  
      ll(dropSuffixICTrim("(definition)", join(first(bla))),
54  
        " means: "), second(bla));
55  
    emit(join(line));
56  
    
57  
    for i to 10: {
58  
      LS line2 = expandLine(line, definitions);
59  
      if (line2 == null) break;
60  
      emit(join(line2));
61  
      line = line2;
62  
    }
63  
  }
64  
  
65  
  // Expand [2] etc. in the line
66  
  LS expandLine(LS line, MultiMap<S, LS> definitions) {
67  
    new LS line2;
68  
    for (S s : line) {
69  
      LS def = last(definitions.get(s));
70  
      if (def != null)
71  
        line2.addAll(def);
72  
      else
73  
        line2.add(s);
74  
    }
75  
    ret eq(join(line), join(line2)) ? null : line2;
76  
  }
77  
}

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: 354 / 985
Version history: 31 change(s)
Referenced in: [show references]