Search in sources :

Example 6 with ProcessingResource

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

the class ConditionalSerialAnalyserController method getOffendingPocessingResources.

/**
 * Checks whether all the contained PRs have all the required runtime
 * parameters set. Ignores the corpus and document parameters as these will
 * be set at run time.
 *
 * @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.
 */
@Override
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());
        // this is a list of lists
        List<List<Parameter>> parameters = rData.getParameterList().getRuntimeParameters();
        // remove corpus and document
        List<List<Parameter>> newParameters = new ArrayList<List<Parameter>>();
        Iterator<List<Parameter>> pDisjIter = parameters.iterator();
        while (pDisjIter.hasNext()) {
            List<Parameter> aDisjunction = pDisjIter.next();
            List<Parameter> newDisjunction = new ArrayList<Parameter>(aDisjunction);
            Iterator<Parameter> internalParIter = newDisjunction.iterator();
            while (internalParIter.hasNext()) {
                Parameter parameter = internalParIter.next();
                if (parameter.getName().equals("corpus") || parameter.getName().equals("document"))
                    internalParIter.remove();
            }
            if (!newDisjunction.isEmpty())
                newParameters.add(newDisjunction);
        }
        if (AbstractResource.checkParameterValues(pr, newParameters)) {
            badPRs.remove(pr);
        }
    }
    return badPRs.isEmpty() ? null : badPRs;
}
Also used : ProcessingResource(gate.ProcessingResource) ArrayList(java.util.ArrayList) CreoleParameter(gate.creole.metadata.CreoleParameter) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with ProcessingResource

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

the class ConditionalSerialController method duplicate.

/**
 * Custom duplication method for conditional controllers to handle
 * duplicating the running strategies.
 */
@Override
public Resource duplicate(Factory.DuplicationContext ctx) throws ResourceInstantiationException {
    ConditionalController c = (ConditionalController) super.duplicate(ctx);
    Collection<ProcessingResource> newPRs = c.getPRs();
    List<RunningStrategy> newStrategies = new ArrayList<RunningStrategy>(strategiesList.size());
    Iterator<RunningStrategy> oldRSIt = getRunningStrategies().iterator();
    Iterator<ProcessingResource> prIt = newPRs.iterator();
    while (oldRSIt.hasNext()) {
        RunningStrategy oldStrat = oldRSIt.next();
        ProcessingResource currentPR = prIt.next();
        if (oldStrat instanceof AnalyserRunningStrategy) {
            newStrategies.add(new AnalyserRunningStrategy((LanguageAnalyser) currentPR, ((AnalyserRunningStrategy) oldStrat).getRunMode(), ((AnalyserRunningStrategy) oldStrat).getFeatureName(), ((AnalyserRunningStrategy) oldStrat).getFeatureValue()));
        } else {
            boolean run = true;
            if (oldStrat instanceof UnconditionalRunningStrategy) {
                run = oldStrat.shouldRun();
            }
            // assume an unconditional strategy.  Subclasses that know about other types
            // of strategies can fix this up later
            newStrategies.add(new RunningStrategy.UnconditionalRunningStrategy(currentPR, run));
        }
    }
    c.setRunningStrategies(newStrategies);
    return c;
}
Also used : UnconditionalRunningStrategy(gate.creole.RunningStrategy.UnconditionalRunningStrategy) UnconditionalRunningStrategy(gate.creole.RunningStrategy.UnconditionalRunningStrategy) ProcessingResource(gate.ProcessingResource) ArrayList(java.util.ArrayList) LanguageAnalyser(gate.LanguageAnalyser) UnconditionalRunningStrategy(gate.creole.RunningStrategy.UnconditionalRunningStrategy)

Example 8 with ProcessingResource

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

the class ConditionalSerialController method runComponent.

/**
 * Executes a {@link ProcessingResource}.
 */
