Search in sources :

Example 1 with TypeDescription

use of org.apache.uima.resource.metadata.TypeDescription in project webanno by webanno.

the class AnnotationSchemaServiceImpl method getProjectTypes.

@Override
public TypeSystemDescription getProjectTypes(Project aProject) {
    // Create a new type system from scratch
    TypeSystemDescription tsd = new TypeSystemDescription_impl();
    for (AnnotationLayer type : listAnnotationLayer(aProject)) {
        if (type.getType().equals(SPAN_TYPE) && !type.isBuiltIn()) {
            TypeDescription td = tsd.addType(type.getName(), "", CAS.TYPE_NAME_ANNOTATION);
            generateFeatures(tsd, td, type);
        } else if (type.getType().equals(RELATION_TYPE) && !type.isBuiltIn()) {
            TypeDescription td = tsd.addType(type.getName(), "", CAS.TYPE_NAME_ANNOTATION);
            AnnotationLayer attachType = type.getAttachType();
            td.addFeature(WebAnnoConst.FEAT_REL_TARGET, "", attachType.getName());
            td.addFeature(WebAnnoConst.FEAT_REL_SOURCE, "", attachType.getName());
            generateFeatures(tsd, td, type);
        } else if (type.getType().equals(CHAIN_TYPE) && !type.isBuiltIn()) {
            TypeDescription tdChains = tsd.addType(type.getName() + "Chain", "", CAS.TYPE_NAME_ANNOTATION_BASE);
            tdChains.addFeature("first", "", type.getName() + "Link");
            // Custom features on chain layers are currently not supported
            // generateFeatures(tsd, tdChains, type);
            TypeDescription tdLink = tsd.addType(type.getName() + "Link", "", CAS.TYPE_NAME_ANNOTATION);
            tdLink.addFeature("next", "", type.getName() + "Link");
            tdLink.addFeature("referenceType", "", CAS.TYPE_NAME_STRING);
            tdLink.addFeature("referenceRelation", "", CAS.TYPE_NAME_STRING);
        }
    }
    return tsd;
}
Also used : TypeSystemDescription_impl(org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) TypeDescription(org.apache.uima.resource.metadata.TypeDescription) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 2 with TypeDescription

use of org.apache.uima.resource.metadata.TypeDescription in project webanno by webanno.

the class SlotFeatureSupport method generateFeature.

