|
1 | 1 | package edu.stanford.nlp.ie.crf; |
2 | 2 |
|
| 3 | +import java.nio.file.Files; |
| 4 | +import java.nio.file.Path; |
3 | 5 | import java.io.File; |
4 | 6 | import java.util.List; |
5 | 7 | import java.util.Scanner; |
|
9 | 11 |
|
10 | 12 | import edu.stanford.nlp.io.IOUtils; |
11 | 13 | import edu.stanford.nlp.util.PropertiesUtils; |
| 14 | +import edu.stanford.nlp.util.logging.Redwood; |
12 | 15 | import edu.stanford.nlp.util.logging.StanfordRedwoodConfiguration; |
13 | 16 |
|
14 | 17 |
|
15 | 18 | public class TrainCRFClassifierSlowITest { |
16 | 19 |
|
17 | | - private static final String crfTrainingWorkingDir = "/u/scr/nlp/data/stanford-corenlp-testing/crf-classifier-training"; |
| 20 | + private static final Redwood.RedwoodChannels log = Redwood.channels(TrainCRFClassifierSlowITest.class); |
18 | 21 |
|
19 | 22 |
|
20 | | - @SuppressWarnings("ResultOfMethodCallIgnored") |
21 | 23 | @Test |
22 | 24 | public void testGermanCRFClassifierTraining() throws Exception { |
| 25 | + Path tempdir = Files.createTempDirectory("ner"); |
| 26 | + tempdir.toFile().deleteOnExit(); |
| 27 | + log.info("Temp directory: " + tempdir); |
| 28 | + |
23 | 29 | StanfordRedwoodConfiguration.apply(PropertiesUtils.asProperties( |
24 | | - "log.file", crfTrainingWorkingDir + "/german-crf.results")); |
25 | | - // delete the model if present |
26 | | - File originalModelFile = new File(crfTrainingWorkingDir, "german.distsim.crf.ser.gz"); |
27 | | - originalModelFile.delete(); |
| 30 | + "log.file", tempdir + "/german-crf.results")); |
| 31 | + |
28 | 32 | // train the new model |
| 33 | + // requires the german ner model in the classpath |
29 | 34 | CRFClassifier.main(new String[] { |
30 | | - "-props", "edu/stanford/nlp/models/ner/german.distsim.prop", |
31 | | - "-serializeTo", crfTrainingWorkingDir+"/german.distsim.crf.ser.gz" |
| 35 | + "-props", "edu/stanford/nlp/models/ner/german.distsim.prop", |
| 36 | + "-serializeTo", tempdir + "/german.distsim.crf.ser.gz" |
32 | 37 | }); |
33 | | - List<String> germanTrainingResults = IOUtils.linesFromFile(crfTrainingWorkingDir + "/german-crf.results"); |
| 38 | + List<String> germanTrainingResults = IOUtils.linesFromFile(tempdir + "/german-crf.results"); |
34 | 39 | String lastLineOfResults = germanTrainingResults.get(germanTrainingResults.size() - 1); |
35 | 40 | Scanner scanner = new Scanner(lastLineOfResults); |
36 | 41 | // ignore word "Totals" |
37 | 42 | scanner.next(); |
38 | 43 | double p = scanner.nextDouble(); |
39 | | - Assert.assertEquals("Precision outside target range", 0.8628, p, 0.001); |
| 44 | + Assert.assertEquals("Precision outside target range", 0.8628, p, 0.002); |
40 | 45 | double r = scanner.nextDouble(); |
41 | | - Assert.assertEquals("Recall outside target range", 0.7406, r, 0.0025); |
| 46 | + Assert.assertEquals("Recall outside target range", 0.7406, r, 0.005); |
42 | 47 | double f1 = scanner.nextDouble(); |
43 | | - Assert.assertEquals("F1 outside target range", 0.7969, f1, 0.001); |
| 48 | + Assert.assertEquals("F1 outside target range", 0.7969, f1, 0.002); |
44 | 49 | } |
45 | 50 |
|
46 | 51 | // Previous results (Totals on CoNLL 2003 testa) |
|
0 commit comments