public void serialize(POSModel artifact, OutputStream out) throws IOException { artifact.serialize(out); } }
@Test public void testPOSModelSerializationMaxent() throws IOException { POSModel posModel = POSTaggerMETest.trainPOSModel(ModelType.MAXENT); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { posModel.serialize(out); } finally { out.close(); } POSModel recreatedPosModel = new POSModel(new ByteArrayInputStream(out.toByteArray())); // TODO: add equals to pos model }
@Test public void testPOSModelSerializationPerceptron() throws IOException { POSModel posModel = POSTaggerMETest.trainPOSModel(ModelType.PERCEPTRON); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { posModel.serialize(out); } finally { out.close(); } POSModel recreatedPosModel = new POSModel(new ByteArrayInputStream(out.toByteArray())); // TODO: add equals to pos model } }
public void serialize(POSModel artifact, OutputStream out) throws IOException { artifact.serialize(out); } }
File posModelFile = new File(resourcesFolder.toFile(),"pos-model.bin"); posModel.serialize(posModelFile);
public void serialize(POSModel artifact, OutputStream out) throws IOException { artifact.serialize(out); } }
/** * Serialize the POS model into the NERC model. * @param out the output stream * @throws IOException io exception */ public void serialize(OutputStream out) throws IOException { Writer writer = new BufferedWriter(new OutputStreamWriter(out)); posModel.serialize(out); writer.flush(); }
@Test public void testPOSTaggerWithDefaultFactory() throws IOException { POSDictionary posDict = POSDictionary.create(POSDictionaryTest.class .getResourceAsStream("TagDictionaryCaseSensitive.xml")); POSModel posModel = trainPOSModel(new POSTaggerFactory(null, null, posDict)); POSTaggerFactory factory = posModel.getFactory(); Assert.assertTrue(factory.getTagDictionary() instanceof POSDictionary); Assert.assertTrue(factory.getPOSContextGenerator() != null); Assert.assertTrue(factory.getSequenceValidator() instanceof DefaultPOSSequenceValidator); ByteArrayOutputStream out = new ByteArrayOutputStream(); posModel.serialize(out); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); POSModel fromSerialized = new POSModel(in); factory = fromSerialized.getFactory(); Assert.assertTrue(factory.getTagDictionary() instanceof POSDictionary); Assert.assertTrue(factory.getPOSContextGenerator() != null); Assert.assertTrue(factory.getSequenceValidator() instanceof DefaultPOSSequenceValidator); }
@Test public void testPOSTaggerWithCustomFactory() throws IOException { DummyPOSDictionary posDict = new DummyPOSDictionary( POSDictionary.create(POSDictionaryTest.class .getResourceAsStream("TagDictionaryCaseSensitive.xml"))); POSModel posModel = trainPOSModel(new DummyPOSTaggerFactory(posDict)); POSTaggerFactory factory = posModel.getFactory(); Assert.assertTrue(factory.getTagDictionary() instanceof DummyPOSDictionary); Assert.assertTrue(factory.getPOSContextGenerator() instanceof DummyPOSContextGenerator); Assert.assertTrue(factory.getSequenceValidator() instanceof DummyPOSSequenceValidator); ByteArrayOutputStream out = new ByteArrayOutputStream(); posModel.serialize(out); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); POSModel fromSerialized = new POSModel(in); factory = fromSerialized.getFactory(); Assert.assertTrue(factory.getTagDictionary() instanceof DummyPOSDictionary); Assert.assertTrue(factory.getPOSContextGenerator() instanceof DummyPOSContextGenerator); Assert.assertTrue(factory.getSequenceValidator() instanceof DummyPOSSequenceValidator); }