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

52
LINES

< > BotCompany Repo | #1002005 // Language detector frame work

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

Libraryless. Click here for Pure Java version (1314L/10K/29K).

!752

p {
  // load Python, JavaX example code
  S text1 = loadSnippet("#1002004");
  S lang1 = "python";
  S text2 = loadSnippet("#1001747");
  S lang2 = "javax";
  
  // select a few lines each (or all lines) & make in/out examples
  L<S[]> examples = concatLists(
    makeExamples(text1, lang1),
    makeExamples(text2, lang2));
 
  // optionally: remove lines appearing in both languages
  
  print("Got " + l(examples) + " example lines.");
  
  // run solver :)
  
  O solver = hotwire("#738"); // the master solver!
  
  // Usually, the solver looks for exact (100%) solutions.
  // This time, instead we try to find the solutions that work in
  // as many cases as possible.
  
  L learners = cast call(solver, "makeLearners");
  print("Got " + l(learners) + " learners.");
  
  O _case = call(solver, "produceCase", unrollExamples(examples));
  print("Full examples: " + structure(get(_case, "fullExamples")));
  
  // it's not split yet - call split()
  print("Split point: " + l((L) get(_case, "examples1")));
}

static S[] unrollExamples(L<S[]> examples) {
  S[] x = new S[l(examples)*2];
  for (int i = 0; i < l(examples); i++) {
    x[i*2] = examples.get(i)[0];
    x[i*2+1] = examples.get(i)[1];
  }
  ret x;
}

// two-element string arrays (source line, language name)
static L<S[]> makeExamples(S text, S lang) {
  new L<S[]> l;
  for (S line : toLinesFullTrim(text))
    l.add(new S[] {line, lang});
  ret l;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002005
Snippet name: Language detector frame work
Eternal ID of this version: #1002005/1
Text MD5: cd1f2a470aefe605a38cc17945190f85
Transpilation MD5: 6436dce5034454b9bd770d13d682af4a
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:43:43
Source code size: 1479 bytes / 52 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 594 / 613
Referenced in: #1002006 - Examples JavaX/Python (output of #1002005)
#1002009 - Language detector - find shortest code (developing)
#3000190 - Answer for stefanreich(>> t 20 questions)
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000238 - Answer for stefanreich (>> t power bot)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)