Search in sources :

Example 11 with TypeSystem

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);
}
Also used : TypeSystem(org.apache.uima.cas.TypeSystem) CAS(org.apache.uima.cas.CAS) TypeDescription(org.apache.uima.resource.metadata.TypeDescription)

Example 12 with TypeSystem

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;
}
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) Type(org.apache.uima.cas.Type) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

TypeSystem (org.apache.uima.cas.TypeSystem)12 CAS (org.apache.uima.cas.CAS)7 Feature (org.apache.uima.cas.Feature)7 Type (org.apache.uima.cas.Type)7 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)6 ArrayList (java.util.ArrayList)4 FeatureStructure (org.apache.uima.cas.FeatureStructure)4 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)4 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)3 Arrays.asList (java.util.Arrays.asList)3 List (java.util.List)3 Map (java.util.Map)3 WebAnnoConst (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst)2 CHAIN_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CHAIN_TYPE)2 FEAT_REL_SOURCE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.FEAT_REL_SOURCE)2 FEAT_REL_TARGET (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.FEAT_REL_TARGET)2 RELATION_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.RELATION_TYPE)2 SPAN_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.SPAN_TYPE)2 Evaluator (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator)2 PossibleValue (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue)2