use of de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.FEAT_REL_TARGET in project webanno by webanno.
the class TypeSystemAnalysis method analyzeRelationLayer.
private Optional<RelationDetails> analyzeRelationLayer(TypeSystem aTS, Type aType) {
// A UIMA type can be a relation layer if...
// ... there are exactly two non-primitive features
// ... both have the same range
// ... the range is a span layer
List<Feature> nonPrimitiveFeatures = aType.getFeatures().stream().filter(f -> !isBuiltInFeature(f)).filter(f -> !f.getRange().isPrimitive()).collect(Collectors.toList());
// ... there are exactly two non-primitive features
if (nonPrimitiveFeatures.size() != 2) {
return Optional.empty();
}
Feature ref1 = nonPrimitiveFeatures.get(0);
Feature ref2 = nonPrimitiveFeatures.get(1);
// Relations must use the names "Governor" and "Dependent" for its references because
// these names are hardcoded throughout WebAnno.
List<String> validNames = asList(FEAT_REL_SOURCE, FEAT_REL_TARGET);
if (!validNames.contains(ref1.getShortName()) || !validNames.contains(ref2.getShortName())) {
return Optional.empty();
}
// ... both have the same range
if (!ref1.getRange().getName().equals(ref2.getRange().getName())) {
return Optional.empty();
}
// Annotation should be fine.
if (!aTS.subsumes(aTS.getType(CAS.TYPE_NAME_ANNOTATION), ref1.getRange())) {
return Optional.empty();
}
RelationDetails details = new RelationDetails();
details.attachLayer = ref1.getRange().getName();
details.sourceFeature = WebAnnoConst.FEAT_REL_SOURCE;
details.targetFeature = WebAnnoConst.FEAT_REL_TARGET;
// Hm, ok, so this looks like a relation layer.
return Optional.of(details);
}
Aggregations