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

43
LINES

< > BotCompany Repo | #1004028 // Test Adapter

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Transpiled version (2316L) is out of date.

1  
!759
2  
3  
!include #1004027 // WordAdapter
4  
5  
p {
6  
  genLog_set(latestChatLog());
7  
  print("Result: " + bla());
8  
}
9  
10  
static bool adapt_debug;
11  
12  
static S bla() {
13  
  L<S> log = gLog();
14  
  S bestResult = null;
15  
  double bestValue = 0;
16  
  thislearn: for (L<S> learn : gLearns()) {
17  
    if (adapt_debug) print("Testing learn: " + struct(learn));
18  
    
19  
    // j is starting point of match in log
20  
    j: for (int j = l(log)-l(learn)+1; j < l(log); j++) pcall {
21  
      if (adapt_debug) print("\nl(log)=" + l(log) + ", j=" + j);
22  
      Adapter adapter = new WordAdapter;
23  
      int k;
24  
      for (k = j; k < l(log); k++) {
25  
        S in = learn.get(k-j), out = log.get(k);
26  
        if (adapt_debug) print(in + " => " + out);
27  
        if (!adapter.canMatch(in, out)) {
28  
          if (adapt_debug) print("Can't match");
29  
          continue j;
30  
        }
31  
        adapter = adapter.plus(in, out);
32  
        if (adapt_debug) printStructure("  ", adapter);
33  
      }
34  
      double v = adapter.size();
35  
      if (bestResult == null || v < bestValue) {
36  
        bestResult = adapter.get(learn.get(k-j));
37  
        bestValue = v;
38  
        if (adapt_debug) print("New best: " + formatDouble(bestValue, 1) + " -- " + bestResult);
39  
      }
40  
    }
41  
  }
42  
  ret bestResult;
43  
}

Author comment

Began life as a copy of #1004026

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004028
Snippet name: Test Adapter
Eternal ID of this version: #1004028/1
Text MD5: c7c83b675796ababc2f0b33649824ee1
Author: stefan
Category: javax / talking robots
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-04 02:53:46
Source code size: 1252 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 538 / 586
Referenced in: [show references]