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

34
LINES

< > BotCompany Repo | #1004729 // scoreTextPredictAlgo

JavaX fragment (include)

1  
static StringBuilder scoreTextPredictAlgo_buf;
2  
3  
static double scoreTextPredictAlgo(Algorithm algorithm, S text) {
4  
  ret scoreTextPredictAlgo(algorithm, text, 0, 0);
5  
}
6  
7  
static double scoreTextPredictAlgo(Algorithm algorithm, S text,
8  
  int descLength, int pivotLength) {
9  
  long time = now();
10  
  int score = 0;
11  
  int n = l(text);
12  
13  
  for (int pos = 0; pos < n; ) {
14  
    S s = algorithm.predict(n-pos);
15  
    if (empty(s)) s = " "; // We're lenient
16  
    
17  
    if (l(s) > n-pos)
18  
      s = substring(s, 0, n-pos);
19  
    if (scoreTextPredictAlgo_buf != null) scoreTextPredictAlgo_buf.append(s);
20  
    int j = pos+l(s);
21  
    S real = substring(text, pos, j);
22  
    score += getNumberOfEqualCharacters(real, s);
23  
    algorithm.feed(real);
24  
    pos = j;
25  
  }
26  
  
27  
  double score2 = score*100.0/n-lengthPunishment(descLength, pivotLength);
28  
  done_always(time, "SCORE: " + score + "/" + n + " = " + formatDouble(score2, 2) + "%");
29  
  
30  
  if (lastSilentException() != null)
31  
    printStackTrace(lastSilentException());
32  
33  
  ret score2;
34  
}

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: 482 / 512
Referenced in: [show references]