TreebankFormatParser { public static String[] splitSentences(String mrgContents) { String[] contents = mrgContents.split("(?=\\(\\s*\\()"); if (contents.length > 1) { if (contents.length > 0 && contents[0].trim().equals("")) { String[] returnValues = new String[contents.length - 1]; System.arraycopy(contents, 1, returnValues, 0, returnValues.length); return returnValues; } else { String[] returnValues = new String[contents.length]; System.arraycopy(contents, 0, returnValues, 0, returnValues.length); return returnValues; } } String[] lines = mrgContents.split("\r?\n"); for (String line : lines) { if (!parensMatch(line)) { throw new IllegalArgumentException( "Parentheses counts do not match for treebank sentence: " + line); } } return lines; }  static TreebankNode getLeafNode(String parseFragment); static String getType(String parseFragment); static String prepareString(String parse); static String inferPlainText(String treebankText); static TopTreebankNode parse(String parse); static TopTreebankNode parse(String parse, String text, int textOffset); static int movePastWhiteSpaceChars(String text, int textOffset); static String[] splitSentences(String mrgContents); static boolean parensMatch(String contents); static List<TopTreebankNode> parseDocument(String parse, int textOffset, String text); static final String LEAF_NODE_REGEX; static final String TYPE_REGEX; static final String cleanUPRegex1; static final String cleanUPRegex2; static final String cleanUPRegex3; static final String cleanUPRegex4; }
@Test public void testSplitSentences() throws IOException { String[] sentences = TreebankFormatParser.splitSentences(FileUtils.file2String(new File( "src/test/resources/data/treebank/11597317.tree"))); assertEquals(99, sentences.length); sentences = TreebankFormatParser.splitSentences(FileUtils.file2String(new File( "src/test/resources/data/treebank/12079497.tree"))); assertEquals(149, sentences.length); sentences = TreebankFormatParser.splitSentences(FileUtils.file2String(new File( "src/test/resources/data/treebank/12546709.tree"))); assertEquals(243, sentences.length); sentences = TreebankFormatParser.splitSentences(FileUtils.file2String(new File( "src/test/resources/data/treebank/12585968.tree"))); assertEquals(283, sentences.length); sentences = TreebankFormatParser.splitSentences("()\n()"); assertEquals(2, sentences.length); sentences = TreebankFormatParser.splitSentences("()\n()\r\n(NN train)"); assertEquals(3, sentences.length); IllegalArgumentException iae = null; try { sentences = TreebankFormatParser.splitSentences("())"); } catch (IllegalArgumentException e) { iae = e; } assertNotNull(iae); }