You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by "Richard Eckart de Castilho (Jira)" <de...@uima.apache.org> on 2021/01/27 21:01:00 UTC
[jira] [Comment Edited] (UIMA-6300) deep copy feature for
org.apache.uima.analysis_engine.AnalysisEngineDescription class
[ https://issues.apache.org/jira/browse/UIMA-6300?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17273139#comment-17273139 ]
Richard Eckart de Castilho edited comment on UIMA-6300 at 1/27/21, 9:00 PM:
----------------------------------------------------------------------------
I am unable to reproduce the problem reported in this issue. The {{clone()}} method does not trigger the resolving of imports and does as far as I can tell not modify the original object. The following unit test shows this:
{code}
public void testCloneDoesNotResolveDelegateImports() throws Exception {
// create aggregate TAE description and add delegate AE import
Import_impl delegateImport = new Import_impl();
delegateImport.setLocation(
JUnitExtension.getFile("TextAnalysisEngineImplTest/TestPrimitiveTae1.xml").toURI().toURL().toString());
AnalysisEngineDescription testAgg = new AnalysisEngineDescription_impl();
Map<String, MetaDataObject> delegateMap = testAgg
.getDelegateAnalysisEngineSpecifiersWithImports();
delegateMap.put("key", delegateImport);
assertThat(testAgg) //
.as("Delegate import in original has not been resolved") //
.extracting("mDelegateAnalysisEngineSpecifiers", as(InstanceOfAssertFactories.MAP))
.isEmpty();
AnalysisEngineDescription clonedAgg = (AnalysisEngineDescription) testAgg.clone();
assertThat(testAgg) //
.as("Delegate import in original has still not been resolved") //
.extracting("mDelegateAnalysisEngineSpecifiers", as(InstanceOfAssertFactories.MAP))
.isEmpty();
assertThat(testAgg.getDelegateAnalysisEngineSpecifiersWithImports().values()) //
.as("import is still there in original") //
.hasSize(1) //
.allMatch(d -> d instanceof Import);
assertThat(clonedAgg) //
.as("Delegate import in clone has not been resolved") //
.extracting("mDelegateAnalysisEngineSpecifiers", as(InstanceOfAssertFactories.MAP))
.isEmpty();
assertThat(clonedAgg.getDelegateAnalysisEngineSpecifiersWithImports().values()) //
.as("import is still there in clone") //
.hasSize(1) //
.allMatch(d -> d instanceof Import);
}
{code}
Note that the unit test accesses the field {{mDelegateAnalysisEngineSpecifiers}} of the {{AnalysisEngineDescription_impl}} directly via reflection instead of calling {{getDelegateAnalysisEngineSpecifiers()}} because calling this method would cause imports to be resolved.
Tested against the UIMAv2 code ({{main-v2}} branch) and against the UIMAv3 code ({{main}} branch).
was (Author: rec):
I am unable to reproduce the problem reported in this issue. The {{clone()}} method does not trigger the resolving of imports and does as far as I can tell not modify the original object. The following unit test shows this:
{code}
public void testCloneDoesNotResolveDelegateImports() throws Exception {
// create aggregate TAE description and add delegate AE import
Import_impl delegateImport = new Import_impl();
delegateImport.setLocation(
JUnitExtension.getFile("TextAnalysisEngineImplTest/TestPrimitiveTae1.xml").toURI().toURL().toString());
AnalysisEngineDescription testAgg = new AnalysisEngineDescription_impl();
Map<String, MetaDataObject> delegateMap = testAgg
.getDelegateAnalysisEngineSpecifiersWithImports();
delegateMap.put("key", delegateImport);
assertThat(testAgg) //
.as("Delegate import in original has not been resolved") //
.extracting("mDelegateAnalysisEngineSpecifiers", as(InstanceOfAssertFactories.MAP))
.isEmpty();
AnalysisEngineDescription clonedAgg = (AnalysisEngineDescription) testAgg.clone();
assertThat(testAgg) //
.as("Delegate import in original has still not been resolved") //
.extracting("mDelegateAnalysisEngineSpecifiers", as(InstanceOfAssertFactories.MAP))
.isEmpty();
assertThat(testAgg.getDelegateAnalysisEngineSpecifiersWithImports().values()) //
.as("import is still there in original") //
.hasSize(1) //
.allMatch(d -> d instanceof Import);
assertThat(clonedAgg) //
.as("Delegate import in clone has not been resolved") //
.extracting("mDelegateAnalysisEngineSpecifiers", as(InstanceOfAssertFactories.MAP))
.isEmpty();
assertThat(clonedAgg.getDelegateAnalysisEngineSpecifiersWithImports().values()) //
.as("import is still there in clone") //
.hasSize(1) //
.allMatch(d -> d instanceof Import);
}
{code}
Note that the unit test accesses the field {{mDelegateAnalysisEngineSpecifiers}} of the {{AnalysisEngineDescription_impl}} directly via reflection instead of calling {{getDelegateAnalysisEngineSpecifiers()}} because calling this method would cause imports to be resolved.
> deep copy feature for org.apache.uima.analysis_engine.AnalysisEngineDescription class
> -------------------------------------------------------------------------------------
>
> Key: UIMA-6300
> URL: https://issues.apache.org/jira/browse/UIMA-6300
> Project: UIMA
> Issue Type: Improvement
> Components: uimaj
> Affects Versions: 3.1.1SDK
> Reporter: Serge Démoulin
> Assignee: Richard Eckart de Castilho
> Priority: Major
> Fix For: 3.2.0SDK
>
> Original Estimate: 48h
> Remaining Estimate: 48h
>
> I need the following feature :
> a deep copy for the following class org.apache.uima.analysis_engine.AnalysisEngineDescription
> It means a copy that resolve the imports and copy the metatdatas, the delegates in case of aggregates and all the others attributes ...
> IMPROVEMENT : this deep copy should let the object unchanged
> That mean it should not call the method resolveImports() on the original object (this method changes the object)
>
> AnalysisEngineDescription_impl inherits from MetaDataObject_impl
> The class MetaDataObject_impl has a clone method
> The clone method of MetaDataObject_impl resolve the imports (changing the object) and makes a deep its undelying metadatas.
> {color:#ffffff}MetaDataOpl{color}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)