/** * Parses the specified tree-bank style parse string and return a Parse structure for that string. * * @param parse A tree-bank style parse string. * * @return a Parse structure for the specified tree-bank style parse string. */ public static Parse parseParse(String parse) { return parseParse(parse,null); }
public Parse read() throws IOException { StringBuilder parseString = new StringBuilder(); while (true) { String parse = samples.read(); if (parse != null) { parse = parse.trim(); } if (parse == null || parse.isEmpty()) { if (parseString.length() > 0) { return Parse.parseParse(parseString.toString()); } else { return null; } } parseString.append(parse).append(" "); } } }
public Parse read() throws IOException { String parse = samples.read(); if (parse != null) { if (!parse.trim().isEmpty()) { return Parse.parseParse(parse); } else { return read(); } } else { return null; } } }
@Test public void testShow() { Parse p1 = Parse.parseParse(PARSE_STRING); StringBuffer parseString = new StringBuffer(); p1.show(parseString); Parse p2 = Parse.parseParse(parseString.toString()); Assert.assertEquals(p1, p2); }
@Test public void testTokenReplacement() { Parse p1 = Parse.parseParse("(TOP (S-CLF (NP-SBJ (PRP It) )(VP (VBD was) " + " (NP-PRD (NP (DT the) (NN trial) )(PP (IN of) " + " (NP (NP (NN oleomargarine) (NN heir) )(NP (NNP Minot) " + " (PRN (-LRB- -LRB-) (NNP Mickey) " + " (-RRB- -RRB-) )(NNP Jelke) )))(PP (IN for) " + " (NP (JJ compulsory) (NN prostitution) " + " ))(PP-LOC (IN in) (NP (NNP New) (NNP York) " + " )))(SBAR (WHNP-1 (WDT that) )(S (VP (VBD put) " + " (NP (DT the) (NN spotlight) )(PP (IN on) (NP (DT the) " + " (JJ international) (NN play-girl) ))))))(. .) ))"); StringBuffer parseString = new StringBuffer(); p1.show(parseString); Parse p2 = Parse.parseParse(parseString.toString()); Assert.assertEquals(p1, p2); }
@Test public void testToHashCode() { Parse p1 = Parse.parseParse(PARSE_STRING); p1.hashCode(); }
@Test public void testToString() { Parse p1 = Parse.parseParse(PARSE_STRING); p1.toString(); }
@Test public void testEquals() { Parse p1 = Parse.parseParse(PARSE_STRING); Assert.assertTrue(p1.equals(p1)); }
@Test public void testGetText() { Parse p = Parse.parseParse(PARSE_STRING); // TODO: Why does parse attaches a space to the end of the text ??? String expectedText = "She was just another freighter from the States , " + "and she seemed as commonplace as her name . "; Assert.assertEquals(expectedText, p.getText()); }
/** * Verify that training and tagging does not cause * runtime problems. */ @Test public void testTreeInsertParserTraining() throws Exception { ObjectStream<Parse> parseSamples = ParserTestUtil.openTestTrainingData(); HeadRules headRules = ParserTestUtil.createTestHeadRules(); ParserModel model = Parser.train("eng", parseSamples, headRules, 100, 0); opennlp.tools.parser.Parser parser = ParserFactory.create(model); // Tests parsing to make sure the code does not has // a bug which fails always with a runtime exception parser.parse(Parse.parseParse("She was just another freighter from the " + "States and she seemed as commonplace as her name .")); // Test serializing and de-serializing model ByteArrayOutputStream outArray = new ByteArrayOutputStream(); model.serialize(outArray); outArray.close(); new ParserModel(new ByteArrayInputStream(outArray.toByteArray())); // TODO: compare both models } }
/** * Parses the specified tree-bank style parse string and return a Parse structure for that string. * * @param parse A tree-bank style parse string. * * @return a Parse structure for the specified tree-bank style parse string. */ public static Parse parseParse(String parse) { return parseParse(parse,null); }
/** * Parses the specified tree-bank style parse string and return a Parse structure for that string. * * @param parse A tree-bank style parse string. * * @return a Parse structure for the specified tree-bank style parse string. */ public static Parse parseParse(String parse) { return parseParse(parse,null); }
@Test public void testParseClone() { Parse p1 = Parse.parseParse(PARSE_STRING); Parse p2 = (Parse) p1.clone(); Assert.assertTrue(p1.equals(p2)); Assert.assertTrue(p2.equals(p1)); }
public static CorefSample parse(String corefSampleString) { List<Parse> parses = new ArrayList<Parse>(); for (String line : corefSampleString.split("\\r?\\n")) { parses.add(Parse.parseParse(line)); } return new CorefSample(parses); } }
public static CorefSample parse(String corefSampleString) { List<Parse> parses = new ArrayList<Parse>(); for (String line : corefSampleString.split("\\r?\\n")) { parses.add(Parse.parseParse(line)); } return new CorefSample(parses); } }
public Parse read() throws IOException { StringBuilder parseString = new StringBuilder(); while (true) { String parse = samples.read(); if (parse != null) { parse = parse.trim(); } if (parse == null || parse.isEmpty()) { if (parseString.length() > 0) { return Parse.parseParse(parseString.toString()); } else { return null; } } parseString.append(parse).append(" "); } } }
public Parse read() throws IOException { StringBuilder parseString = new StringBuilder(); while (true) { String parse = samples.read(); if (parse != null) { parse = parse.trim(); } if (parse == null || parse.isEmpty()) { if (parseString.length() > 0) { return Parse.parseParse(parseString.toString()); } else { return null; } } parseString.append(parse).append(" "); } } }
public Parse read() throws IOException { String parse = samples.read(); if (parse != null) { if (!parse.trim().isEmpty()) { return Parse.parseParse(parse); } else { return read(); } } else { return null; } } }
public Parse read() throws IOException { String parse = samples.read(); if (parse != null) { if (!parse.trim().isEmpty()) { return Parse.parseParse(parse); } else { return read(); } } else { return null; } } }
@Test public void testGetTagNodes() { Parse p = Parse.parseParse(PARSE_STRING); Parse[] tags = p.getTagNodes(); for (Parse node : tags) { Assert.assertTrue(node.isPosTag()); } Assert.assertEquals("PRP", tags[0].getType()); Assert.assertEquals("VBD", tags[1].getType()); Assert.assertEquals("RB", tags[2].getType()); Assert.assertEquals("DT", tags[3].getType()); Assert.assertEquals("NN", tags[4].getType()); Assert.assertEquals("IN", tags[5].getType()); Assert.assertEquals("DT", tags[6].getType()); Assert.assertEquals("NNPS", tags[7].getType()); Assert.assertEquals(",", tags[8].getType()); Assert.assertEquals("CC", tags[9].getType()); Assert.assertEquals("PRP", tags[10].getType()); Assert.assertEquals("VBD", tags[11].getType()); Assert.assertEquals("RB", tags[12].getType()); Assert.assertEquals("JJ", tags[13].getType()); Assert.assertEquals("IN", tags[14].getType()); Assert.assertEquals("PRP$", tags[15].getType()); Assert.assertEquals("NN", tags[16].getType()); Assert.assertEquals(".", tags[17].getType()); } }