HeadRules implements opennlp.tools.parser.HeadRules, GapLabeler { public void serialize(Writer writer) throws IOException { for (String type : headRules.keySet()) { HeadRule headRule = headRules.get(type); writer.write(Integer.toString(headRule.tags.length + 2)); writer.write(' '); writer.write(type); writer.write(' '); if (headRule.leftToRight) writer.write("1"); else writer.write("0"); for (String tag : headRule.tags) { writer.write(' '); writer.write(tag); } writer.write('\n'); } writer.flush(); } @Deprecated  HeadRules(String ruleFile);  HeadRules(Reader rulesReader); Set<String> getPunctuationTags(); Parse getHead(Parse[] constituents, String type); void labelGaps(Stack<Constituent> stack); void serialize(Writer writer); @Override boolean equals(Object obj);  }
@Test public void testSerialization() throws IOException { InputStream headRulesIn = HeadRulesTest.class.getResourceAsStream("/opennlp/tools/parser/en_head_rules"); HeadRules headRulesOrginal = new HeadRules(new InputStreamReader(headRulesIn, "UTF-8")); ByteArrayOutputStream out = new ByteArrayOutputStream(); headRulesOrginal.serialize(new OutputStreamWriter(out, "UTF-8")); out.close(); HeadRules headRulesRecreated = new HeadRules(new InputStreamReader( new ByteArrayInputStream(out.toByteArray()), "UTF-8")); assertEquals(headRulesOrginal, headRulesRecreated); }