TreebankFormatParser { public static boolean parensMatch(String contents) { int leftParenCount = 0; int rightParenCount = 0; for (char c : contents.toCharArray()) { if (c == '(') leftParenCount++; if (c == ')') rightParenCount++; } return leftParenCount == rightParenCount; }  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 testMatchingParens() { assertTrue(TreebankFormatParser.parensMatch("(((())))")); assertFalse(TreebankFormatParser.parensMatch("((())))")); assertTrue(TreebankFormatParser .parensMatch("( (S (NP-SBJ-1 (DT The) (NN striatum)) (VP (VBZ plays) (NP (DT a) (JJ pivotal) (NN role)) (PP (IN in) (S-NOM (NP-SBJ-1 (-NONE- *PRO*)) (VP (VBG modulating) (NP (NP (NN motor) (NN activity)) (CC and) (NP (JJR higher) (JJ cognitive) (NN function))))))) (. .)) )")); assertFalse(TreebankFormatParser .parensMatch("(NP-SBJ-1 (DT The) (NN striatum)) (VP (VBZ plays) (NP (DT a) (JJ pivotal) (NN role)) (PP (IN in) (S-NOM (NP-SBJ-1 (-NONE- *PRO*)) (VP (VBG modulating) (NP (NP (NN motor) (NN activity)) (CC and) (NP (JJR higher) (JJ cognitive) (NN function))))))) (. .)) )")); }