Search in sources :

Example 6 with Parameter

use of gate.creole.Parameter in project gate-core by GateNLP.

the class PRPersistence method extractDataFromSource.

/**
 * Populates this Persistence with the data that needs to be stored from the
 * original source object.
 */
@Override
public void extractDataFromSource(Object source) throws PersistenceException {
    if (!(source instanceof ProcessingResource)) {
        throw new UnsupportedOperationException(getClass().getName() + " can only be used for " + ProcessingResource.class.getName() + " objects!\n" + source.getClass().getName() + " is not a " + ProcessingResource.class.getName());
    }
    super.extractDataFromSource(source);
    Resource res = (Resource) source;
    ResourceData rData = Gate.getCreoleRegister().get(res.getClass().getName());
    if (rData == null)
        throw new PersistenceException("Could not find CREOLE data for " + res.getClass().getName());
    // now get the runtime params
    ParameterList params = rData.getParameterList();
    try {
        // get the values for the init time parameters
        runtimeParams = Factory.newFeatureMap();
        // this is a list of lists
        Iterator<List<Parameter>> parDisjIter = params.getRuntimeParameters().iterator();
        while (parDisjIter.hasNext()) {
            Iterator<Parameter> parIter = parDisjIter.next().iterator();
            while (parIter.hasNext()) {
                Parameter parameter = parIter.next();
                String parName = parameter.getName();
                Object parValue = res.getParameterValue(parName);
                if (storeParameterValue(parValue, parameter.getDefaultValue())) {
                    ((FeatureMap) runtimeParams).put(parName, parValue);
                }
            }
        }
        runtimeParams = PersistenceManager.getPersistentRepresentation(runtimeParams);
    } catch (ResourceInstantiationException | ParameterException rie) {
        throw new PersistenceException(rie);
    }
}
Also used : ResourceData(gate.creole.ResourceData) ProcessingResource(gate.ProcessingResource) Resource(gate.Resource) ProcessingResource(gate.ProcessingResource) ResourceInstantiationException(gate.creole.ResourceInstantiationException) FeatureMap(gate.FeatureMap) PersistenceException(gate.persist.PersistenceException) ParameterList(gate.creole.ParameterList) Parameter(gate.creole.Parameter) ParameterList(gate.creole.ParameterList) List(java.util.List) ParameterException(gate.creole.ParameterException)

Aggregations

Parameter (gate.creole.Parameter)6 ResourceData (gate.creole.ResourceData)6 List (java.util.List)6 ProcessingResource (gate.ProcessingResource)4 FeatureMap (gate.FeatureMap)3 ParameterException (gate.creole.ParameterException)3 ResourceInstantiationException (gate.creole.ResourceInstantiationException)3 Resource (gate.Resource)2 ParameterList (gate.creole.ParameterList)2 PersistenceException (gate.persist.PersistenceException)2 HashSet (java.util.HashSet)2 Corpus (gate.Corpus)1 CorpusExporter (gate.CorpusExporter)1 Document (gate.Document)1 AnalyserRunningStrategy (gate.creole.AnalyserRunningStrategy)1 RunningStrategy (gate.creole.RunningStrategy)1 UnconditionalRunningStrategy (gate.creole.RunningStrategy.UnconditionalRunningStrategy)1 InvalidOffsetException (gate.util.InvalidOffsetException)1 ActionEvent (java.awt.event.ActionEvent)1 File (java.io.File)1