|
2 | 2 |
|
3 | 3 | import java.util.Arrays;
|
4 | 4 |
|
5 |
| -import junit.framework.TestCase; |
| 5 | +import org.junit.Assert; |
| 6 | +import org.junit.Test; |
6 | 7 |
|
7 | 8 | import edu.stanford.nlp.ling.BasicDatum;
|
8 | 9 | import edu.stanford.nlp.util.Pair;
|
9 | 10 |
|
10 |
| - |
11 | 11 | /**
|
12 | 12 | * @author Christopher Manning
|
13 | 13 | */
|
14 |
| -public class GeneralDatasetTest extends TestCase { |
| 14 | +public class GeneralDatasetTest { |
15 | 15 |
|
16 |
| - public static void testCreateFolds() { |
| 16 | + @Test |
| 17 | + public void testCreateFolds() { |
17 | 18 | GeneralDataset<String, String> data = new Dataset<>();
|
18 |
| - data.add(new BasicDatum<String, String>(Arrays.asList(new String[]{"fever", "cough", "congestion"}), "cold")); |
19 |
| - data.add(new BasicDatum<String, String>(Arrays.asList(new String[]{"fever", "cough", "nausea"}), "flu")); |
20 |
| - data.add(new BasicDatum<String, String>(Arrays.asList(new String[]{"cough", "congestion"}), "cold")); |
21 |
| - data.add(new BasicDatum<String, String>(Arrays.asList(new String[]{"cough", "congestion"}), "cold")); |
22 |
| - data.add(new BasicDatum<String, String>(Arrays.asList(new String[]{"fever", "nausea"}), "flu")); |
23 |
| - data.add(new BasicDatum<String, String>(Arrays.asList(new String[]{"cough", "sore throat"}), "cold")); |
| 19 | + data.add(new BasicDatum<>(Arrays.asList(new String[]{"fever", "cough", "congestion"}), "cold")); |
| 20 | + data.add(new BasicDatum<>(Arrays.asList(new String[]{"fever", "cough", "nausea"}), "flu")); |
| 21 | + data.add(new BasicDatum<>(Arrays.asList(new String[]{"cough", "congestion"}), "cold")); |
| 22 | + data.add(new BasicDatum<>(Arrays.asList(new String[]{"cough", "congestion"}), "cold")); |
| 23 | + data.add(new BasicDatum<>(Arrays.asList(new String[]{"fever", "nausea"}), "flu")); |
| 24 | + data.add(new BasicDatum<>(Arrays.asList(new String[]{"cough", "sore throat"}), "cold")); |
24 | 25 |
|
25 | 26 | Pair<GeneralDataset<String,String>,GeneralDataset<String,String>> devTrainTest =
|
26 | 27 | data.split(3, 5);
|
27 |
| - assertEquals(4, devTrainTest.first().size()); |
28 |
| - assertEquals(2, devTrainTest.second().size()); |
29 |
| - assertEquals("cold", devTrainTest.first().getDatum(devTrainTest.first().size() - 1).label()); |
30 |
| - assertEquals("flu", devTrainTest.second().getDatum(devTrainTest.second().size() - 1).label()); |
| 28 | + Assert.assertEquals(4, devTrainTest.first().size()); |
| 29 | + Assert.assertEquals(2, devTrainTest.second().size()); |
| 30 | + Assert.assertEquals("cold", devTrainTest.first().getDatum(devTrainTest.first().size() - 1).label()); |
| 31 | + Assert.assertEquals("flu", devTrainTest.second().getDatum(devTrainTest.second().size() - 1).label()); |
31 | 32 |
|
32 | 33 | Pair<GeneralDataset<String,String>,GeneralDataset<String,String>> devTrainTest2 =
|
33 | 34 | data.split(0,2);
|
34 |
| - assertEquals(4, devTrainTest2.first().size()); |
35 |
| - assertEquals(2, devTrainTest2.second().size()); |
| 35 | + Assert.assertEquals(4, devTrainTest2.first().size()); |
| 36 | + Assert.assertEquals(2, devTrainTest2.second().size()); |
36 | 37 |
|
37 | 38 | Pair<GeneralDataset<String,String>,GeneralDataset<String,String>> devTrainTest3 =
|
38 | 39 | data.split(1.0/3.0);
|
39 |
| - assertEquals(devTrainTest2.first().size(), devTrainTest3.first().size()); |
40 |
| - assertEquals(devTrainTest2.first().labelIndex(), devTrainTest3.first().labelIndex()); |
41 |
| - assertEquals(devTrainTest2.second().size(), devTrainTest3.second().size()); |
42 |
| - assertTrue(Arrays.equals(devTrainTest2.first().labels, devTrainTest2.first().labels)); |
43 |
| - assertTrue(Arrays.equals(devTrainTest2.second().labels, devTrainTest2.second().labels)); |
| 40 | + Assert.assertEquals(devTrainTest2.first().size(), devTrainTest3.first().size()); |
| 41 | + Assert.assertEquals(devTrainTest2.first().labelIndex(), devTrainTest3.first().labelIndex()); |
| 42 | + Assert.assertEquals(devTrainTest2.second().size(), devTrainTest3.second().size()); |
| 43 | + Assert.assertArrayEquals(devTrainTest2.first().labels, devTrainTest2.first().labels); |
| 44 | + Assert.assertArrayEquals(devTrainTest2.second().labels, devTrainTest2.second().labels); |
44 | 45 |
|
45 |
| - data.add(new BasicDatum<String, String>(Arrays.asList(new String[]{"fever", "nausea"}), "flu")); |
| 46 | + data.add(new BasicDatum<>(Arrays.asList(new String[]{"fever", "nausea"}), "flu")); |
46 | 47 |
|
47 | 48 | Pair<GeneralDataset<String,String>,GeneralDataset<String,String>> devTrainTest4 =
|
48 | 49 | data.split(1.0/3.0);
|
49 |
| - assertEquals(5, devTrainTest4.first().size()); |
50 |
| - assertEquals(2, devTrainTest4.second().size()); |
| 50 | + Assert.assertEquals(5, devTrainTest4.first().size()); |
| 51 | + Assert.assertEquals(2, devTrainTest4.second().size()); |
51 | 52 |
|
52 | 53 | Pair<GeneralDataset<String,String>,GeneralDataset<String,String>> devTrainTest5 =
|
53 | 54 | data.split(1.0/8.0);
|
54 |
| - assertEquals(7, devTrainTest5.first().size()); |
55 |
| - assertEquals(0, devTrainTest5.second().size()); |
| 55 | + Assert.assertEquals(7, devTrainTest5.first().size()); |
| 56 | + Assert.assertEquals(0, devTrainTest5.second().size()); |
56 | 57 |
|
57 |
| - // Sonal did this, but I think she got it wrong and either should have past in test ratio or have taken p.second() |
| 58 | + // Sonal did this, but I think she got it wrong and either should have passed in test ratio or have taken p.second() |
58 | 59 | // double trainRatio = 0.9;
|
59 | 60 | // Pair<GeneralDataset<String,String>,GeneralDataset<String,String>> p = data.split(0, (int) Math.floor(data.size() * trainRatio));
|
60 | 61 | // assertEquals(6, p.first().size());
|
|
0 commit comments