1
13 package gate.creole;
14
15 import gate.*;
16 import gate.util.GateRuntimeException;
17
18
25
26 public class AnalyserRunningStrategy implements RunningStrategy{
27
28 public AnalyserRunningStrategy(LanguageAnalyser pr, int runMode,
29 String featureName, String featureValue){
30 this.pr = pr;
31 this.runMode = runMode;
32 this.featureName = featureName;
33 this.featureValue = featureValue;
34 }
35
36
57 public boolean shouldRun() {
58 if(runMode == RUN_ALWAYS) return true;
59 if(runMode == RUN_NEVER) return false;
60 if(runMode == RUN_CONDITIONAL){
61 if(featureName == null || featureName.length() == 0) return true;
62 Document doc = pr.getDocument();
63 if(doc != null){
64 FeatureMap fm = doc.getFeatures();
65 if(fm != null){
66 Object actualValue = fm.get(featureName);
67 return (actualValue == null && featureValue == null)
68 ||
69 (actualValue != null && actualValue.equals(featureValue));
70 }else return featureName == null;
71 }else return false;
72 }
73 throw new GateRuntimeException("Unknown run mode!");
74 }
75
76 public int getRunMode() {
77 return runMode;
78 }
79
80 public void setRunMode(int mode){
81 this.runMode = mode;
82 }
83
84 public void setFeatureName(String name){
85 this.featureName = name;
86 }
87
88 public void setFeatureValue(String value){
89 this.featureValue = value;
90 }
91
92 public String getFeatureName() {
93 return featureName;
94 }
95
96 public String getFeatureValue() {
97 return featureValue;
98 }
99
100 public ProcessingResource getPR() {
101 return pr;
102 }
103
104 public void setProcessingResource(ProcessingResource pr){
105 if(pr instanceof LanguageAnalyser){
106 this.pr = (LanguageAnalyser)pr;
107 }else throw new GateRuntimeException(
108 getClass().getName() + " can only be used for " +
109 LanguageAnalyser.class.getName() + "!\n" +
110 pr.getClass().getName() + " is not a " +
111 LanguageAnalyser.class.getName() + "!");
112 }
113
114 protected LanguageAnalyser pr;
115 protected int runMode = RUN_ALWAYS;
116 protected String featureName;
117 protected String featureValue;
118 }