@Override
protected void runComponent(int componentIndex) throws ExecutionException {
    ProcessingResource currentPR = prList.get(componentIndex);
    // create the listeners
    // FeatureMap listeners = Factory.newFeatureMap();
    Map<String, Object> listeners = new HashMap<String, Object>();
    listeners.put("gate.event.StatusListener", sListener);
    int componentProgress = 100 / prList.size();
    listeners.put("gate.event.ProgressListener", new IntervalProgressListener(componentIndex * componentProgress, (componentIndex + 1) * componentProgress));
    // add the listeners
    try {
        AbstractResource.setResourceListeners(currentPR, listeners);
    } catch (Exception e) {
        // the listeners setting failed; nothing important
        Err.prln("Could not set listeners for " + currentPR.getClass().getName() + "\n" + e.toString() + "\n...nothing to lose any sleep over.");
    }
    // run the thing
    if (strategiesList.get(componentIndex).shouldRun()) {
        benchmarkFeatures.put(Benchmark.PR_NAME_FEATURE, currentPR.getName());
        long startTime = System.currentTimeMillis();
        // run the thing
        Benchmark.executeWithBenchmarking(currentPR, Benchmark.createBenchmarkId(Benchmark.PR_PREFIX + currentPR.getName(), getBenchmarkId()), this, benchmarkFeatures);
        benchmarkFeatures.remove(Benchmark.PR_NAME_FEATURE);
        // calculate the time taken by the PR
        long timeTakenByThePR = System.currentTimeMillis() - startTime;
        Long time = prTimeMap.get(currentPR.getName());
        if (time == null) {
            time = 0L;
        }
        time += timeTakenByThePR;
        prTimeMap.put(currentPR.getName(), time);
    }
    // remove the listeners
    try {
        AbstractResource.removeResourceListeners(currentPR, listeners);
    } catch (Exception e) {
        // the listeners removing failed; nothing important
        Err.prln("Could not clear listeners for " + currentPR.getClass().getName() + "\n" + e.toString() + "\n...nothing to lose any sleep over.");
    }
}
Also used : HashMap(java.util.HashMap) ProcessingResource(gate.ProcessingResource)

Example 9 with ProcessingResource

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

the class TestCreole method testLoading.

// testToolsAndPrivate()
/**
 * Test resource loading
 */
public void testLoading() throws Exception {
    // get some res data from the register
    assertEquals("wrong number of resources in the register: " + reg.size(), 9, reg.size());
    ResourceData pr1rd = reg.get("testpkg.TestPR1");
    ResourceData pr2rd = reg.get("testpkg.TestPR2");
    assertTrue("couldn't find PR1/PR2 res data", pr1rd != null && pr2rd != null);
    assertTrue("wrong name on PR1", pr1rd.getName().equals("Sheffield Test PR 1"));
    // instantiation
    ProcessingResource pr1 = (ProcessingResource) Factory.createResource("testpkg.TestPR1", Factory.newFeatureMap());
    ProcessingResource pr2 = (ProcessingResource) Factory.createResource("testpkg.TestPR2", Factory.newFeatureMap());
    // run the beasts
    FeatureMap pr1features = pr1.getFeatures();
    FeatureMap pr2features = pr2.getFeatures();
    assertNotNull("PR1 features are null", pr1features);
    assertTrue("PR2 got wrong features: " + pr2features, pr2features != null && pr2features.size() != 1);
    pr1.execute();
    pr2.execute();
    assertTrue("PR1 feature not present", pr1.getFeatures().get("I").equals("have been run, thankyou"));
    assertTrue("PR2 feature not present", pr2.getFeatures().get("I").equals("am in a bad mood"));
    reg.clear();
}
Also used : FeatureMap(gate.FeatureMap) ProcessingResource(gate.ProcessingResource)

Example 10 with ProcessingResource

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

the class TeamwareUtils method populateOutputSetNamesForController.

/**
 * Populate the set of output annotation set names for a controller
 * based on heuristics. In the strict case, we assume that if a PR in
 * the controller has an outputASName or annotationSetName parameter
 * whose value is not used as the inputASName or annotationSetName of
 * a later PR then it is probably a set that will be output from the
 * controller. In the non-strict case we simply take all outputASName
 * and annotationSetName parameter values from the controller's PRs
 * without regard for which ones may simply be feeding later PRs in
 * the controller (also, the default annotation set is always included
 * in non-strict mode).
 */
private static void populateOutputSetNamesForController(Set<String> setNames, Controller c, boolean strict) {
    Collection<ProcessingResource> prs = c.getPRs();
    try {
        for (ProcessingResource pr : prs) {
            ResourceData rd = Gate.getCreoleRegister().get(pr.getClass().getName());
            List<List<Parameter>> runtimeParams = rd.getParameterList().getRuntimeParameters();
            // PR.
            if (strict) {
                for (List<Parameter> disjunction : runtimeParams) {
                    for (Parameter param : disjunction) {
                        if (param.getName().equals("inputASName") || param.getName().equals("annotationSetName")) {
                            setNames.remove(pr.getParameterValue(param.getName()));
                        }
                    }
                }
            }
            // parameters
            for (List<Parameter> disjunction : runtimeParams) {
                for (Parameter param : disjunction) {
                    if (param.getName().equals("outputASName") || param.getName().equals("annotationSetName")) {
                        setNames.add((String) pr.getParameterValue(param.getName()));
                    }
                }
            }
        }
        // finally, add the default set for non-strict mode
        if (!strict) {
            setNames.add(null);
        }
    } catch (Exception e) {
    // ignore - this is all heuristics, after all
    }
}
Also used : ResourceData(gate.creole.ResourceData) ProcessingResource(gate.ProcessingResource) Parameter(gate.creole.Parameter) List(java.util.List)

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