MCPcopy Create free account
hub / github.com/GateNLP/gate-core / defaultDuplicate

Method defaultDuplicate

src/main/java/gate/Factory.java:686–736  ·  view source on GitHub ↗

Implementation of the default duplication algorithm described in the comment for #duplicate(Resource). This method is public for the benefit of resources that implement CustomDuplication but only need to do some post-processing after the default duplication algorithm; they can call t

(Resource res, DuplicationContext ctx)

Source from the content-addressed store, hash-verified

684 * duplicating the given resource.
685 */
686 public static Resource defaultDuplicate(Resource res, DuplicationContext ctx)
687 throws ResourceInstantiationException {
688 checkDuplicationContext(ctx);
689 String className = res.getClass().getName();
690 ResourceData resData = Gate.getCreoleRegister().get(className);
691 if(resData == null) {
692 throw new ResourceInstantiationException(
693 "Could not find CREOLE data for " + className);
694 }
695 String resName = res.getName();
696
697 FeatureMap newResFeatures = duplicate(res.getFeatures(), ctx);
698
699 // init parameters
700 FeatureMap initParams = AbstractResource.getInitParameterValues(res);
701 // remove parameters that are also sharable properties
702 for(String propName : resData.getSharableProperties()) {
703 initParams.remove(propName);
704 }
705 // duplicate any Resources in the params map (excluding sharable
706 // ones)
707 initParams = duplicate(initParams, ctx);
708 // add sharable properties to the params map (unduplicated). Some of
709 // these
710 // may be registered parameters but others may not be.
711 for(String propName : resData.getSharableProperties()) {
712 initParams.put(propName, res.getParameterValue(propName));
713 }
714
715 // create the new resource
716 Resource newResource =
717 createResource(className, initParams, newResFeatures, resName);
718 if(newResource instanceof ProcessingResource) {
719 // runtime params
720 FeatureMap runtimeParams =
721 AbstractProcessingResource.getRuntimeParameterValues(res);
722 // remove parameters that are also sharable properties
723 for(String propName : resData.getSharableProperties()) {
724 runtimeParams.remove(propName);
725 }
726 // duplicate any Resources in the params map (excluding sharable
727 // ones)
728 runtimeParams = duplicate(runtimeParams, ctx);
729 // do not need to add sharable properties here, they have already
730 // been injected by createResource
731
732 newResource.setParameterValues(runtimeParams);
733 }
734
735 return newResource;
736 }
737
738 /**
739 * Construct a feature map that is a copy of the one provided except

Callers 3

duplicateMethod · 0.95
duplicateMethod · 0.95
duplicateMethod · 0.95

Calls 14

getCreoleRegisterMethod · 0.95
duplicateMethod · 0.95
getSharablePropertiesMethod · 0.95
createResourceMethod · 0.95
setParameterValuesMethod · 0.95
getNameMethod · 0.65
getMethod · 0.65
getFeaturesMethod · 0.65
removeMethod · 0.65

Tested by

no test coverage detected