This questions描述了如何在dkpro中重用管道,但是如果我仅创建一个JCas,然后尝试更改文本,则会得到异常org.apache.uima.cas.CASRuntimeException: Data for Sofa feature setLocalSofaData() has already been set.
我该如何解决?
最佳答案
CAS中的沙发数据只能设置一次。设置后无法修改。
为了重新使用CAS,请在其上调用reset()
方法。这将清除所有注释,并允许您再次设置沙发/文字。
为了逐步构建CAS,一种常见的策略是向CAS添加注释,同时将文本添加到字符串缓冲区并仅在过程结束时设置文本。
基于uimaFIT的示例可能如下所示:
Strings[] texts = {
"Hello world.",
"This is a test." };
// Create empty CAS/JCas initialized using uimaFIT typesystem auto-detection
JCas jcas = JCasFactory.createJCas();
// Instantiate some analysis engine
AnalysisEngine engine = AnalysisEngineFactory.createEngine(...);
// Process texts re-using the previously created CAS/JCas instance
for (String t : texts) {
jcas.reset();
jcas.setDocumentText(t);
jcas.setDocumentLanguage("en");
engine.process(jcas);
}
engine.collectionProcessComplete();
engine.destroy();
披露:我正在研究Apache UIMA项目。
关于java - 更改DKPro中可重用管道中的文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37771028/