本文整理汇总了Java中org.apache.uima.util.XMLSerializer类的典型用法代码示例。如果您正苦于以下问题:Java XMLSerializer类的具体用法?Java XMLSerializer怎么用?Java XMLSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XMLSerializer类属于org.apache.uima.util包,在下文中一共展示了XMLSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeXmi
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
/**
* Serialize a CAS to a file in XMI format
*
* @param aCas CAS to serialize
* @param name output file
* @throws SAXException
* @throws Exception
* @throws ResourceProcessException
*/
private void writeXmi(CAS aCas, File name) throws IOException,
SAXException {
OutputStream out = null;
try {
// write XMI
out = FileUtils.openOutputStream(name);
// seems like it is not necessary to buffer outputStream for SAX TransformationHandler
// out = new BufferedOutputStream(out);
XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem());
XMLSerializer xmlSer = new XMLSerializer(out, xmlFormatted);
ser.serialize(aCas, xmlSer.getContentHandler());
} finally {
if (out != null) {
out.close();
}
}
}
示例2: testReaderXcas
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
@Test
public void testReaderXcas() throws Exception {
tokenBuilder.buildTokens(jCas, "I like\nspam!", "I like spam !", "PRP VB NN .");
File outputFile = new File(outputDirectory, "test.xcas");
FileOutputStream out = new FileOutputStream(outputFile);
XCASSerializer ser = new XCASSerializer(jCas.getTypeSystem());
XMLSerializer xmlSer = new XMLSerializer(out, false);
ser.serialize(jCas.getCas(), xmlSer.getContentHandler());
CollectionReaderDescription desc = CollectionReaderFactory.createReaderDescription(
XReader.class,
FilesCollectionReader.PARAM_ROOT_FILE,
new File(outputDirectory, "test.xcas").getPath(),
XReader.PARAM_XML_SCHEME,
XReader.XCAS);
jCas = new JCasIterable(desc).iterator().next();
String jCasText = jCas.getDocumentText();
String docText = "I like\nspam!";
Assert.assertEquals(jCasText, docText);
Token token = JCasUtil.selectByIndex(jCas, Token.class, 0);
Assert.assertEquals("I", token.getCoveredText());
}
示例3: writeXmi
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
/**
* Write xmi.
*
* @param aCas the a cas
* @throws IOException Signals that an I/O exception has occurred.
* @throws SAXException the sAX exception
*/
private void writeXmi(CAS aCas) throws IOException, SAXException {
if (outputFile == null) {
outputFile = new File(outputFileName);
if(!outputFile.exists()) { outputFile.createNewFile(); }
}
FileOutputStream out = null;
try {
out = new FileOutputStream(outputFile);
XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem());
XMLSerializer xmlSer = new XMLSerializer(out, true);
ser.serialize(aCas, xmlSer.getContentHandler());
}
finally {
if (out != null) { out.close(); }
}
}
示例4: serialize
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
private static void serialize(JCas jcas, File file) throws SAXException, IOException {
OutputStream outputStream = null;
try {
outputStream = new BufferedOutputStream(new FileOutputStream(file));
XmiCasSerializer xmiSerializer = new XmiCasSerializer(
jcas.getTypeSystem());
XMLSerializer xmlSerializer = new XMLSerializer(outputStream, true);
xmiSerializer.serialize(jcas.getCas(),
xmlSerializer.getContentHandler());
} catch (FileNotFoundException fnfe) {
throw new FileNotFoundException(fnfe.getMessage());
} catch (SAXException saxe) {
throw new SAXException(saxe.getMessage());
} finally {
try {
outputStream.close();
} catch (IOException ioe) {
throw new IOException(ioe.getMessage());
}
}
}
示例5: writeXmi
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
private void writeXmi(CAS aCas, String id) throws IOException, SAXException {
File outFile = new File(outputDirectory, id + ".xmi");
FileOutputStream out = null;
try {
out = new FileOutputStream(outFile);
XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem());
XMLSerializer xmlSer = new XMLSerializer(out, false);
ser.serialize(aCas, xmlSer.getContentHandler());
}
finally {
if (out != null) {
out.close();
}
}
}
示例6: writeXmi
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
/**
* Serialize a CAS to a file in XMI format
*
* @param aCas
* CAS to serialize
* @param name
* output file
* @throws SAXException
* @throws Exception
*
* @throws ResourceProcessException
*/
private void writeXmi(CAS aCas, File name, String modelFileName) throws IOException, SAXException {
FileOutputStream out = null;
try {
// write XMI
out = new FileOutputStream(name);
XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem());
XMLSerializer xmlSer = new XMLSerializer(out, false);
ser.serialize(aCas, xmlSer.getContentHandler());
} finally {
if (out != null) {
out.close();
}
}
}
示例7: serializeCasToXmi
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
/**
* Utility method that handles the XMI serialization
*
* @param jcas
* the CAS that will be serialized
* @param xmiFile
* the output file where the XMI will be stored
* @throws IOException
* if there's an issue writing to the output file
* @throws SAXException
* if there's an issue serializing the CAS
*/
private void serializeCasToXmi(JCas jcas, File xmiFile) throws IOException, SAXException {
Writer writer = FileWriterUtil.initBufferedWriter(xmiFile, CharacterEncoding.UTF_8, WriteMode.OVERWRITE,
FileSuffixEnforcement.OFF);
try {
XmiCasSerializer serializer = new XmiCasSerializer(jcas.getTypeSystem());
XMLSerializer xmlSerializer = new XMLSerializer(writer, false);
serializer.serialize(jcas.getCas(), xmlSerializer.getContentHandler());
} finally {
if (writer != null)
writer.close();
}
}
示例8: writeXmi
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
private void writeXmi(CAS aCas, OutputStream out) throws IOException,
SAXException {
// seems like it is not necessary to buffer outputStream for SAX TransformationHandler
// out = new BufferedOutputStream(out);
XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem());
XMLSerializer xmlSer = new XMLSerializer(out, xmlFormatted);
ser.serialize(aCas, xmlSer.getContentHandler());
}
示例9: serializeCAS
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
static private void serializeCAS(CAS cas, File outFile) throws IOException, SAXException {
OutputStream out = null;
try {
out = FileUtils.openOutputStream(outFile);
XmiCasSerializer xcs = new XmiCasSerializer(cas.getTypeSystem());
XMLSerializer ser = new XMLSerializer(out, true);
xcs.serialize(cas, ser.getContentHandler());
} finally {
IOUtils.closeQuietly(out);
}
}
示例10: call
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
@Override
public String call(String paragraph) throws Exception {
this.jcas.setDocumentText(paragraph);
// final AnalysisEngineDescription aed = getFastPipeline(); // Outputs
// from default and fast pipelines are identical
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SimplePipeline.runPipeline(this.jcas, this.aed);
XmiCasSerializer xmiSerializer = new XmiCasSerializer(jcas.getTypeSystem());
XMLSerializer xmlSerializer = new XMLSerializer(baos, true);
xmiSerializer.serialize(jcas.getCas(),xmlSerializer.getContentHandler());
this.jcas.reset();
return baos.toString("utf-8");
}
示例11: dumpXmi
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
/**
* Dumps the given JCas to a file on disk.
*
* @param xmiFile
* @param jcas
* @throws UimaUtilsException
*/
public static void dumpXmi(File xmiFile, JCas jcas) throws UimaUtilsException {
try {
FileOutputStream out = new FileOutputStream(xmiFile);
XmiCasSerializer ser = new XmiCasSerializer(jcas.getTypeSystem());
XMLSerializer xmlSer = new XMLSerializer(out, false);
ser.serialize(jcas.getCas(), xmlSer.getContentHandler());
out.close();
}
catch (IOException | SAXException e) {
throw new UimaUtilsException(e);
}
}
示例12: writeXCas
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
private void writeXCas(CAS aCas, String fileName) throws IOException, SAXException {
File outFile = new File(outputDirectory, fileName + ".xcas");
FileOutputStream out = null;
try {
out = new FileOutputStream(outFile);
XCASSerializer ser = new XCASSerializer(aCas.getTypeSystem());
XMLSerializer xmlSer = new XMLSerializer(out, false);
ser.serialize(aCas, xmlSer.getContentHandler());
}
finally {
if (out != null) {
out.close();
}
}
}
示例13: zipXCas
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
private void zipXCas(CAS aCas, String fileName) throws IOException,
SAXException {
// create file structure
File outFile = null;
if (dirStructure) {
outFile = new File(outputDirectory,
StructuredDirectory.getFilePath(new Integer(fileName),
"xcas.zip"));
outFile.getParentFile().mkdirs();
} else {
outFile = new File(outputDirectory, fileName + ".xcas.zip");
}
FileOutputStream fos = null;
ZipOutputStream zos = null;
try {
fos = new FileOutputStream(outFile);
zos = new ZipOutputStream(fos);
zos.setLevel(9);
ZipEntry ze = new ZipEntry(fileName + ".xmi");
zos.putNextEntry(ze);
XCASSerializer ser = new XCASSerializer(aCas.getTypeSystem());
XMLSerializer xmlSer = new XMLSerializer(zos, false);
ser.serialize(aCas, xmlSer.getContentHandler());
} finally {
if (zos != null) {
zos.close();
}
}
}
示例14: zipXmi
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
private void zipXmi(CAS aCas, String id) throws IOException, SAXException {
// create file structure
File outFile = null;
if (dirStructure) {
outFile = new File(outputDirectory,
StructuredDirectory.getFilePath(new Integer(id), "xmi.zip"));
outFile.getParentFile().mkdirs();
} else {
outFile = new File(outputDirectory, id + ".xmi.zip");
}
FileOutputStream fos = null;
ZipOutputStream zos = null;
try {
fos = new FileOutputStream(outFile);
zos = new ZipOutputStream(fos);
zos.setLevel(9);
ZipEntry ze = new ZipEntry(id + ".xmi");
zos.putNextEntry(ze);
XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem());
XMLSerializer xmlSer = new XMLSerializer(zos, false);
ser.serialize(aCas, xmlSer.getContentHandler());
} finally {
if (zos != null) {
zos.close();
}
}
}
示例15: writeXmi
import org.apache.uima.util.XMLSerializer; //导入依赖的package包/类
private void writeXmi(CAS aCas, File name, String modelFileName) throws IOException, SAXException {
FileOutputStream out = null;
try {
// write XMI
out = new FileOutputStream(name);
XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem());
XMLSerializer xmlSer = new XMLSerializer(out, false);
ser.serialize(aCas, xmlSer.getContentHandler());
} finally {
if (out != null) {
out.close();
}
}
}