-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a brief test of the subtree output tool
- Loading branch information
1 parent
73f0dbd
commit 613887a
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package edu.stanford.nlp.trees; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import edu.stanford.nlp.io.IOUtils; | ||
|
||
public class OutputSubtreesTest { | ||
public Path tmpDir; | ||
|
||
@Before | ||
public void makeTmpDir() throws IOException { | ||
tmpDir = Files.createTempDirectory("output"); | ||
tmpDir.toFile().deleteOnExit(); | ||
} | ||
|
||
String[] EXPECTED = {"1 In this case zero .", | ||
"2 In this", | ||
"2 In", | ||
"2 this", | ||
"1 case zero .", | ||
"2 case", | ||
"1 zero .", | ||
"1 zero", | ||
"2 ."}; | ||
|
||
|
||
@Test | ||
public void testSingleTree() throws IOException { | ||
String inputFilename = tmpDir + File.separator + "input.txt"; | ||
IOUtils.writeStringToFile("(1 (2 (2 In) (2 this)) (1 (2 case) (1 (1 zero) (2 .))))", inputFilename, "utf-8"); | ||
|
||
String outputFilename = tmpDir + File.separator + "output.txt"; | ||
String[] args = {"-input", inputFilename, "-output", outputFilename}; | ||
OutputSubtrees.main(args); | ||
|
||
String[] results = IOUtils.slurpFile(outputFilename).trim().split("\n"); | ||
assertArrayEquals(EXPECTED, results); | ||
} | ||
} |