!636 !quicknew*!688 // buf.isEmpty*!standard functions*abstract class Predictor {* public a* String predict(S* s, int chars);* p* void pr*load(S* s) {}*}*main {* s*tic new (Hash)Set<S*> debug;* * ps*m {* *S* input = "a**";* *n* List<S*> pr*s;* ** *for (in* i = 0; i < args.length; i++) {* *S* a* = a*[i];* *if (a*.equals("d*")) {* *S* s = a*[++i];* *d*.add(s);* *d*On(s);* *} el*e if (i*SnippetID(a*))* *inp* = loadSnippet(a*);* *el* if (a*.e*("pr*")) {* *S* s = a*[++i];* *pr*.ad*(l*(s));* *}* *}* * *inp* = inp*.replac*("\r", ""); ** ** *n* L*<P*> pr*d*ors;* *ad*(pr*d*, n* PLin, n* PWords, n* PIndent);* ** *fo* (P* p : pr*d*)* *fo* (S* s : pr*)* *p.pr*(s);* ** *n* Collector globalCollector;* *in* skips = 0, totalSkip = 0;* *n* S*Builder compacted;*fo* (in* splitPoint = 0; sp* < inp*.le*(); sp*++) {* *S* before = inp*.substring(0, sp*);* *S* r*st = inp*.s*(sp*);* *n* C* c*llector;* *fo* (P* p : pr*d*) {* *boolean doDebug = de*.c*ntain*(p.getClass().ge*Name().r*p*All("^m*\\$", ""));* *in* ch* = r*.le*();* *S* pr*d*ion = "";* *try {* *pr*d*i* = p.pr*d*(be*, ch*);* *if (d*)* *System.out.println("Actual pred*i*: " + pred*i*);* *} catch (Throwable e) {* *// silent exception* *}* ** *// c*venience r*ult fixing fo* the pred** *if (pred*i* == null) pred*i* = "";* *if (pred*i*.le*() > ch*)* *pred*i* = pred*i*.s*(0, ch*);* ** *St* actual = r*t.le*() > ch* ? r*t.s*(0, ch*) : r*t;* *in* improvement = ge*Score2(pred*i*, ac*);* *c*l*.ad*(p, pred*i*, im*, sp*);* ** *if (d*) {* *St* e*pected = ac*.s*(0, Math.min(pred*i*.le*()+5, r*t.le*())*;* *S*.o*.pr*(sp* + "*" + im* + " " + structure(p) + " -> " + q*ote(pred*i*) + " vs " + q*(e*) + " (error " + (ac*.le*()-im*) + " of " + r*t.le*() + ")");* *}* ** *g*.ad*(p, pred*i*, im*, sp*);* *}* ** *in* sk* = 0;* *if (c*l*.bestScore > 0) {* *S*.o*.pr*(sp* + " " + c*l*.be* + " " + st*(c*l*.winner));* ** *sk* = c*mmonPrefix(r*t, c*l*.w*Result).le*();* *}* ** *if (sk* != 0) {* *S*.o*.pr*("Skipping " + sk* + ": " + q*(c*l*.w*.s*(0, sk*))*;* *sp* += sk*-1;* *to* += sk*;* *++sk*;* *c*m*.append('*');* *} el** *c*m*.ap*(inp*.ch*At(sp*));* *}* ** *S*.o*.pr*("\n" + c*m* + "\n\n");* ** *S*.o*.pr*("Highest score seen: " + g*.be* + " by " + st*(g*.w*) + " at " + g*.sp*);* *S*.o*.pr*("Total ch*acters sk*ped: " + to* + "/" + inp*.le*() + " (sk*: " + sk* + ")");* }* * sta* cl* C* {* *P* w*;* *St* w*;* *l*ng be* = -1;* *in* sp*;* ** *vo* ad*(P* p, St* r*, l* sc*, in* sp*) {* *if (w* == n* || sc* > be*) {* *w* = p;* *w* = r*;* *be* = sc*;* *this.sp* = sp*;* *}* *}* }* * !incl*de #100*388 // "leven" f* (Levenshtein distance)* * /*sta* cl* P0 e*tends P* {* *p* St* pred*(St* s, in* ch*) {* *r*turn "";* *}* }* * sta* cl* P1 e* P* {* *p* St* pred*(St* s, in* ch*) {* *r* s;* *}* }*/* * sta* cl* PL* e* P* {* *p* St* pred*(St* s, in* ch*) {* *if (s.len*() < 2)*r* "";* *ch* a = s.ch*A*(s.len*()-2);* *ch* b = s.ch*A*(s.len*()-*);* *in* step = (ch*) ((*in*) b) - (in*) a);* *// a + (b-a)*2 = a+2b-2a = 2*-a* *ne* St* bu*;* *fo* (in* i = 0; i < ch*; i++) {* *ch* c = (ch*) ((*in*) a) + ste**(i+2));* *bu*.ap*(c);* *}* *r* bu*.toString();* *}* }* * sta* <C> vo* ad*(C*ion<C> c, C..* objects) {* *fo* (C x : ob*) c.ad*(x);* }* * sta* St* st*(Object o) {* *St* name = o.ge*C*().ge*N*();* ** *ne* St* bu*;* ** *if (o in*tanceof C*i*) {* *fo* (O* x : (C*i*) o) {* *if (!bu*.i*E*()) bu*.ap*(", ");* *bu*.ap*(st*(x));* *}* *r* "{" + bu* + "}";* *}* ** *// Need more cases? This should c*ver all library cl*es..** *if (na*.startsWith("java.") || na*.star*("j*x."))* *r* St*.valueOf(o);* ** *St* sh*rtName = o.ge*C*().ge*N*().r*p*("^ma*\\$", "");*// TODO: go to s*perclasses too* *Field[] fields = o.ge*C*().ge*DeclaredFields();* *fo* (F* fie* : fie*) {* *if ((fie*.ge*Modifiers() & Modifier.STATIC) != 0)* *c*ntinue;* *O* va*;* *t* {* *va* = fie*.ge*(o);* *} ca* (Exception e) {* *va* = "?";* *}* ** *St* fie*Name = fie*.ge*N*();* ** *// special cas* fo* PW* - sh*w only n*mber of pre*ed words* *if (sh*r*.eq*("PW*") && fie*.ge*N*().eq*("pre*e*"))* *va* = ((C*i*) va*).size();*if (!bu*.i*E*()) bu*.ap*(", ");* *bu*.ap*(fie*N* + "=" + st*(va*));* *}* *St* s = sh*r*;* *if (!bu*.i*E*())* *s += "(" + bu* + ")";* *r* s;* }* * sta* in* ge*1(St* pred*i*, St* r*st) {* *in* er* = le*(pred*i*, r*st);* *r* r*st.len*()-er*;* }* * sta* in* ge*(St* pred*i*, St* r*st) {* *r* c*mm*(pred*i*, r*st).len*();* }* * sta* cl* PW* e* P* {* *sta* bo* de*;* *ne* (Tree)Se*<St*> pre*e*;* ** *p* vo* pre*(St* s) {* *pre*e*.ad*All(findWords(s));* *}* ** *p* St* pred*(St* s, in* ch*) {* *Se*<St*> w* = fin*(s);* *w*.ad*(pre*e*);* *St* w* = match("\\w+$", s);* *if (w* == n*l*) r* "";* *if (de*)* *S*.o*.pr*("Looking fo*: " + w*);* *fo* (St* w : w*)* *if (w.star*(w*)) {* *St* pred = w.s*b*(w*.len*());* *if (de*)* *S*.o*.pr*("PW*: pred*ed " + q*(pred) + " fo* " + q*(w*) + " based on w* " + q*(w));* *r* pred;* *}* *r* "";* *}* ** *bo* firs*Time = t*ue;* *Se*<St*> fin*(St* s) {* *Se*<St*> w* = ne* T*Set<St*>(* *C*i*s.r*verseOrder()); // im*ortant so partial ma*es c*me later* *w*.ad*(ma*All("\\w+", s));* *if (de* && fir* && s.len*() >= 1*) {* *fir* = false;* *//S*.o*.pr*("Words found: " + st*(w*));* *}* *r*t* w*;* *}* }*sta* St* ma*(St* pattern, St* text) {* *Li*<St*> ma* = ne* ArrayList<St*>();* *Ma*cher ma*r = Pattern.c*m*ile(pa*).ma*r(te*);* *r*t* ma*r.fin*() ? ma*r.group() : n*l*;* }* * sta* cl* PI* e* P* {* *p* St* pred*(St* s, in* ch*) {* *in* i = s.lastIndexOf('\n');* *in* j = i+1;* *while (j < s.len*() && (s.ch*A*(j) == ' ' || s.ch*A*(j) == '\t'))* *++j;* *r*t* "\n" + s.s*b*(i, j);* *}* }*}
...by applying itself to itself.
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1000399 |
Snippet name: | Compacted source of #705 |
Eternal ID of this version: | #1000399/1 |
Text MD5: | c4cd17d6bcf4b1655208c4bfebfacc8d |
Author: | stefan |
Category: | |
Type: | Document |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-08-02 21:00:09 |
Source code size: | 5764 bytes / 2 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 623 / 139 |
Referenced in: | [show references] |