Skip to content

Commit dba0752

Browse files
committed
refactor
1 parent ccc185f commit dba0752

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

itest/src/edu/stanford/nlp/parser/nndep/DependencyParserITest.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import java.io.File;
77
import java.io.IOException;
8+
import java.nio.file.Files;
9+
import java.nio.file.Paths;
810
import java.util.Collection;
911
import java.util.List;
1012
import java.util.Properties;
@@ -37,20 +39,30 @@
3739
*/
3840
public class DependencyParserITest {
3941

40-
@Test
41-
public void testEnglishOnWSJDev() {
42-
Properties props = new Properties();
43-
props.put("testFile", String.format("%s/depparser/nn/benchmark/wsj-dev.conllu", TestPaths.testHome()));
44-
props.put("model", "edu/stanford/nlp/models/parser/nndep/english_UD.gz");
45-
props.put("outFile", "tmp.conll");
42+
public void runDepparseTest(Properties props, double uasThreshold, double lasThreshold) {
4643
DependencyParser parser = new DependencyParser(props);
4744
parser.loadModelFile(props.getProperty("model"));
4845
Pair<Double, Double> scores =
4946
parser.testCoNLLReturnScores(props.getProperty("testFile"), props.getProperty("outFile"));
5047
double uas = scores.first;
5148
double las = scores.second;
52-
assertTrue(uas >= 93.4);
53-
assertTrue(las >= 91.9);
49+
assertTrue(uas >= uasThreshold);
50+
assertTrue(las >= lasThreshold);
51+
// clean up after test
52+
try {
53+
Files.deleteIfExists(Paths.get("tmp.conll"));
54+
} catch (IOException e) {
55+
System.err.println("Error with removing tmp.conll");
56+
}
57+
}
58+
59+
@Test
60+
public void testEnglishOnWSJDev() {
61+
Properties props = new Properties();
62+
props.put("testFile", String.format("%s/depparser/nn/benchmark/wsj-dev.conllu", TestPaths.testHome()));
63+
props.put("model", "edu/stanford/nlp/models/parser/nndep/english_UD.gz");
64+
props.put("outFile", "tmp.conll");
65+
runDepparseTest(props,93.4, 91.9);
5466
}
5567

5668
@Test
@@ -59,14 +71,7 @@ public void testEnglishOnWSJTest() {
5971
props.put("testFile", String.format("%s/depparser/nn/benchmark/wsj-test.conllu", TestPaths.testHome()));
6072
props.put("model", "edu/stanford/nlp/models/parser/nndep/english_UD.gz");
6173
props.put("outFile", "tmp.conll");
62-
DependencyParser parser = new DependencyParser(props);
63-
parser.loadModelFile(props.getProperty("model"));
64-
Pair<Double, Double> scores =
65-
parser.testCoNLLReturnScores(props.getProperty("testFile"), props.getProperty("outFile"));
66-
double uas = scores.first;
67-
double las = scores.second;
68-
assertTrue(uas >= 93.4);
69-
assertTrue(las >= 92.09);
74+
runDepparseTest(props, 93.4, 92.09);
7075
}
7176

7277

0 commit comments

Comments
 (0)