TreebankFormatParser { public static TreebankNode getLeafNode(String parseFragment) { Matcher leafNodeMatcher = leafNodePattern.matcher(parseFragment); if (leafNodeMatcher.matches()) { String type = leafNodeMatcher.group(1); String value = leafNodeMatcher.group(2); TreebankNode node = new TreebankNode(); node.setType(getTypeFromType(type)); node.setTags(getTagsFromType(type)); node.setValue(value); node.setLeaf(true); String token = getToken(node.getValue(), node.getType()); node.setText(token); return node; } return null; }  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 testGetLeafNode() { TreebankNode node = TreebankFormatParser.getLeafNode("(NNP Nov.)"); assertEquals("NNP", node.getType()); assertEquals("Nov.", node.getValue()); assertEquals("Nov.", node.getText()); assertTrue(node.isLeaf()); node = TreebankFormatParser.getLeafNode("(NNP Nov.))"); assertEquals(null, node); node = TreebankFormatParser.getLeafNode("(QP ($ $) (CD 250) (CD million) )"); assertEquals(null, node); node = TreebankFormatParser.getLeafNode("($ $)"); assertEquals("$", node.getType()); assertEquals("$", node.getValue()); assertEquals("$", node.getText()); node = TreebankFormatParser.getLeafNode("(CD 3\\/8)"); assertEquals("CD", node.getType()); assertEquals("3\\/8", node.getValue()); assertEquals("3/8", node.getText()); node = TreebankFormatParser.getLeafNode("(-NONE- *)"); assertEquals("-NONE-", node.getType()); assertEquals("*", node.getValue()); assertEquals("", node.getText()); node = TreebankFormatParser.getLeafNode("(-NONE- *-1)"); assertEquals("-NONE-", node.getType()); assertEquals("*-1", node.getValue()); assertEquals("", node.getText()); node = TreebankFormatParser.getLeafNode("(-LRB- -LCB-)"); assertEquals("-LRB-", node.getType()); assertEquals("-LCB-", node.getValue()); assertEquals("{", node.getText()); node = TreebankFormatParser.getLeafNode("(-LRB- -LRB-)"); assertEquals("(", node.getText()); node = TreebankFormatParser.getLeafNode("(-LRB- -LSB-)"); assertEquals("[", node.getText()); node = TreebankFormatParser.getLeafNode("(-RRB- -RCB-)"); assertEquals("-RRB-", node.getType()); assertEquals("-RCB-", node.getValue()); assertEquals("}", node.getText()); node = TreebankFormatParser.getLeafNode("(-RRB- -RRB-)"); assertEquals(")", node.getText()); node = TreebankFormatParser.getLeafNode("(-RRB- -RSB-)"); assertEquals("]", node.getText()); node = TreebankFormatParser.getLeafNode("(ASDF)"); assertEquals(null, node); node = TreebankFormatParser.getLeafNode("(ASDF )"); assertEquals(null, node); node = TreebankFormatParser.getLeafNode("(NN Complex )"); assertEquals("NN", node.getType()); assertEquals("Complex", node.getValue()); assertEquals("Complex", node.getText()); assertTrue(node.isLeaf()); node = TreebankFormatParser.getLeafNode("(IN ± )"); assertEquals("IN", node.getType()); assertEquals("±", node.getValue()); assertEquals("±", node.getText()); assertTrue(node.isLeaf()); node = TreebankFormatParser.getLeafNode("(CC +\\/-)"); assertEquals("CC", node.getType()); assertEquals("+\\/-", node.getValue()); assertEquals("+/-", node.getText()); assertTrue(node.isLeaf()); }