Skip to content

Commit 8f4a97b

Browse files
committed
Fix issue #32, throw exception when instance without target value is
found.
1 parent c39d427 commit 8f4a97b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/gate/plugin/learningframework/LF_TrainClassification.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,15 @@ public Document process(Document doc) {
178178
// This makes sure that for training, any attribute which makes use of the internal class feature
179179
// will get the correct value from the training set, even if the gate.LF.target feature has
180180
// been set differently before this PR is run.
181+
// While we are at it, we also check that the target feature actually has a non-null
182+
// value. We throw an exception if there is an instance without a target value!
181183
for(Annotation inst : instanceAS) {
182184
FeatureMap fm = inst.getFeatures();
183-
fm.put("gate.LF.target",fm.get(getTargetFeature()));
185+
Object targetVal = fm.get(getTargetFeature());
186+
if(null==targetVal) {
187+
throw new GateRuntimeException("Target value is null in document "+document.getName()+" for instance "+inst);
188+
}
189+
fm.put("gate.LF.target",targetVal);
184190
}
185191

186192

src/gate/plugin/learningframework/LF_TrainRegression.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
*/
2020
package gate.plugin.learningframework;
2121

22+
import gate.Annotation;
2223
import gate.AnnotationSet;
2324
import java.net.URL;
2425

2526
import org.apache.log4j.Logger;
2627

2728
import gate.Controller;
2829
import gate.Document;
30+
import gate.FeatureMap;
2931
import gate.creole.metadata.CreoleParameter;
3032
import gate.creole.metadata.CreoleResource;
3133
import gate.creole.metadata.Optional;
@@ -154,6 +156,14 @@ public Document process(Document doc) {
154156
// the sequenceAS is always null for the regression task!
155157
// the nameFeatureName is always null for now!
156158
String nameFeatureName = null;
159+
for(Annotation inst : instanceAS) {
160+
FeatureMap fm = inst.getFeatures();
161+
Object targetVal = fm.get(getTargetFeature());
162+
if(null==targetVal) {
163+
throw new GateRuntimeException("Target value is null in document "+document.getName()+" for instance "+inst);
164+
}
165+
}
166+
157167
corpusRepresentation.add(instanceAS, null, inputAS, null, getTargetFeature(), TargetType.NUMERIC, instanceWeightFeature, nameFeatureName, null);
158168
return doc;
159169
}

0 commit comments

Comments
 (0)