in ctakes-core/src/main/java/org/apache/ctakes/core/ae/SHARPKnowtatorXMLReader.java [1166:1320]
public void addToIndexes(JCas jCas, Map<String, TOP> idAnnotationMap) {
if (this.source == null) {
// throw new UnsupportedOperationException(String.format(
LOGGER.error(String.format(
"no source for '%s' with id '%s' and annotationSlots %s in %s",
this.annotation.type,
this.annotation.id,
this.annotation.annotationSlots.keySet(),
this.sourceFile));
return;
}
if (this.target == null) {
// throw new UnsupportedOperationException(String.format(
LOGGER.error(String.format(
"no target for '%s' with id '%s' and annotationSlots %s in %s",
this.annotation.type,
this.annotation.id,
this.annotation.annotationSlots.keySet(),
this.sourceFile));
return;
}
// look up the relations in the map and issue an error if they're missing or an invalid type
Annotation sourceMention, targetMention;
try {
sourceMention = (Annotation)idAnnotationMap.get(this.source.id);
} catch (ClassCastException e) {
LOGGER.error(String.format("invalid source %s: %s", this.source.id, e.getMessage()));
return;
}
try {
targetMention = (Annotation)idAnnotationMap.get(this.target.id);
} catch (ClassCastException e) {
LOGGER.error(String.format("invalid target %s: %s", this.target.id, e.getMessage()));
return;
}
if (sourceMention == null) {
LOGGER.error(String.format(
"no Annotation for source id '%s' in %s",
this.source.id,
this.sourceFile));
return;
} else if (targetMention == null) {
LOGGER.error(String.format(
"no Annotation for target id '%s' in %s",
this.target.id,
this.sourceFile));
return;
}
// get the conditional
if (this.conditional != null) {
Annotation conditionalAnnotation = (Annotation)idAnnotationMap.get(this.conditional.id);
if (conditionalAnnotation == null) {
throw new UnsupportedOperationException(String.format(
"no annotation with id '%s' in %s",
this.conditional.id,
this.sourceFile));
}
}
// get the negation
if (this.negation != null) {
Annotation negationAnnotation = (Annotation)idAnnotationMap.get(this.negation.id);
if (negationAnnotation == null) {
throw new UnsupportedOperationException(String.format(
"no annotation with id '%s' in %s",
this.negation.id,
this.sourceFile));
}
}
// get the uncertainty
if (this.uncertainty != null) {
Annotation uncertaintyAnnotation = (Annotation)idAnnotationMap.get(this.uncertainty.id);
if (uncertaintyAnnotation == null) {
throw new UnsupportedOperationException(String.format(
"no annotation with id '%s' in %s",
this.uncertainty.id,
this.sourceFile));
}
}
// add the relation to the CAS
BinaryTextRelation relation = null;
if ("affects".equals(this.annotation.type)) {
this.assertTypes(sourceMention, EventMention.class, targetMention, IdentifiedAnnotation.class);
relation = new AffectsTextRelation(jCas);
} else if ("complicates/disrupts".equals(this.annotation.type)) {
this.assertTypes(sourceMention, EventMention.class, targetMention, EventMention.class);
relation = new ComplicatesDisruptsTextRelation(jCas);
} else if ("causes/brings_about".equals(this.annotation.type)) {
this.assertTypes(sourceMention, EventMention.class, targetMention, EventMention.class);
relation = new CausesBringsAboutTextRelation(jCas);
} else if ("indicates".equals(this.annotation.type)) {
this.assertTypes(sourceMention, EventMention.class, targetMention, EventMention.class);
relation = new IndicatesTextRelation(jCas);
} else if ("degree_of".equals(this.annotation.type)) {
this.assertTypes(sourceMention, EventMention.class, targetMention, Modifier.class);
relation = new DegreeOfTextRelation(jCas);
} else if ("location_of".equals(this.annotation.type)) {
if (!(targetMention instanceof AnatomicalSiteMention) && (sourceMention instanceof AnatomicalSiteMention)) {
// fix reversed arguments in manual annotations
Annotation temp = sourceMention;
sourceMention = targetMention;
targetMention = temp;
// LOGGER.warn(String.format(
// "relation arguments in reverse order for \"%s\" annotation with id \"%s\"",
// annotation.type,
// annotation.id));
}
this.assertTypes(sourceMention, IdentifiedAnnotation.class, targetMention, AnatomicalSiteMention.class);
relation = new LocationOfTextRelation(jCas);
} else if ("manages/treats".equals(this.annotation.type)) {
this.assertTypes(sourceMention, EventMention.class, targetMention, EventMention.class);
relation = new ManagesTreatsTextRelation(jCas);
} else if ("manifestation_of".equals(this.annotation.type)) {
this.assertTypes(sourceMention, EventMention.class, targetMention, EventMention.class);
relation = new ManifestationOfTextRelation(jCas);
relation.setCategory("manifestation_of"); // fix typo in Knowtator type system
} else if ("prevents".equals(this.annotation.type)) {
this.assertTypes(sourceMention, EventMention.class, targetMention, EventMention.class);
relation = new PreventsTextRelation(jCas);
} else if ("result_of".equals(this.annotation.type)) {
this.assertTypes(sourceMention, EventMention.class, targetMention, IdentifiedAnnotation.class);
relation = new ResultOfTextRelation(jCas);
} else if ("TLINK".equals(this.annotation.type)) {
relation = new TemporalTextRelation(jCas);
relation.setCategory(this.type);
} else if ("ALINK".equals(this.annotation.type)) {
relation = new AspectualTextRelation(jCas);
relation.setCategory(this.type);
} else {
relation = new BinaryTextRelation(jCas);
}
// set the relation cateory (if not already set)
if (relation.getCategory() == null) {
relation.setCategory(this.annotation.type);
}
// link the relation to its arguments and add it to the CAS
RelationArgument sourceRA = new RelationArgument(jCas);
sourceRA.setArgument(sourceMention);
sourceRA.addToIndexes();
RelationArgument targetRA = new RelationArgument(jCas);
targetRA.setArgument(targetMention);
targetRA.addToIndexes();
relation.setArg1(sourceRA);
relation.setArg2(targetRA);
relation.addToIndexes();
// add the relation to the map so it can be used in features of other annotations
idAnnotationMap.put(this.annotation.id, relation);
}