-
Notifications
You must be signed in to change notification settings - Fork 4
/
ModelTest.java
66 lines (53 loc) · 2.2 KB
/
ModelTest.java
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
package kenlm;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
public class ModelTest {
private Model model;
@Before
public void setUp() {
model = new Model("test.arpa", new Config());
}
@After
public void tearDown() {
model.close();
}
@Test
public void testScore() {
Assert.assertEquals(-49.579346, model.score("this is a sentence .", true, true), 0.000001);
}
@Test
public void testFullScores() {
List<FullScoreReturn> returns = model.fullScores("this is a sentence .", true, true);
Assert.assertEquals(6, returns.size());
Assert.assertEquals(-2.4106083, returns.get(0).getLogProb(), 0.0000001);
Assert.assertEquals(1, returns.get(0).getNgramLength());
Assert.assertEquals(-21.6878719329834, returns.get(1).getLogProb(), 0.0000001);
Assert.assertEquals(1, returns.get(1).getNgramLength());
Assert.assertEquals(-1.5869710445404053, returns.get(2).getLogProb(), 0.0000001);
Assert.assertEquals(1, returns.get(2).getNgramLength());
Assert.assertEquals(-2.6946051120758057, returns.get(3).getLogProb(), 0.0000001);
Assert.assertEquals(1, returns.get(3).getNgramLength());
Assert.assertEquals(-21.139057159423828, returns.get(4).getLogProb(), 0.0000001);
Assert.assertEquals(1, returns.get(4).getNgramLength());
Assert.assertEquals(-0.060235898941755295, returns.get(5).getLogProb(), 0.0000001);
Assert.assertEquals(2, returns.get(5).getNgramLength());
}
@Test
public void testBaseScore() {
State state = new State();
State state1 = new State();
model.beginSentenceWrite(state);
float accum = 0;
accum += model.baseScore(state, "a", state1);
State.swap(state, state1);
accum += model.baseScore(state, "sentence", state1);
State.swap(state, state1);
Assert.assertEquals(model.score("a sentence", true, false), accum, 1e-3);
accum += model.baseScore(state, "</s>", state1);
State.swap(state, state1);
Assert.assertEquals(model.score("a sentence", true, true), accum, 1e-3);
}
}