Java Reverse Engineer Demo
Input
[METHODS]
public BayesDisambiguatorOnLine(int) {
0 aload_0
1 iload_1
2 invokespecial BayesDisambiguator(int)
5 return
}
public void untrain(java.lang.Object, int) {
0 aload_0
1 getfield BayesDisambiguatorOnLine.priors
4 iload_2
5 dup2
6 daload
7 dconst_1
8 dsub
9 dastore
10 aload_0
11 getfield BayesDisambiguatorOnLine.weights
14 aload_1
15 invokeinterface java.util.Map.get(java.lang.Object)
20 checkcast double[]
23 astore_3
24 aload_3
25 iload_2
26 dup2
27 daload
28 dconst_1
29 dsub
30 dastore
31 iconst_1
32 istore 4
34 iconst_0
35 istore 5
37 iload 5
39 aload_0
40 getfield BayesDisambiguatorOnLine.numberOfClasses
43 if_icmpge 66
46 aload_3
47 iload 5
49 daload
50 getstatic BayesDisambiguatorOnLine.SMOOTH
53 dcmpl
54 ifeq 60
57 iconst_0
58 istore 4
60 iinc 5 1
63 goto 37
66 iload 4
68 ifeq 113
71 aload_0
72 getfield BayesDisambiguatorOnLine.weights
75 aload_1
76 invokeinterface java.util.Map.remove(java.lang.Object)
81 pop
82 iconst_0
83 istore 5
85 iload 5
87 aload_0
88 getfield BayesDisambiguatorOnLine.numberOfClasses
91 if_icmpge 113
94 aload_0
95 getfield BayesDisambiguatorOnLine.priors
98 iload 5
100 dup2
101 daload
102 getstatic BayesDisambiguatorOnLine.SMOOTH
105 dsub
106 dastore
107 iinc 5 1
110 goto 85
113 return
}
public void normalize() {
0 return
}
public int predict(java.lang.Object[]) {
0 dconst_0
1 dstore_2
2 iconst_0
3 istore 4
5 iload 4
7 aload_0
8 getfield BayesDisambiguatorOnLine.numberOfClasses
11 if_icmpge 30
14 dload_2
15 aload_0
16 getfield BayesDisambiguatorOnLine.priors
19 iload 4
21 daload
22 dadd
23 dstore_2
24 iinc 4 1
27 goto 5
30 dload_2
31 invokestatic java.lang.Math.log(double)
34 dstore_2
35 aload_0
36 getfield BayesDisambiguatorOnLine.numberOfClasses
39 newarray double
41 astore 4
43 aload_0
44 getfield BayesDisambiguatorOnLine.numberOfClasses
47 newarray double
49 astore 5
51 iconst_0
52 istore 6
54 iload 6
56 aload_0
57 getfield BayesDisambiguatorOnLine.numberOfClasses
60 if_icmpge 84
63 aload 5
65 iload 6
67 aload_0
68 getfield BayesDisambiguatorOnLine.priors
71 iload 6
73 daload
74 invokestatic java.lang.Math.log(double)
77 dastore
78 iinc 6 1
81 goto 54
84 iconst_0
85 istore 6
87 iload 6
89 aload_1
90 arraylength
91 if_icmpge 173
94 aload_0
95 getfield BayesDisambiguatorOnLine.weights
98 aload_1
99 iload 6
101 aaload
102 invokeinterface java.util.Map.containsKey(java.lang.Object)
107 ifeq 167
110 aload_0
111 getfield BayesDisambiguatorOnLine.weights
114 aload_1
115 iload 6
117 aaload
118 invokeinterface java.util.Map.get(java.lang.Object)
123 checkcast double[]
126 astore 7
128 iconst_0
129 istore 8
131 iload 8
133 aload 4
135 arraylength
136 if_icmpge 167
139 aload 4
141 iload 8
143 dup2
144 daload
145 aload 7
147 iload 8
149 daload
150 invokestatic java.lang.Math.log(double)
153 aload 5
155 iload 8
157 daload
158 dsub
159 dadd
160 dastore
161 iinc 8 1
164 goto 131
167 iinc 6 1
170 goto 87
173 ldc2_w -infinity
176 dstore 6
178 iconst_0
179 istore 8
181 iconst_0
182 istore 9
184 iload 9
186 aload 4
188 arraylength
189 if_icmpge 220
192 aload 4
194 iload 9
196 daload
197 dload 6
199 dcmpl
200 ifle 214
203 aload 4
205 iload 9
207 daload
208 dstore 6
210 iload 9
212 istore 8
214 iinc 9 1
217 goto 184
220 iload 8
222 ireturn
}
Output
- public BayesDisambiguator(int) {
100 2_ 3_ 6 8 _a abstract achieved allocate allocated alternate analysis appropriately arcs arrays ask assigned assigns batch becomes begins blank building built calculated care changing chosen clip collect colour combined computation computed conjunction convention converter cost counts deal _default defining definitions design detect dimension dimensions discard distribution duplicates effectively ends evaluates evaluation exponent extended false_ features fills fit frequency further generally generation go graphics handled happens hides hierarchical hook illegal implementations incorrect independent indicated indices individual invisible involves keep large larger layer lazy lead leaf limited linear listed looks mac maintain managed marks mean meaning modifications modifying my n _n nearest net network _no notifications outside parents placed please prefixes prevent probability providing quality r rate reflect relevant reload require respectively restore resume runs _s sample samples say scheme score separated set_ shift small sorts specifically split step stopped stores structures sub surrounding symbols themselves todo tracked translation trees trimmed trying turn various visibility wants weight _which whole widths
}
- public void train(java.lang.Object, int) {
_0_ 100 16 _2 _2_ 2d 6 _a _a_ alpha approximation arc arrays assigned assigns assume auto average avoids away _b _b_ backward basis batch best beyond blank building built _by calculated calculating calculation cancels choose class_ cluster collect combination combined computation computed computing conjunction convention cost counter counts cross deal decision defining degrees delta depth design detect differ difference dimension distributed distribution draw draws duplicates earlier evaluates evaluation evaluator exclusive expensive exponent extended f far faster figure filled fills filtered finished fit floating fraction frequency _from gain garbage generating go good gradient graphics grow hand handled hashmap hasn_t hide hierarchical highlight idea _ie implementations implementing _including incorrect increase increases independent indices individual initialise interaction interest involves k lazy leave levels likely linear live located locations loop lowest m mean min modifies modifying n natural nearest net network node_ nominal normalize normalizes _note _ok_ one_ _only opengl opposite optimization ordering originally outputs outside overall packages partial phase pixel placed places please positions possibly precision primitives probability problems procedure projection purpose push pushed puts r raise rate ratio reduced refers reflection relevant require respectively responsibility routine runs sample score segments separated set_ shift significant simulation size_ sizes slow small sorts split square statistics step steps stores strict sub sufficient sum surrounding symbols t term themselves _this todo too track training transformed trees true_ v various vectors vertices weight weights _when wish word world _x zoom
}
- public void normalize() {
100 _2 _2_ 6 _a _a_ accurate addition alternate approximation arc aren_t arrays assume auto average avoids axes _b_ batch best beyond blank bottom building built _by calculated calculation cancels center chance choose class_ cluster combination computation computed computing consider constants contributed convention cost counts critical cross cycle deal decimal decision defining degrees delta depth design difference dimension distributed distribution doing draw draws duplicates earlier easy estimate evaluates evaluation evaluator exclusive expensive exponent extended f factor far faster figure filled fills filtered finished fix fixed floating four fraction frequency _from gain garbage generating go good graphics grow hand handled hashcode__ hashmap hits idea implementations implementing _including increase independent indicator indices indirect individual inherit interaction interest large larger lazy leave levels limits linear locations loop lowest m math mean models move much n natural net network nominal nor normalizes _note _ok_ one_ opposite optimization optimized ordering origin outputs outside overall partial permitted phase pick placed positions possibly post probability problems procedure projection providing push pushed puts r rate ratio really reduced relevant respect respectively responsibility rest routine sample samples score segments set_ shift sign simulation size_ slow small smallest sorts specifically split square startup statistics step steps stores strict stub sub subset sum surrounding t term _this three todo too transformed transition translation true_ v values_ various vectors vertices weight weights whole won_t works world _x zoom
}
- public int predict(java.lang.Object[]) {
_0 0_ _1_ 100 12 16 _2 _2_ 2d 6 64 7 8 9 _a _a_ accepts accordingly accurate addition along alpha alternate although analysis anchor angle applicable applying approximation arc around arraylist arrays ascending assigns assume assumed assuming atoms auto average avoids axes _b _b_ bag basis batch belong best beyond biginteger bond bottom boundary bounding branch bug building _but _by caches calculated calculating calculation cancels caution center chance checksum choice choose class_ clip clipping cluster coefficients combination complex computation computed computing consider constants contract contributed convention conversions cost counts creator critical cut days deal decimal decision defining degrees deletes delivered delta depth describes design detect differ difference dimension dimensions distance distribution doing domain draw draws dt duplicates earlier easy efficient element_ endian enough estimate evaluates evaluating evaluation evaluator examples exclusive exit expensive explicit exponent extended extracted f factor _false_ far faster figure fill filled fills filtered finished fit fix floating forced formats forms four fraction frames frequency _from gain gap give goes good gradient grayscale grow handled hashcode__ head high higher highest hits idea _ie implementing implicit _in_ _including increase increases increment increments indexes indices indirect individual infinite inherit interaction interest interpreted intersection interval inverse invisible involves iterates iterating k kind labels large larger launched leading leave legal legend letter levels _like limits linear little locate locations loop low lowest _lt_ m major math max max_value mean measured merge metrics middle min minimal minus missing models moving much n nan natural nearest network node_ nominal normalization normalize normalized normalizes notation _note numerical obtained _ok_ ol one_ _only opaque opposite optimization optimized origin originally others outputs outside overall overflow overlap palette parameterized partial permitted phase pick pixel placed places polygon polynomial positions positive possibly post postscript power precision priority probability problems procedure procedures processes projection pushed puts r raise rate ratio reason receives reduced regardless repeated replaces reserved respect respectively responsibility rest rotation round rounded routine sample samples scaling score secondary segments separated shadow shapes shift shifted sign simulation size_ sizes slow small smallest sorted sorts square startup states statistics step steps stores strict structures sub subset substitution successfully suggested sum supposed surrounding t taking td term that_s _this _this_ three too training transformed transforms translation unchanged unknown unspecified upon usually v values_ vectors vertex vertices visitor weight weights _which whole widths window_s _x z zoom
}
- public double[] fullPredict(java.lang.Object[]) {
_0_ 100 _2 _2_ 2d 3_ 6 _a allocate allocated alternate approximation args arrays assigned assigns assume average _b b_ batch best beyond blank bottom building built _by calculated calculating class_ collect combination combined comma computation computed computing construct convention cost counter counts critical deal decision defining degrees depth design detect dimension distance distribution draw draws duplicates earlier effectively evaluates evaluation evaluator exclusive extended extracted f faces far faster figure filled fills filtered final finished fit floating formats frequency _from gain garbage generating goes good gradient grow hand handled hashmap hasn_t highlight _ie _including incorrect increases increment independent indices individual interaction interest invisible isn_t k kernel key_ labels larger layers lazy leave levels likely linear located locations lowest m mac max_value mean merge method_s min minus modifying move much n nearest network node_ nominal normalize normalizes _not notation object__ _ok_ one_ _only opengl opposite optimization ordering outputs outside overall parameterized partial phase placed places positions possibly post probability problem processes projection proper push pushed puts r rate ratio recursively reduce reduced refers reflect rely removing require reserved respectively responsibility routine runs sample say scheme score segments selects separated set_ shifted signatures significant size_ sizes skip slow smaller sort sorts split square statistics step steps stores strict string__ sub subset sufficient surrounding symbols t term terminate themselves todo too track tracked transformed translation treat trees true_ v various vectors vertices weight weights widths word wrap
}
Original
import edu.columbia.cs.pablo.match.MatchedText;
import edu.columbia.cs.pablo.contsel.SelectionDatum;
import edu.columbia.cs.pablo.langmod.LanguageModel;
import edu.columbia.cs.pablo.data.FrameData;
import edu.columbia.cs.pablo.data.FrameObject;
import edu.columbia.cs.pablo.refexpr.Dictionary;
import edu.columbia.cs.pablo.util.Counter;
import java.io.Serializable;
import java.io.ObjectOutputStream;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.Collections;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Iterator;
public class BayesDisambiguator{
public static double SMOOTH=HMMTagger.SMOOTH;
public int numberOfClasses;
public double[]priors;
public Map weights; // token to array of double
public BayesDisambiguator(int numberOfClasses){
this.numberOfClasses=numberOfClasses;
this.weights=new HashMap();
this.priors=new double[numberOfClasses];
}
public void train(Object token,int tag){
priors[tag]++;
if(weights.containsKey(token))
((double[])weights.get(token))[tag]++;
else{
double[]w=new double[numberOfClasses];w[tag]=1;
for(int i=0;i<numberOfClasses;i++){
priors[i]+=SMOOTH;
w[i]=SMOOTH;
}
w[tag]+=1;
weights.put(token,w);
}
}
public void normalize(){
double totalCount=0;
for(int i=0;i<numberOfClasses;i++)
totalCount+=priors[i];
totalCount=Math.log(totalCount);
for(int i=0;i<numberOfClasses;i++)
priors[i]=Math.log(priors[i]);
Iterator v=weights.values().iterator();
while(v.hasNext()){
double[]w=(double[])v.next();
for(int i=0;i<numberOfClasses;i++)
w[i]=Math.log(w[i])-priors[i];
}
// priors
for(int i=0;i<numberOfClasses;i++)
priors[i]-=totalCount;
}
public int predict(Object[]tokens){
double[]predict=this.fullPredict(tokens);
double max=Double.NEGATIVE_INFINITY;
int result=0;
for(int i=0;i<predict.length;i++)
if(predict[i]>max){
max=predict[i];
result=i;
}
//System.err.println("Predict: "+Arrays.asList(tokens).toString()+" 0="+predict[0]+
// " 1="+predict[1]);
return result;
}
public double[]fullPredict(Object[]tokens){
double[]result=new double[numberOfClasses];
//System.arraycopy(priors,0,predict,0,numberOfClasses);
for(int i=0;i<tokens.length;i++)
if(weights.containsKey(tokens[i])){
double[]w=(double[])weights.get(tokens[i]);
for(int j=0;j<result.length;j++)
result[j]+=w[j];
}
return result;
}
}