|
1
2
3
4
5
|
package is2.data;
|
|
6
|
final public class ParseNBest extends Parse {
|
|
7
|
|
|
8
9
10
11
12
13
14
|
private String signature=null;
//public float[] scores;
public ParseNBest() {}
|
|
15
16
17
|
public ParseNBest(short[] heads2, short[] types2, float p_new) {
super(heads2, types2, p_new);
}
|
|
18
|
|
|
19
|
public ParseNBest(int i) {
|
|
20
|
super(i);
|
|
21
|
}
|
|
22
|
|
|
23
24
25
26
27
|
/**
* @param sig
* @param readFloat
*/
public ParseNBest(String sig, float score) {
|
|
28
|
super(sig,score);
|
|
29
30
31
32
33
34
35
36
|
}
/**
* create a total order to provide replicable deterministic results
* @param o
* @return
*/
public int compareTo(ParseNBest o) {
|
|
37
38
39
40
41
42
43
|
if (f1<o.f1) return 1;
if (f1==o.f1) {
if (signature==null) signature=signature();
if (o.signature==null) o.signature=o.signature();
return o.signature.compareTo(signature);
}
|
|
44
45
|
return -1;
}
|
|
46
|
|
|
47
48
49
50
|
/**
* @return the signature of a parse
*/
public String signature() {
|
|
51
52
|
if (signature!=null) return signature;
signature= super.signature();
|
|
53
54
|
return signature;
}
|
|
55
|
|
|
56
57
58
59
|
/**
* @return the signature of a parse
*/
public String signature(short[] heads, short[] labels) {
|
|
60
61
62
63
|
StringBuilder b = new StringBuilder(heads.length*2);
for(int k=0;k<heads.length;k++) {
b.append((char)heads[k]).
append((char)labels[k]);
|
|
64
65
66
67
68
69
70
71
72
73
74
75
|
}
signature = b.toString();
return signature;
}
/**
* @param heads
* @param types
* @param oldP
* @param ch
* @param s
*/
|
|
76
77
78
79
80
81
82
83
|
public String signature(short[] heads, short[] types, short p, short ch,short l) {
StringBuilder b = new StringBuilder(heads.length*2);
for(int k=0;k<heads.length;k++) {
b.append(k==ch?(char)p:
(char)heads[k]).
append(k==ch?(char)l:(char)types[k]);
|
|
84
85
86
|
}
signature = b.toString();
return signature;
|
|
87
|
|
|
88
89
90
91
92
93
94
|
}
@Override
public Parse clone() {
ParseNBest p = new ParseNBest();
p.heads = new short[heads.length];
p.labels = new short[labels.length];
|
|
95
|
|
|
96
97
|
System.arraycopy(heads, 0, p.heads, 0, heads.length);
System.arraycopy(labels, 0, p.labels, 0, labels.length);
|
|
98
99
100
|
p.f1=f1;
|
|
101
102
103
|
return p;
}
|
|
104
|
|
|
105
|
}
|
|
106
107
|
|