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);
}
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations