本文整理汇总了Java中org.apache.uima.cas.impl.XmiCasSerializer类的典型用法代码示例。如果您正苦于以下问题:Java XmiCasSerializer类的具体用法?Java XmiCasSerializer怎么用?Java XmiCasSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XmiCasSerializer类属于org.apache.uima.cas.impl包,在下文中一共展示了XmiCasSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的package包/类
@Override
public void process(CAS aCAS) throws AnalysisEngineProcessException {
Type documentIdType = aCAS.getTypeSystem()
.getType("edu.umn.biomedicus.uima.type1_5.DocumentId");
Feature docIdFeat = documentIdType.getFeatureByBaseName("documentId");
String documentId = aCAS.getIndexRepository()
.getAllIndexedFS(documentIdType)
.get()
.getStringValue(docIdFeat);
if (documentId == null) {
documentId = UUID.randomUUID().toString();
}
GridFSInputFile file = gridFS.createFile(documentId + ".xmi");
try (OutputStream outputStream = file.getOutputStream()) {
XmiCasSerializer.serialize(aCAS, outputStream);
} catch (IOException | SAXException e) {
throw new AnalysisEngineProcessException(e);
}
}
示例2: writeXmi
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的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();
}
}
}
示例3: run
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的package包/类
private void run() throws ResourceInitializationException, IOException, SAXException {
Collection<File> inputFiles =
FileUtils.listFiles(inputDir, FileFilterUtils.suffixFileFilter(".xml"), null);
if (inputFiles.isEmpty()) {
return;
}
TypeSystemDescription tsd = TypeSystemDescriptionFactory
.createTypeSystemDescription(typeSystemDescName);
CAS cas = CasCreationUtils.createCas(tsd, null, null);
for (File inputFile : inputFiles) {
AXMLReader.read(inputFile, cas);
File outFile = getOutputFile(inputFile);
OutputStream out = FileUtils.openOutputStream(outFile);
try {
XmiCasSerializer.serialize(cas, null, out, true, null);
} finally {
out.close();
cas.reset();
}
}
}
示例4: process
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的package包/类
@Override
public void process(JCas aJCas)
throws AnalysisEngineProcessException
{
try (OutputStream docOS = getOutputStream(aJCas, ".xmi")) {
XmiCasSerializer.serialize(aJCas.getCas(), null, docOS, prettyPrint, null);
if (!typeSystemWritten || typeSystemFile == null) {
writeTypeSystem(aJCas);
typeSystemWritten = true;
}
}
catch (Exception e) {
throw new AnalysisEngineProcessException(e);
}
}
示例5: writeXmi
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的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(); }
}
}
示例6: serialize
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的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());
}
}
}
示例7: writeXmi
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的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();
}
}
}
示例8: writeXmi
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的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();
}
}
}
示例9: process
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的package包/类
@Override
public void process(JCas aJCas)
throws AnalysisEngineProcessException
{
try {
java.io.ByteArrayOutputStream jCasOutputStream = new java.io.ByteArrayOutputStream();
XmiCasSerializer.serialize(aJCas.getCas(), jCasOutputStream);
// get name = id + .xmi
String singleEntryName = DocumentMetaData.get(aJCas).getDocumentId() + ".xmi";
// convert output stream to input stream
// InputStream inputStream = new ByteArrayInputStream(jCasOutputStream.toByteArray());
// add to the tar
addSingleEntryToTar(jCasOutputStream.toByteArray(), singleEntryName);
if (!typeSystemWritten) {
writeTypeSystem(aJCas);
typeSystemWritten = true;
}
counter++;
}
catch (IOException | SAXException ex) {
throw new AnalysisEngineProcessException(ex);
}
}
示例10: setJCas
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的package包/类
public void setJCas(JCas jCas)
throws IOException
{
// now convert to XMI
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
try {
XmiCasSerializer.serialize(jCas.getCas(), byteOutputStream);
}
catch (SAXException e) {
throw new IOException(e);
}
// encode to base64
this.base64JCas = new BASE64Encoder().encode(byteOutputStream.toByteArray());
}
示例11: serializeCasToXmi
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的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();
}
}
示例12: writeXmi
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的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());
}
示例13: serializeCAS
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的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);
}
}
示例14: call
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的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");
}
示例15: toXMICas
import org.apache.uima.cas.impl.XmiCasSerializer; //导入依赖的package包/类
public JCas toXMICas(JCas cas, Path filePath) {
try {
logger.debug("Exporting CAS to {}", filePath);
XmiCasSerializer.serialize(cas.getCas(), new FileOutputStream(makeParentDirs(filePath).toFile()));
logger.debug("XMI CAS export succeeded");
return cas;
} catch (FileNotFoundException | SAXException e) {
throw new TermSuiteException(e);
}
}