Blame view

tools/mate-tools/src/is2/data/ParseNBest.java 2.04 KB
Jan Lupa authored
1
2
3
4
5
package is2.data;
Jan Lupa authored
6
final public class ParseNBest extends Parse {
Jan Lupa authored
7
Jan Lupa authored
8
9
10
11
12
13
14

	private String signature=null;

	//public float[] scores;

	public ParseNBest() {}
Jan Lupa authored
15
16
17
	public ParseNBest(short[] heads2, short[] types2, float p_new) {
		super(heads2, types2, p_new);
	}
Jan Lupa authored
18
Jan Lupa authored
19
	public ParseNBest(int i) {
Jan Lupa authored
20
		super(i);		
Jan Lupa authored
21
	}
Jan Lupa authored
22
Jan Lupa authored
23
24
25
26
27
	/**
	 * @param sig
	 * @param readFloat
	 */
	public ParseNBest(String sig, float score) {
Jan Lupa authored
28
		super(sig,score);
Jan Lupa authored
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) {
Jan Lupa authored
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); 

		} 
Jan Lupa authored
44
45
		return -1;
	}
Jan Lupa authored
46
Jan Lupa authored
47
48
49
50
	/**
	 * @return the signature of a parse
	 */
	public String signature() {
Jan Lupa authored
51
52
		if (signature!=null) return signature; 
		signature= super.signature();
Jan Lupa authored
53
54
		return signature;
	}
Jan Lupa authored
55
Jan Lupa authored
56
57
58
59
	/**
	 * @return the signature of a parse
	 */
	public String signature(short[] heads, short[] labels) {
Jan Lupa authored
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]);
Jan Lupa authored
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
	 */
Jan Lupa authored
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]);
Jan Lupa authored
84
85
86
		}
		signature = b.toString();
		return signature;
Jan Lupa authored
87
Jan Lupa authored
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];
Jan Lupa authored
95
Jan Lupa authored
96
97
		System.arraycopy(heads, 0, p.heads, 0, heads.length);
		System.arraycopy(labels, 0, p.labels, 0, labels.length);
Jan Lupa authored
98
99
100

		p.f1=f1;
Jan Lupa authored
101
102
103
		return p;
	}
Jan Lupa authored
104
Jan Lupa authored
105
}
Jan Lupa authored
106
107