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

34
LINES

< > BotCompany Repo | #1004729 // scoreTextPredictAlgo

JavaX fragment (include)

static StringBuilder scoreTextPredictAlgo_buf;

static double scoreTextPredictAlgo(Algorithm algorithm, S text) {
  ret scoreTextPredictAlgo(algorithm, text, 0, 0);
}

static double scoreTextPredictAlgo(Algorithm algorithm, S text,
  int descLength, int pivotLength) {
  long time = now();
  int score = 0;
  int n = l(text);

  for (int pos = 0; pos < n; ) {
    S s = algorithm.predict(n-pos);
    if (empty(s)) s = " "; // We're lenient
    
    if (l(s) > n-pos)
      s = substring(s, 0, n-pos);
    if (scoreTextPredictAlgo_buf != null) scoreTextPredictAlgo_buf.append(s);
    int j = pos+l(s);
    S real = substring(text, pos, j);
    score += getNumberOfEqualCharacters(real, s);
    algorithm.feed(real);
    pos = j;
  }
  
  double score2 = score*100.0/n-lengthPunishment(descLength, pivotLength);
  done_always(time, "SCORE: " + score + "/" + n + " = " + formatDouble(score2, 2) + "%");
  
  if (lastSilentException() != null)
    printStackTrace(lastSilentException());

  ret score2;
}

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: #1004729
Snippet name: scoreTextPredictAlgo
Eternal ID of this version: #1004729/1
Text MD5: bd3ad79d25c580857d897bc9e1587c90
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-09-11 22:41:02
Source code size: 1033 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 483 / 512
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)