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

59
LINES

< > BotCompany Repo | #1002009 // Language detector - find shortest code (developing)

JavaX source code - run with: x30.jar

1  
!752
2  
3  
p {
4  
  // load Python, JavaX example code
5  
  S text1 = loadSnippet("#1002004");
6  
  S lang1 = "python";
7  
  S text2 = loadSnippet("#1001747");
8  
  S lang2 = "javax";
9  
  
10  
  // select a few lines each (or all lines) & make in/out examples
11  
  L<S[]> examples = concatLists(
12  
    makeExamples(text1, lang1),
13  
    makeExamples(text2, lang2));
14  
 
15  
  // optionally: remove lines appearing in both languages
16  
  
17  
  print("Got " + l(examples) + " example lines.");
18  
  
19  
  // run solver :)
20  
  
21  
  O solver = hotwire("#738"); // the master solver!
22  
  
23  
  // Usually, the solver looks for exact (100%) solutions.
24  
  // This time, instead we try to find the solutions that work in
25  
  // as many cases as possible.
26  
  
27  
  L learners = cast call(solver, "makeLearners");
28  
  print("Got " + l(learners) + " learners.");
29  
  
30  
  O _case = call(solver, "produceCase", unrollExamples(examples));
31  
  print("Full examples: " + structure(get(_case, "fullExamples")));
32  
  
33  
  // it's not split yet - call split()
34  
  print("Split point: " + l((L) get(_case, "examples1")));
35  
}
36  
37  
static S[] unrollExamples(L<S[]> examples) {
38  
  S[] x = new S[l(examples)*2];
39  
  for (int i = 0; i < l(examples); i++) {
40  
    x[i*2] = examples.get(i)[0];
41  
    x[i*2+1] = examples.get(i)[1];
42  
  }
43  
  ret x;
44  
}
45  
46  
// two-element string arrays (source line, language name)
47  
static L<S[]> makeExamples(S text, S lang) {
48  
  new L<S[]> l;
49  
  for (S line : toLinesFullTrim(text))
50  
    l.add(new S[] {line, lang});
51  
  ret l;
52  
}
53  
54  
static int codeSize(S java) {
55  
  ret totalLengthOfCodeTokens(javaTok(java));
56  
}
57  
58  
59  
}

Author comment

Began life as a copy of #1002005

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002009
Snippet name: Language detector - find shortest code (developing)
Eternal ID of this version: #1002009/1
Text MD5: 3681357a848478a692b3ecbd1f8d821a
Author: stefan
Category: python/javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-13 17:58:37
Source code size: 1569 bytes / 59 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 670 / 602
Referenced in: [show references]