Search in sources :

Example 1 with FEAT_REL_SOURCE

use of de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.FEAT_REL_SOURCE 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);
}
Also used : FEAT_REL_SOURCE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.FEAT_REL_SOURCE) FEAT_REL_TARGET(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.FEAT_REL_TARGET) TypeDescription(org.apache.uima.resource.metadata.TypeDescription) LoggerFactory(org.slf4j.LoggerFactory) CAS(org.apache.uima.cas.CAS) Feature(org.apache.uima.cas.Feature) HashMap(java.util.HashMap) LinkMode(de.tudarmstadt.ukp.clarin.webanno.model.LinkMode) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) FSUtil(org.apache.uima.fit.util.FSUtil) ArrayList(java.util.ArrayList) Type(org.apache.uima.cas.Type) HashSet(java.util.HashSet) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) Arrays.asList(java.util.Arrays.asList) ListValuedMap(org.apache.commons.collections4.ListValuedMap) Map(java.util.Map) TypeSystem(org.apache.uima.cas.TypeSystem) StringUtils.trimToNull(org.apache.commons.lang3.StringUtils.trimToNull) Logger(org.slf4j.Logger) MultiValueMode(de.tudarmstadt.ukp.clarin.webanno.model.MultiValueMode) WebAnnoConst(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst) Set(java.util.Set) RELATION_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.RELATION_TYPE) SPAN_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.SPAN_TYPE) Collectors(java.util.stream.Collectors) CasCreationUtils(org.apache.uima.util.CasCreationUtils) List(java.util.List) FeatureDescription(org.apache.uima.resource.metadata.FeatureDescription) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) StringUtils.removeEnd(org.apache.commons.lang3.StringUtils.removeEnd) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) CHAIN_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CHAIN_TYPE) Optional(java.util.Optional) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

WebAnnoConst (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst)1 CHAIN_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CHAIN_TYPE)1 FEAT_REL_SOURCE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.FEAT_REL_SOURCE)1 FEAT_REL_TARGET (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.FEAT_REL_TARGET)1 RELATION_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.RELATION_TYPE)1 SPAN_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.SPAN_TYPE)1 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)1 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)1 LinkMode (de.tudarmstadt.ukp.clarin.webanno.model.LinkMode)1 MultiValueMode (de.tudarmstadt.ukp.clarin.webanno.model.MultiValueMode)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ListValuedMap (org.apache.commons.collections4.ListValuedMap)1