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

93
LINES

< > BotCompany Repo | #1004574 // Make Text & Learn (dev.)

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

Transpiled version (2654L) is out of date.

!752

p {
  L<S> texts = splitAtSpace("a b c d");
  data = litorderedmap();
  for (S s : texts)
    data.put(renderTheText(s), s);
  push("Dummy");
  push("MD5Recognizer");
  solveImage2Text();
}

static class Dummy {
  O get(BWImage img) { ret "dummy"; }
}

static class MD5Recognizer {
  new Map<S, S> map;
  
  O get(BWImage img) { ret map.get(md5OfBWImage(img)); }
  
  void train(Map<BWImage, S> data) {
    for (BWImage img : keys(data)) {
      S text = data.get(img);
      map.put(md5OfBWImage(img), text);
    }
  }
}

static Font renderTheText_font;

static BWImage renderTheText(S s) {
  if (renderTheText_font == null)
    renderTheText_font = loadFont("#1004569"); // "Ticketing"
  ret new BWImage(renderText(renderTheText_font, 20f, s));
}

static void push(S solver) {
  newProducts.add(solver);
}

// solvers are func(BWImage) -> S

static Map<BWImage, S> data;
static new LinkedBlockingQueue<S> newProducts;
static new Best best;

sclass Best {
  S solver;
  double score;
  
  void update(S solver, double score) {
    if (score > this.score) {
      print("New best score: " + score);
      this.score = score;
      this.solver = solver;
    }
  }
}

static void solveImage2Text() {
  while licensed {
    testSolver(grabFromQueue(newProducts));
  }
}

static void testSolver(S solver) {
  O realSolver = unstructure(solver);
  train(realSolver, data);
  double score = score(realSolver, data);
  print(formatDouble(score, 1) + ": " + solver);
  best.update(solver, score);
}

static void train(O realSolver, Map<BWImage, S> data) {
  callOpt(realSolver, "train", data);
}

static double score(O realSolver, Map<BWImage, S> data) {
  double score = 0;
  int n = 0;
  for (BWImage img : keys(data)) {
    S text = data.get(img);
    ++n;
    try {
      if (eq(callF(realSolver, img), text))
        ++score;
    } catch e {
      silentException(e);
    }
  }
  ret score*100/n;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1004574
Snippet name: Make Text & Learn (dev.)
Eternal ID of this version: #1004574/1
Text MD5: 3fcf5fe9e65f09fb820473bbce4aa9fb
Author: stefan
Category: javax / a.i.
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-24 14:49:38
Source code size: 1993 bytes / 93 lines
Pitched / IR pitched: No / No
Views / Downloads: 657 / 743
Referenced in: [show references]