use of org.apache.uima.cas.TypeSystem in project webanno by webanno.
the class TypeSystemAnalysis method analyzeTypeSystem.
private void analyzeTypeSystem(TypeSystemDescription aTSD) throws ResourceInitializationException {
// We create a CAS from which we can obtain an instantiated type system. With that, it
// is easier to check type inheritance.
CAS cas = CasCreationUtils.createCas(aTSD, null, null);
TypeSystem ts = cas.getTypeSystem();
for (TypeDescription td : aTSD.getTypes()) {
analyzeType(ts, aTSD, td);
}
log.debug("Recognized {} of {} types as layers ({}%)", getLayers().size(), aTSD.getTypes().length, getLayers().size() * 100 / aTSD.getTypes().length);
}
use of org.apache.uima.cas.TypeSystem in project webanno by webanno.
the class TypeSystemAnalysis method isSlotFeature.
private boolean isSlotFeature(TypeSystem aTS, Feature aFeature) {
// Slot features are multi-valued
if (!FSUtil.isMultiValuedFeature(aTS, aFeature)) {
return false;
}
// The component type is the link type - it must be present
Type linkType = aFeature.getRange().getComponentType();
if (linkType == null) {
return false;
}
// The range of the slot feature is its link type which must inherit from TOP
if (!aTS.getTopType().equals(aTS.getParent(linkType))) {
return false;
}
// The link feature must have exactly two features (link-with-role)
if (linkType.getFeatures().size() != 2) {
return false;
}
Optional<Feature> roleFeature = linkType.getFeatures().stream().filter(f -> f.getRange().getName().equals(CAS.TYPE_NAME_STRING)).findFirst();
if (!roleFeature.isPresent()) {
return false;
}
Optional<Feature> linkFeature = linkType.getFeatures().stream().filter(f -> !f.getRange().isPrimitive()).findFirst();
if (!linkFeature.isPresent()) {
return false;
}
// Hm, ok, so this looks like a slot feature.
return true;
}
Aggregations