You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by al...@apache.org on 2008/12/19 20:23:36 UTC
svn commit: r728118 - in /incubator/uima/uimaj/trunk/uimaj-core/src:
main/java/org/apache/uima/util/CasCopier.java
test/java/org/apache/uima/util/CasCopierTest.java
Author: alally
Date: Fri Dec 19 11:23:35 2008
New Revision: 728118
URL: http://svn.apache.org/viewvc?rev=728118&view=rev
Log:
UIMA-1258: Optimize CasCopier to avoid looking up Type and Feature handles
unnecessarily when the source and destination CASes share the same TypeSystem.
https://issues.apache.org/jira/browse/UIMA-1258
Modified:
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java
incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasCopierTest.java
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java?rev=728118&r1=728117&r2=728118&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java Fri Dec 19 11:23:35 2008
@@ -210,8 +210,13 @@
}
// create a new FS of the same type in the target CAS
- // TODO: could optimize type lookup if type systems are identical
- Type destType = mDestCas.getTypeSystem().getType(srcType.getName());
+ Type destType;
+ if (mDestCas.getTypeSystem() == mSrcCas.getTypeSystem()) {
+ //optimize type lookup if type systems are identical
+ destType = srcType;
+ } else {
+ destType = mDestCas.getTypeSystem().getType(srcType.getName());
+ }
if (destType == null) {
throw new UIMARuntimeException(UIMARuntimeException.TYPE_NOT_FOUND_DURING_CAS_COPY,
new Object[] { srcType.getName() });
@@ -247,7 +252,6 @@
Iterator srcFeatIter = srcType.getFeatures().iterator();
while (srcFeatIter.hasNext()) {
Feature srcFeat = (Feature) srcFeatIter.next();
- // TODO: could optimize type lookup if type systems are identical
Feature destFeat;
if (destType == aSrcFS.getType()) {
// sharing same type system, so destFeat == srcFeat
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasCopierTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasCopierTest.java?rev=728118&r1=728117&r2=728118&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasCopierTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasCopierTest.java Fri Dec 19 11:23:35 2008
@@ -97,6 +97,51 @@
CasCopier.copyCas(srcCasBase, destCasBase, true);
CasComparer.assertEquals(srcCasBase, destCasBase);
}
+
+ public void testCopyCasWithDifferentTypeSystemObject() throws Exception {
+ // create a source CAS by deserializing from XCAS
+ CAS srcCas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes);
+ InputStream serCasStream = new FileInputStream(JUnitExtension
+ .getFile("ExampleCas/multiSofaCas.xml"));
+ XCASDeserializer.deserialize(serCasStream, srcCas);
+ serCasStream.close();
+
+ // create a destination CAS (do not share the same type system object)
+ File typeSystemFile = JUnitExtension.getFile("ExampleCas/testTypeSystem.xml");
+ File indexesFile = JUnitExtension.getFile("ExampleCas/testIndexes.xml");
+
+ TypeSystemDescription newTsDesc = typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+ new XMLInputSource(typeSystemFile));
+ FsIndexDescription[] newFsIndexes = indexes = UIMAFramework.getXMLParser().parseFsIndexCollection(new XMLInputSource(indexesFile))
+ .getFsIndexes();
+ CAS destCas = CasCreationUtils.createCas(newTsDesc, new TypePriorities_impl(), newFsIndexes);
+
+ // do the copy
+ CasCopier.copyCas(srcCas, destCas, true);
+ // XCASSerializer.serialize(destCas, System.out);
+
+ // verify copy
+ CasComparer.assertEquals(srcCas, destCas);
+
+ // try with type systems are not identical (dest. a superset of src.)
+ TypeSystemDescription additionalTypes = new TypeSystemDescription_impl();
+ TypeDescription fooType = additionalTypes.addType("test.Foo", "Test Type",
+ "uima.tcas.Annotation");
+ fooType.addFeature("bar", "Test Feature", "uima.cas.String");
+ ArrayList destTypeSystems = new ArrayList();
+ destTypeSystems.add(additionalTypes);
+ destTypeSystems.add(typeSystem);
+ CAS destCas2 = CasCreationUtils.createCas(destTypeSystems);
+ CasCopier.copyCas(srcCas, destCas2, true);
+ CasComparer.assertEquals(srcCas, destCas);
+
+ // try with base CAS rather than initial view
+ CAS srcCasBase = ((CASImpl) srcCas).getBaseCAS();
+ destCas.reset();
+ CAS destCasBase = ((CASImpl) destCas).getBaseCAS();
+ CasCopier.copyCas(srcCasBase, destCasBase, true);
+ CasComparer.assertEquals(srcCasBase, destCasBase);
+ }
public void testCopyCasView() throws Exception {
// create a source CAS by deserializing from XCAS