use of gate.ProcessingResource in project gate-core by GateNLP.
the class TeamwareUtils method populateInputSetNamesForController.
/**
* Populate the set of input annotation set names for a controller
* based on heuristics. In the strict case we assume that if a PR in
* the controller has an inputASName parameter whose value is not the
* default set, and there is no PR earlier in the pipeline which has
* the same set as its outputASName or annotationSetName parameter,
* then it is probably a set that needs to be provided externally. In
* the non-strict case we simply take all inputASName and
* annotationSetName parameter values from the controller's PRs,
* without regard for whether they may have been satisfied by an
* earlier PR in the pipeline.
*
* @param setNames
* @param c
* @param strict
*/
private static void populateInputSetNamesForController(Set<String> setNames, Controller c, boolean strict) {
Set<String> outputSetNamesSoFar = new HashSet<String>();
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();
// check for inputASName and annotationSetName params
for (List<Parameter> disjunction : runtimeParams) {
for (Parameter param : disjunction) {
if (param.getName().equals("inputASName")) {
String setName = (String) pr.getParameterValue(param.getName());
if (!strict || (setName != null && !outputSetNamesSoFar.contains(setName))) {
setNames.add(setName);
}
} else if (!strict && param.getName().equals("annotationSetName")) {
setNames.add((String) pr.getParameterValue(param.getName()));
}
}
}
// check for output set names and update that set
if (strict) {
for (List<Parameter> disjunction : runtimeParams) {
for (Parameter param : disjunction) {
if (param.getName().equals("outputASName") || param.getName().equals("annotationSetName")) {
outputSetNamesSoFar.add(String.valueOf(pr.getParameterValue(param.getName())));
}
}
}
}
}
} catch (Exception e) {
// ignore - this is all heuristics, after all
}
}
use of gate.ProcessingResource in project gate-core by GateNLP.
the class DynamicRegistrationTest method testDynamicRegistration.
public void testDynamicRegistration() throws Exception {
Gate.getCreoleRegister().registerPlugin(new Plugin.Component(TestResource.class));
SerialAnalyserController controller = (SerialAnalyserController) Factory.createResource("gate.creole.SerialAnalyserController", Factory.newFeatureMap(), Factory.newFeatureMap(), "basicRun");
ProcessingResource testResource = (ProcessingResource) Factory.createResource(TestResource.class.getName());
controller.add(testResource);
Corpus corpus = Factory.newCorpus("basicTestCorpus");
String engText = "This is the cereal shot from gnus.";
Document doc = Factory.newDocument(engText);
corpus.add(doc);
controller.setCorpus(corpus);
controller.setDocument(doc);
controller.execute();
}
use of gate.ProcessingResource in project gate-core by GateNLP.
the class TestCreole method testDefaultRun.
// testParameters()
/**
* Test default run() on processing resources
*/
public void testDefaultRun() throws Exception {
@SuppressWarnings("serial") ProcessingResource defaultPr = new AbstractProcessingResource() {
};
boolean gotExceptionAsExpected = false;
try {
defaultPr.execute();
} catch (ExecutionException e) {
gotExceptionAsExpected = true;
}
assertTrue("check should have thrown exception", gotExceptionAsExpected);
}
use of gate.ProcessingResource in project gate-core by GateNLP.
the class SerialControllerEditor method resourceUnloaded.
@Override
public void resourceUnloaded(CreoleEvent e) {
if (Gate.getHiddenAttribute(e.getResource().getFeatures()))
return;
if (e.getResource() instanceof ProcessingResource) {
ProcessingResource pr = (ProcessingResource) e.getResource();
if (controller != null && controller.getPRs().contains(pr)) {
controller.remove(pr);
}
refreshPRLists();
} else if (e.getResource() instanceof LanguageResource) {
if (e.getResource() instanceof Corpus && corpusControllerMode) {
Corpus c = (Corpus) e.getResource();
if (controller instanceof CorpusController) {
if (c == ((CorpusController) controller).getCorpus()) {
// setCorpus(null) is also called in the controller's
// resourceUnloaded(), but we can't be sure which handler is
// called first...
((CorpusController) controller).setCorpus(null);
}
} else {
throw new GateRuntimeException("Controller editor in analyser mode " + "but the target controller is not an " + "analyser!");
}
corpusComboModel.fireDataChanged();
}
}
}
use of gate.ProcessingResource in project gate-core by GateNLP.
the class SerialControllerEditor method selectPR.
/**
* Called when a PR has been selected in the member PRs table;
* @param index row index in {@link #memberPRsTable} (or -1 if no PR is
* currently selected)
*/
protected void selectPR(int index) {
// stop current editing of parameters
if (parametersEditor.getResource() != null) {
try {
parametersEditor.setParameters();
} catch (ResourceInstantiationException rie) {
JOptionPane.showMessageDialog(SerialControllerEditor.this, "Failed to set parameters for \"" + parametersEditor.getResource().getName() + "\"!\n", "GATE", JOptionPane.ERROR_MESSAGE);
rie.printStackTrace(Err.getPrintWriter());
}
if (conditionalMode) {
if (selectedPRRunStrategy != null && selectedPRRunStrategy instanceof AnalyserRunningStrategy) {
AnalyserRunningStrategy strategy = (AnalyserRunningStrategy) selectedPRRunStrategy;
strategy.setFeatureName(featureNameTextField.getText());
strategy.setFeatureValue(featureValueTextField.getText());
}
selectedPRRunStrategy = null;
}
}
// find the new PR
ProcessingResource pr = null;
if (index >= 0 && index < controller.getPRs().size()) {
pr = controller.getPRs().get(index);
}
if (pr != null) {
// update the GUI for the new PR
ResourceData rData = Gate.getCreoleRegister().get(pr.getClass().getName());
// update the border name
parametersBorder.setTitle(" Runtime Parameters for the \"" + pr.getName() + "\" " + rData.getName() + ": ");
// update the params editor
// this is a list of lists
List<List<Parameter>> parameters = rData.getParameterList().getRuntimeParameters();
if (corpusControllerMode) {
// remove corpus and document
// create a new list so we don't change the one from CreoleReg.
List<List<Parameter>> oldParameters = parameters;
parameters = new ArrayList<List<Parameter>>();
for (List<Parameter> aDisjunction : oldParameters) {
List<Parameter> newDisjunction = new ArrayList<Parameter>();
for (Parameter parameter : aDisjunction) {
if (!parameter.getName().equals("corpus") && !parameter.getName().equals("document")) {
newDisjunction.add(parameter);
}
}
if (!newDisjunction.isEmpty())
parameters.add(newDisjunction);
}
}
parametersEditor.init(pr, parameters);
if (conditionalMode) {
strategyBorder.setTitle(" Run \"" + pr.getName() + "\"? ");
// update the state of the run strategy buttons
yes_RunRBtn.setEnabled(true);
no_RunRBtn.setEnabled(true);
conditional_RunRBtn.setEnabled(true);
// editing the strategy panel causes the edits to be sent to the current
// strategy object, which can lead to a race condition.
// So we used a cached value instead.
selectedPRRunStrategy = null;
RunningStrategy newStrategy = ((ConditionalController) controller).getRunningStrategies().get(index);
if (newStrategy instanceof AnalyserRunningStrategy) {
featureNameTextField.setEnabled(true);
featureValueTextField.setEnabled(true);
conditional_RunRBtn.setEnabled(true);
featureNameTextField.setText(((AnalyserRunningStrategy) newStrategy).getFeatureName());
featureValueTextField.setText(((AnalyserRunningStrategy) newStrategy).getFeatureValue());
} else {
featureNameTextField.setEnabled(false);
featureValueTextField.setEnabled(false);
conditional_RunRBtn.setEnabled(false);
}
switch(newStrategy.getRunMode()) {
case RunningStrategy.RUN_ALWAYS:
{
yes_RunRBtn.setSelected(true);
break;
}
case RunningStrategy.RUN_NEVER:
{
no_RunRBtn.setSelected(true);
break;
}
case RunningStrategy.RUN_CONDITIONAL:
{
conditional_RunRBtn.setSelected(true);
break;
}
}
// switch
// now that the UI is updated, we can safely link to the new strategy
selectedPRRunStrategy = newStrategy;
}
} else {
// selected PR == null -> clean all mentions of the old PR from the GUI
parametersBorder.setTitle(" No processing resource selected... ");
parametersEditor.init(null, null);
if (conditionalMode) {
strategyBorder.setTitle(" No processing resource selected... ");
yes_RunRBtn.setEnabled(false);
no_RunRBtn.setEnabled(false);
conditional_RunRBtn.setEnabled(false);
featureNameTextField.setText("");
featureNameTextField.setEnabled(false);
featureValueTextField.setText("");
featureValueTextField.setEnabled(false);
}
}
// this seems to be needed to show the changes
SerialControllerEditor.this.repaint(100);
}
Aggregations