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