@Override
public void generateFeature(TypeSystemDescription aTSD, TypeDescription aTD, AnnotationFeature aFeature) {
    // Link type
    TypeDescription linkTD = aTSD.addType(aFeature.getLinkTypeName(), "", CAS.TYPE_NAME_TOP);
    linkTD.addFeature(aFeature.getLinkTypeRoleFeatureName(), "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature(aFeature.getLinkTypeTargetFeatureName(), "", aFeature.getType());
    // Link feature
    aTD.addFeature(aFeature.getName(), "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);
}
Also used : TypeDescription(org.apache.uima.resource.metadata.TypeDescription)

Example 3 with TypeDescription

use of org.apache.uima.resource.metadata.TypeDescription in project webanno by webanno.

the class TypeSystemAnalysis method analyzeType.

private void analyzeType(TypeSystem aTS, TypeSystemDescription aTSD, TypeDescription aTD) {
    log.trace("Analyzing [{}]", aTD.getName());
    Type type = aTS.getType(aTD.getName());
    // Skip built-in UIMA types
    if (aTD.getName().startsWith("uima.tcas.")) {
        log.debug("[{}] is a built-in UIMA type. Skipping.", aTD.getName());
        return;
    }
    // Skip document metadata types
    if (aTS.subsumes(aTS.getType(CAS.TYPE_NAME_DOCUMENT_ANNOTATION), type)) {
        log.debug("[{}] is a document-level annotation. Skipping.", type.getName());
        return;
    }
    // Skip DKPro Core Token and Sentence which as handled specially by WebAnno
    if ("de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence".equals(aTD.getName()) || "de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token".equals(aTD.getName())) {
        log.debug("[{}] is a DKPro Core segmentation type. Skipping.", aTD.getName());
        return;
    }
    Optional<RelationDetails> relationDetails = analyzeRelationLayer(aTS, type);
    Optional<ChainDetails> chainDetails = analyzeChainLayer(aTS, type);
    boolean isChain = chainDetails.isPresent();
    // Layers must be sub-types of Annotation (unless they are chains)
    if (!isChain && !aTS.subsumes(aTS.getType(CAS.TYPE_NAME_ANNOTATION), type)) {
        log.debug("[{}] is not an annotation type. Skipping.", aTD.getName());
        return;
    }
    // because WebAnno presently does not support DKPro Core elevated types (e.g. NOUN).
    if (isElevatedType(aTS, type)) {
        log.debug("[{}] looks like an elevated type. Skipping.", aTD.getName());
        return;
    }
    AnnotationLayer layer = new AnnotationLayer();
    Optional<? extends LayerDetails> details;
    if (isChain) {
        details = chainDetails;
        layer.setName(removeEnd(aTD.getName(), "Chain"));
        layer.setUiName(removeEnd(type.getShortName(), "Chain"));
        layer.setType(CHAIN_TYPE);
        chainDetailMap.put(layer.getName(), chainDetails.get());
    } else if (relationDetails.isPresent()) {
        details = relationDetails;
        layer.setName(aTD.getName());
        layer.setUiName(type.getShortName());
        layer.setType(RELATION_TYPE);
        relationDetailMap.put(layer.getName(), relationDetails.get());
    } else if (isSpanLayer(aTS, type)) {
        details = Optional.empty();
        layer.setName(aTD.getName());
        layer.setUiName(type.getShortName());
        layer.setType(SPAN_TYPE);
    } else {
        log.debug("Unable to determine layer type for [{}]", type.getName());
        return;
    }
    log.debug("[{}] seems to be a {}", aTD.getName(), layer.getType());
    layer.setDescription(trimToNull(aTD.getDescription()));
    layer.setEnabled(true);
    layer.setBuiltIn(false);
    // We cannot determine good values for these without looking at actual annotations, thus
    // we choose the most relaxed/permissive configuration here.
    layer.setAllowStacking(true);
    layer.setCrossSentence(true);
    layer.setLockToTokenOffset(false);
    layer.setMultipleTokens(false);
    layer.setLinkedListBehavior(false);
    layers.add(layer);
    // any features for it - instead we record the features of the link type.
    if (CHAIN_TYPE.equals(layer.getType())) {
        TypeDescription linkTypeDescription = aTSD.getType(layer.getName() + "Link");
        analyzeFeatures(layer, aTS, linkTypeDescription, details);
    } else {
        analyzeFeatures(layer, aTS, aTD, details);
    }
}
Also used : Type(org.apache.uima.cas.Type) TypeDescription(org.apache.uima.resource.metadata.TypeDescription) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 4 with TypeDescription

use of org.apache.uima.resource.metadata.TypeDescription in project webanno by webanno.

the class DiffUtils method createMultiLinkWithRoleTestTypeSytem.

public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem(String... aFeatures) throws Exception {
    List<TypeSystemDescription> typeSystems = new ArrayList<>();
    TypeSystemDescription tsd = new TypeSystemDescription_impl();
    // Link type
    TypeDescription linkTD = tsd.addType(LINK_TYPE, "", CAS.TYPE_NAME_TOP);
    linkTD.addFeature("role", "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature("target", "", Token.class.getName());
    // Link host
    TypeDescription hostTD = tsd.addType(HOST_TYPE, "", CAS.TYPE_NAME_ANNOTATION);
    hostTD.addFeature("links", "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);
    for (String feature : aFeatures) {
        hostTD.addFeature(feature, "", CAS.TYPE_NAME_STRING);
    }
    typeSystems.add(tsd);
    typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());
    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
Also used : TypeSystemDescription_impl(org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) ArrayList(java.util.ArrayList) TypeDescription(org.apache.uima.resource.metadata.TypeDescription) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)

Example 5 with TypeDescription

use of org.apache.uima.resource.metadata.TypeDescription in project webanno by webanno.

the class DiffUtils method createMultiLinkWithRoleTestTypeSytem.

public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem() throws Exception {
    List<TypeSystemDescription> typeSystems = new ArrayList<>();
    TypeSystemDescription tsd = new TypeSystemDescription_impl();
    // Link type
    TypeDescription linkTD = tsd.addType(LINK_TYPE, "", CAS.TYPE_NAME_TOP);
    linkTD.addFeature("role", "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature("target", "", Token.class.getName());
    // Link host
    TypeDescription hostTD = tsd.addType(HOST_TYPE, "", CAS.TYPE_NAME_ANNOTATION);
    hostTD.addFeature("links", "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);
    typeSystems.add(tsd);
    typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());
    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
Also used : TypeSystemDescription_impl(org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) ArrayList(java.util.ArrayList) TypeDescription(org.apache.uima.resource.metadata.TypeDescription) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)

Aggregations

TypeDescription (org.apache.uima.resource.metadata.TypeDescription)9 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)5 ArrayList (java.util.ArrayList)4 CAS (org.apache.uima.cas.CAS)3 Type (org.apache.uima.cas.Type)3 TypeSystemDescription_impl (org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl)3 CasDoctor (de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor)2 LogMessage (de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage)2 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)2 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)2 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 AnalysisEngine (org.apache.uima.analysis_engine.AnalysisEngine)1 TypeSystem (org.apache.uima.cas.TypeSystem)1 ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1