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