Hi, CASes can work outside UIMA, no idea why you get this exception.
If you want to fully clone a CAS, an alternative approach would be to serialize the CAS to a binary representation, create a new CAS, and deserialize the original CAS into the new one. Probably much faster even. See [1] and [2] for some code driving the UIMA binary serialization. In your case, serializing to a ByteArrayOutputStream and deserializing from an ByteArrayInputStream seems a good approach. -- Richard [1] https://dkpro-core-asl.googlecode.com/svn/de.tudarmstadt.ukp.dkpro.core-asl/trunk/de.tudarmstadt.ukp.dkpro.core.io.bincas-asl/src/main/java/de/tudarmstadt/ukp/dkpro/core/io/bincas/SerializedCasWriter.java [2] https://dkpro-core-asl.googlecode.com/svn/de.tudarmstadt.ukp.dkpro.core-asl/trunk/de.tudarmstadt.ukp.dkpro.core.io.bincas-asl/src/main/java/de/tudarmstadt/ukp/dkpro/core/io/bincas/SerializedCasReader.java Am 03.06.2013 um 23:49 schrieb Bojan Janisch <[email protected]>: > Hi everyone, > > I'm a german student and currently working at my bachelor > thesis. I'm new to this mailing list so I hope my question > is suitable for you. > > I'm using Genetic Algorithms to create rules which processes / > annotates the JCases. After that, the results are evaluated and > a F-Score is returned which flows into the fitness function of > the genetic algorithm. So I'm only using the JCases for > evaluation and don't need to write them back. > > I already tried the CasCopier.copyCas() method: > > public static JCas copyJCas(JCas aJCas) { > JCas jcas = null; > jcas = JCasFactory.createJCas(UIMATestUtils.readTypeSystem()); > CasCopier.copyCas(aJCas.getCas(), jcas.getCas(), true); > return jcas; > } > > but I'm getting these two exceptions with the following > stacktraces: > > Exception in thread "ECJ Evaluation Thread 0" > java.lang.ArrayIndexOutOfBoundsException: 1015 > at org.apache.uima.jcas.impl.JCasHashMap.put(JCasHashMap.java:139) > at > org.apache.uima.jcas.impl.JCasImpl.putJfsFromCaddr(JCasImpl.java:1035) > at > org.apache.uima.jcas.impl.JCasImpl$JCasFsGenerator.createFS(JCasImpl.java:847) > at org.apache.uima.cas.impl.CASImpl.ll_getFSForRef(CASImpl.java:3117) > at org.apache.uima.cas.impl.CASImpl.createFS(CASImpl.java:1773) > at > org.apache.uima.cas.impl.FeatureStructureImpl.getFeatureValue(FeatureStructureImpl.java:234) > at org.apache.uima.util.CasCopier.copyFeatures(CasCopier.java:312) > at org.apache.uima.util.CasCopier.copyFs(CasCopier.java:190) > at org.apache.uima.util.CasCopier.copyCasView(CasCopier.java:149) > at org.apache.uima.util.CasCopier.copyCas(CasCopier.java:108) > at rulevolution.utils.JCasUtils.copyJCas(JCasUtils.java:80) > at rulevolution.utils.JCasUtils.copyCasPool(JCasUtils.java:94) > at rulevolution.RulEvolution.evaluate(RulEvolution.java:105) > at ec.simple.SimpleEvaluator.evalPopChunk(SimpleEvaluator.java:259) > at > ec.simple.SimpleEvaluator$SimpleEvaluatorThreadCG.run(SimpleEvaluator.java:341) > at ec.util.ThreadPool$PoolThread.run(ThreadPool.java:57) > > Exception in thread "ECJ Evaluation Thread 2" > java.lang.IndexOutOfBoundsException: Index: 0, Size: 1 > at java.util.ArrayList.rangeCheck(Unknown Source) > at java.util.ArrayList.get(Unknown Source) > at > org.apache.uima.cas.impl.FSIndexRepositoryImpl$LeafPointerIterator.initPointerIterator(FSIndexRepositoryImpl.java:628) > at > org.apache.uima.cas.impl.FSIndexRepositoryImpl$LeafPointerIterator.<init>(FSIndexRepositoryImpl.java:636) > at > org.apache.uima.cas.impl.FSIndexRepositoryImpl$LeafPointerIterator.<init>(FSIndexRepositoryImpl.java:612) > at > org.apache.uima.cas.impl.FSIndexRepositoryImpl.createPointerIterator(FSIndexRepositoryImpl.java:158) > at > org.apache.uima.cas.impl.FSIndexRepositoryImpl$IndexImpl.iterator(FSIndexRepositoryImpl.java:792) > at org.apache.uima.util.CasCopier.copyCasView(CasCopier.java:145) > at org.apache.uima.util.CasCopier.copyCas(CasCopier.java:108) > at rulevolution.utils.JCasUtils.copyJCas(JCasUtils.java:80) > at rulevolution.utils.JCasUtils.copyCasPool(JCasUtils.java:94) > at rulevolution.RulEvolution.evaluate(RulEvolution.java:105) > at ec.simple.SimpleEvaluator.evalPopChunk(SimpleEvaluator.java:259) > at > ec.simple.SimpleEvaluator$SimpleEvaluatorThreadCG.run(SimpleEvaluator.java:341) > at ec.util.ThreadPool$PoolThread.run(ThreadPool.java:57) > > My goal would be generating a JCas pool at beginning of the algorithm. Then > cloning the entire > jcas pool for each rule evaluation. After the rule is evaluated the cloned > cas pool needs to be > deleted. > > Does someone know why I'm getting these exceptions and are there some ways to > work with JCas objects outside of UIMA Concext? > > Greetings > > Bojan >
