1
14
15 package gate.creole;
16
17 import java.util.*;
18
19 import gate.*;
20 import gate.util.Err;
21 import gate.util.GateRuntimeException;
22
23
33 public class ConditionalSerialAnalyserController
34 extends ConditionalSerialController implements CorpusController {
35
36 public gate.Corpus getCorpus() {
37 return corpus;
38 }
39
40 public void setCorpus(gate.Corpus corpus) {
41 this.corpus = corpus;
42 }
43
44
45 public void execute() throws ExecutionException{
46 interrupted = false;
47 if(corpus == null) throw new ExecutionException(
48 "(SerialAnalyserController) \"" + getName() + "\":\n" +
49 "The corpus supplied for execution was null!");
50 for(int i = 0; i < corpus.size(); i++){
52 if(isInterrupted()) throw new ExecutionInterruptedException(
53 "The execution of the " + getName() +
54 " application has been abruptly interrupted!");
55
56 boolean docWasLoaded = corpus.isDocumentLoaded(i);
57 Document doc = (Document)corpus.get(i);
58 for(int j = 0; j < prList.size(); j++){
61 ((LanguageAnalyser)prList.get(j)).setDocument(doc);
62 ((LanguageAnalyser)prList.get(j)).setCorpus(corpus);
63 }
64
65 try{
66 super.execute();
67 }catch(Exception e){
68 e.printStackTrace(Err.getPrintWriter());
69 }
70
71 for(int j = 0; j < prList.size(); j++){
73 ((LanguageAnalyser)prList.get(j)).setDocument(null);
74 ((LanguageAnalyser)prList.get(j)).setCorpus(null);
75 }
76
77 corpus.unloadDocument(doc);
78 if(!docWasLoaded) Factory.deleteResource(doc);
79 }
80 }
81
82
86 public void add(ProcessingResource pr){
87 if(pr instanceof LanguageAnalyser){
88 super.add(pr);
89 }else{
90 throw new GateRuntimeException(getClass().getName() +
91 "only accepts " +
92 LanguageAnalyser.class.getName() +
93 "s as components\n" +
94 pr.getClass().getName() +
95 " is not!");
96 }
97 }
98
101 protected void setDocToPrs(Document doc){
102 Iterator prIter = getPRs().iterator();
103 while(prIter.hasNext()){
104 ((LanguageAnalyser)prIter.next()).setDocument(doc);
105 }
106 }
107
108
109
121 public List getOffendingPocessingResources()
122 throws ResourceInstantiationException{
123 ArrayList badPRs = new ArrayList(getPRs());
125 Iterator prIter = getPRs().iterator();
127 while(prIter.hasNext()){
128 ProcessingResource pr = (ProcessingResource)prIter.next();
129 ResourceData rData = (ResourceData)Gate.getCreoleRegister().
130 get(pr.getClass().getName());
131 List parameters = rData.getParameterList().getRuntimeParameters();
133 List newParameters = new ArrayList();
135 Iterator pDisjIter = parameters.iterator();
136 while(pDisjIter.hasNext()){
137 List aDisjunction = (List)pDisjIter.next();
138 List newDisjunction = new ArrayList(aDisjunction);
139 Iterator internalParIter = newDisjunction.iterator();
140 while(internalParIter.hasNext()){
141 Parameter parameter = (Parameter)internalParIter.next();
142 if(parameter.getName().equals("corpus") ||
143 parameter.getName().equals("document")) internalParIter.remove();
144 }
145 if(!newDisjunction.isEmpty()) newParameters.add(newDisjunction);
146 }
147
148 if(AbstractResource.checkParameterValues(pr, newParameters)){
149 badPRs.remove(pr);
150 }
151 }
152 return badPRs.isEmpty() ? null : badPRs;
153 }
154
155
156 private gate.Corpus corpus;
157 }