Search in sources :

Example 16 with ProcessingResource

use of gate.ProcessingResource 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)

Example 17 with ProcessingResource

use of gate.ProcessingResource in project gate-core by GateNLP.

the class CorpusBenchmarkTool method processDocument.

// evaluateMarkedClean
protected void processDocument(Document doc) {
    try {
        if (application instanceof CorpusController) {
            Corpus tempCorpus = Factory.newCorpus("temp");
            tempCorpus.add(doc);
            ((CorpusController) application).setCorpus(tempCorpus);
            application.execute();
            Factory.deleteResource(tempCorpus);
            tempCorpus = null;
        } else {
            Iterator<ProcessingResource> iter = application.getPRs().iterator();
            while (iter.hasNext()) iter.next().setParameterValue("document", doc);
            application.execute();
        }
    } catch (ResourceInstantiationException ex) {
        throw (RuntimeException) new RuntimeException("Error executing application: " + ex.getMessage()).initCause(ex);
    } catch (ExecutionException ex) {
        throw (RuntimeException) new RuntimeException("Error executing application: " + ex.getMessage()).initCause(ex);
    }
}
Also used : CorpusController(gate.CorpusController) ProcessingResource(gate.ProcessingResource) ExecutionException(gate.creole.ExecutionException) Corpus(gate.Corpus) ResourceInstantiationException(gate.creole.ResourceInstantiationException)

Example 18 with ProcessingResource

use of gate.ProcessingResource in project gate-core by GateNLP.

the class ControllerPersistence method createObject.

/**
 * Creates a new object from the data contained. This new object is supposed
 * to be a copy for the original object used as source for data extraction.
 */
@SuppressWarnings("unchecked")
@Override
public Object createObject() throws PersistenceException, ResourceInstantiationException {
    Controller controller = (Controller) super.createObject();
    if (controller.getPRs().isEmpty()) {
        prList = PersistenceManager.getTransientRepresentation(prList, resourceName, initParamOverrides);
        controller.setPRs((Collection<ProcessingResource>) prList);
    }
    return controller;
}
Also used : ProcessingResource(gate.ProcessingResource) Controller(gate.Controller)

Example 19 with ProcessingResource

use of gate.ProcessingResource in project gate-core by GateNLP.

the class ControllerPersistence 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 Controller)) {
        throw new UnsupportedOperationException(getClass().getName() + " can only be used for " + Controller.class.getName() + " objects!\n" + source.getClass().getName() + " is not a " + Controller.class.getName());
    }
    Controller controller = (Controller) source;
    super.extractDataFromSource(source);
    /*prList = new ArrayList(controller.getPRs().size());
    Iterator prIter = controller.getPRs().iterator();

    while(prIter.hasNext()){
      ((List)prList).add(prIter.next());
    }*/
    prList = new ArrayList<ProcessingResource>(controller.getPRs());
    prList = PersistenceManager.getPersistentRepresentation(prList);
}
Also used : ProcessingResource(gate.ProcessingResource) Controller(gate.Controller)

Example 20 with ProcessingResource

use of gate.ProcessingResource in project gate-core by GateNLP.

the class AbstractController method getOffendingPocessingResources.

/**
 * Checks whether all the contained PRs have all the required runtime
 * parameters set.
 *
 * @return a {@link List} of {@link ProcessingResource}s that have required
 *         parameters with null values if they exist <tt>null</tt>
 *         otherwise.
 * @throws {@link ResourceInstantiationException}
 *           if problems occur while inspecting the parameters for one of the
 *           resources. These will normally be introspection problems and are
 *           usually caused by the lack of a parameter or of the read accessor
 *           for a parameter.
 */
public List<ProcessingResource> getOffendingPocessingResources() throws ResourceInstantiationException {
    // take all the contained PRs
    List<ProcessingResource> badPRs = new ArrayList<ProcessingResource>(getPRs());
    // remove the ones that no parameters problems
    Iterator<ProcessingResource> prIter = getPRs().iterator();
    while (prIter.hasNext()) {
        ProcessingResource pr = prIter.next();
        ResourceData rData = Gate.getCreoleRegister().get(pr.getClass().getName());
        if (AbstractResource.checkParameterValues(pr, rData.getParameterList().getRuntimeParameters())) {
            badPRs.remove(pr);
        }
    }
    return badPRs.isEmpty() ? null : badPRs;
}
Also used : ProcessingResource(gate.ProcessingResource) ArrayList(java.util.ArrayList)

Aggregations

ProcessingResource (gate.ProcessingResource)21 List (java.util.List)7 ArrayList (java.util.ArrayList)6 Controller (gate.Controller)5 Corpus (gate.Corpus)4 LanguageResource (gate.LanguageResource)4 Parameter (gate.creole.Parameter)4 ResourceData (gate.creole.ResourceData)4 CorpusController (gate.CorpusController)3 Resource (gate.Resource)3 ConditionalSerialAnalyserController (gate.creole.ConditionalSerialAnalyserController)3 ResourceInstantiationException (gate.creole.ResourceInstantiationException)3 UnconditionalRunningStrategy (gate.creole.RunningStrategy.UnconditionalRunningStrategy)3 Document (gate.Document)2 FeatureMap (gate.FeatureMap)2 VisualResource (gate.VisualResource)2 AnalyserRunningStrategy (gate.creole.AnalyserRunningStrategy)2 PackagedController (gate.creole.PackagedController)2 RunningStrategy (gate.creole.RunningStrategy)2 CreoleParameter (gate.creole.metadata.CreoleParameter)2