// collect all relevant relation arguments from the sentence
List<IdentifiedAnnotationPair> candidatePairs = this.getCandidateRelationArgumentPairs(identifiedAnnotationView, sentence);
// walk through the pairs of annotations
for (IdentifiedAnnotationPair pair : candidatePairs) {
IdentifiedAnnotation arg1 = pair.getArg1();
IdentifiedAnnotation arg2 = pair.getArg2();
// apply all the feature extractors to extract the list of features
List<Feature> features = new ArrayList<Feature>();
for (RelationFeaturesExtractor extractor : this.featureExtractors) {
features.addAll(extractor.extract(jCas, arg1, arg2));
}
// sanity check on feature values
for (Feature feature : features) {
if (feature.getValue() == null) {
String message = "Null value found in %s from %s";
throw new IllegalArgumentException(String.format(message, feature, features));
}
}
// during training, feed the features to the data writer
if (this.isTraining()) {
String category = this.getRelationCategory(relationLookup, arg1, arg2);
if (category == null) { continue; }
// create a classification instance and write it to the training data
this.dataWriter.write(new Instance<String>(category, features));
}
// during classification feed the features to the classifier and create annotations
else {
String predictedCategory = this.classifier.classify(features);
if(printErrors) {
String goldCategory; // gold standard relation category
if (categoryLookup.containsKey(new HashableArguments(arg1, arg2))) {
goldCategory = categoryLookup.get(new HashableArguments(arg1, arg2));
} else {
goldCategory = NO_RELATION_CATEGORY;
}
logResults(sentence, arg1, arg2, features, predictedCategory, goldCategory);
}
// add a relation annotation if a true relation was predicted
if (!predictedCategory.equals(NO_RELATION_CATEGORY)) {
// if we predict an inverted relation, reverse the order of the arguments
if (predictedCategory.endsWith("-1")) {
predictedCategory = predictedCategory.substring(0, predictedCategory.length() - 2);
IdentifiedAnnotation temp = arg1;
arg1 = arg2;
arg2 = temp;
}
// add the relation to the CAS