Search in sources :

Example 66 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.

the class BratRenderer method buildEntityTypes.

/**
 * Generates brat type definitions from the WebAnno layer definitions.
 *
 * @param aAnnotationLayers
 *            the layers
 * @param aAnnotationService
 *            the annotation service
 * @return the brat type definitions
 */
public static Set<EntityType> buildEntityTypes(List<AnnotationLayer> aAnnotationLayers, AnnotationSchemaService aAnnotationService) {
    // Sort layers
    List<AnnotationLayer> layers = new ArrayList<>(aAnnotationLayers);
    layers.sort(Comparator.comparing(AnnotationLayer::getName));
    // Now build the actual configuration
    Set<EntityType> entityTypes = new LinkedHashSet<>();
    for (AnnotationLayer layer : layers) {
        EntityType entityType = configureEntityType(layer);
        List<RelationType> arcs = new ArrayList<>();
        // For link features, we also need to configure the arcs, even though there is no arc
        // layer here.
        boolean hasLinkFeatures = false;
        for (AnnotationFeature f : aAnnotationService.listAnnotationFeature(layer)) {
            if (!LinkMode.NONE.equals(f.getLinkMode())) {
                hasLinkFeatures = true;
                break;
            }
        }
        if (hasLinkFeatures) {
            String bratTypeName = getBratTypeName(layer);
            arcs.add(new RelationType(layer.getName(), layer.getUiName(), bratTypeName, bratTypeName, null, "triangle,5", "3,3"));
        }
        // Styles for the remaining relation and chain layers
        for (AnnotationLayer attachingLayer : getAttachingLayers(layer, layers, aAnnotationService)) {
            arcs.add(configureRelationType(layer, attachingLayer));
        }
        entityType.setArcs(arcs);
        entityTypes.add(entityType);
    }
    return entityTypes;
}
Also used : EntityType(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.EntityType) LinkedHashSet(java.util.LinkedHashSet) RelationType(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.RelationType) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 67 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.

the class ImportServiceImpl method importProject.

@Override
public Project importProject(File aProjectFile, boolean aGenerateUsers) throws Exception {
    Project importedProject = new Project();
    ZipFile zip = new ZipFile(aProjectFile);
    InputStream projectInputStream = null;
    for (Enumeration<? extends ZipEntry> zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements(); ) {
        ZipEntry entry = (ZipEntry) zipEnumerate.nextElement();
        if (entry.toString().replace("/", "").startsWith(ImportUtil.EXPORTED_PROJECT) && entry.toString().replace("/", "").endsWith(".json")) {
            projectInputStream = zip.getInputStream(entry);
            break;
        }
    }
    // Load the project model from the JSON file
    String text = IOUtils.toString(projectInputStream, "UTF-8");
    de.tudarmstadt.ukp.clarin.webanno.export.model.Project importedProjectSetting = JSONUtil.getJsonConverter().getObjectMapper().readValue(text, de.tudarmstadt.ukp.clarin.webanno.export.model.Project.class);
    // Import the project itself
    importedProject = ImportUtil.createProject(importedProjectSetting, projectService);
    // Import additional project things
    projectService.onProjectImport(zip, importedProjectSetting, importedProject);
    // Import missing users
    if (aGenerateUsers) {
        ImportUtil.createMissingUsers(importedProjectSetting, userRepository);
    }
    applicationEventPublisher.publishEvent(new ProjectImportEvent(this, zip, importedProjectSetting, importedProject));
    // Import layers
    Map<String, AnnotationFeature> featuresMap = ImportUtil.createLayer(importedProject, importedProjectSetting, userRepository, annotationService);
    /*
         * for (TagSet tagset : importedProjectSetting.getTagSets()) {
         * ImportUtil.createTagset(importedProject, tagset, projectRepository, annotationService); }
         */
    // Import source document
    ImportUtil.createSourceDocument(importedProjectSetting, importedProject, documentService);
    // Import Training document
    if (automationService != null) {
        ImportUtil.createTrainingDocument(importedProjectSetting, importedProject, automationService, featuresMap);
    }
    // Import source document content
    ImportUtil.createSourceDocumentContent(zip, importedProject, documentService);
    // Import training document content
    if (automationService != null) {
        ImportUtil.createTrainingDocumentContent(zip, importedProject, automationService);
    }
    // Import automation settings
    if (automationService != null) {
        ImportUtil.createMiraTemplate(importedProjectSetting, automationService, featuresMap);
    }
    // Import annotation document content
    ImportUtil.createAnnotationDocument(importedProjectSetting, importedProject, documentService);
    // Import annotation document content
    ImportUtil.createAnnotationDocumentContent(zip, importedProject, documentService);
    // Import curation document content
    ImportUtil.createCurationDocumentContent(zip, importedProject, documentService);
    return importedProject;
}
Also used : InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ZipFile(java.util.zip.ZipFile) ProjectImportEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.ProjectImportEvent) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 68 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.

the class ImportUtil method exportLayerDetails.

public static de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer exportLayerDetails(Map<AnnotationLayer, de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer> aLayerToExLayer, Map<AnnotationFeature, de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature> aFeatureToExFeature, AnnotationLayer aLayer, AnnotationSchemaService aAnnotationService) {
    de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer exLayer = new de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer();
    exLayer.setAllowStacking(aLayer.isAllowStacking());
    exLayer.setBuiltIn(aLayer.isBuiltIn());
    exLayer.setReadonly(aLayer.isReadonly());
    exLayer.setCrossSentence(aLayer.isCrossSentence());
    exLayer.setDescription(aLayer.getDescription());
    exLayer.setEnabled(aLayer.isEnabled());
    exLayer.setLockToTokenOffset(aLayer.isLockToTokenOffset());
    exLayer.setMultipleTokens(aLayer.isMultipleTokens());
    exLayer.setLinkedListBehavior(aLayer.isLinkedListBehavior());
    exLayer.setName(aLayer.getName());
    exLayer.setProjectName(aLayer.getProject().getName());
    exLayer.setType(aLayer.getType());
    exLayer.setUiName(aLayer.getUiName());
    if (aLayerToExLayer != null) {
        aLayerToExLayer.put(aLayer, exLayer);
    }
    List<de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature> exFeatures = new ArrayList<>();
    for (AnnotationFeature feature : aAnnotationService.listAnnotationFeature(aLayer)) {
        de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature exFeature = new de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature();
        exFeature.setDescription(feature.getDescription());
        exFeature.setEnabled(feature.isEnabled());
        exFeature.setRemember(feature.isRemember());
        exFeature.setRequired(feature.isRequired());
        exFeature.setHideUnconstraintFeature(feature.isHideUnconstraintFeature());
        exFeature.setName(feature.getName());
        exFeature.setProjectName(feature.getProject().getName());
        exFeature.setType(feature.getType());
        exFeature.setUiName(feature.getUiName());
        exFeature.setVisible(feature.isVisible());
        exFeature.setMultiValueMode(feature.getMultiValueMode());
        exFeature.setLinkMode(feature.getLinkMode());
        exFeature.setLinkTypeName(feature.getLinkTypeName());
        exFeature.setLinkTypeRoleFeatureName(feature.getLinkTypeRoleFeatureName());
        exFeature.setLinkTypeTargetFeatureName(feature.getLinkTypeTargetFeatureName());
        if (feature.getTagset() != null) {
            TagSet tagSet = feature.getTagset();
            ExportedTagSet exTagSet = new ExportedTagSet();
            exTagSet.setDescription(tagSet.getDescription());
            exTagSet.setLanguage(tagSet.getLanguage());
            exTagSet.setName(tagSet.getName());
            exTagSet.setCreateTag(tagSet.isCreateTag());
            List<ExportedTag> exportedTags = new ArrayList<>();
            for (Tag tag : aAnnotationService.listTags(tagSet)) {
                ExportedTag exTag = new ExportedTag();
                exTag.setDescription(tag.getDescription());
                exTag.setName(tag.getName());
                exportedTags.add(exTag);
            }
            exTagSet.setTags(exportedTags);
            exFeature.setTagSet(exTagSet);
        }
        exFeatures.add(exFeature);
        if (aFeatureToExFeature != null) {
            aFeatureToExFeature.put(feature, exFeature);
        }
    }
    exLayer.setFeatures(exFeatures);
    return exLayer;
}
Also used : ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ExportedTagSet(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) ExportedTagSet(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 69 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.

the class ImportUtil method createMiraTemplate.

public static void createMiraTemplate(de.tudarmstadt.ukp.clarin.webanno.export.model.Project aImportedProjectSetting, AutomationService aRepository, Map<String, AnnotationFeature> aFeatureMaps) {
    for (MiraTemplate exTemplate : aImportedProjectSetting.getMiraTemplates()) {
        de.tudarmstadt.ukp.clarin.webanno.automation.model.MiraTemplate template = new de.tudarmstadt.ukp.clarin.webanno.automation.model.MiraTemplate();
        template.setAnnotateAndRepeat(exTemplate.isAnnotateAndPredict());
        template.setAutomationStarted(false);
        template.setCurrentLayer(exTemplate.isCurrentLayer());
        template.setResult("---");
        template.setTrainFeature(aFeatureMaps.get(exTemplate.getTrainFeature().getName()));
        Set<AnnotationFeature> otherFeatures = new HashSet<>();
        if (exTemplate.getOtherFeatures() != null) {
            for (de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature other : exTemplate.getOtherFeatures()) {
                otherFeatures.add(aFeatureMaps.get(other.getName()));
            }
            template.setOtherFeatures(otherFeatures);
        }
        aRepository.createTemplate(template);
    }
}
Also used : MiraTemplate(de.tudarmstadt.ukp.clarin.webanno.export.model.MiraTemplate) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) HashSet(java.util.HashSet)

Example 70 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.

the class LegacyProjectInitializer method createDepLayer.

private void createDepLayer(Project aProject, TagSet aTagset) throws IOException {
    // Dependency Layer
    AnnotationLayer depLayer = new AnnotationLayer(Dependency.class.getName(), "Dependency", RELATION_TYPE, aProject, true);
    AnnotationLayer tokenLayer = annotationSchemaService.getLayer(Token.class.getName(), aProject);
    List<AnnotationFeature> tokenFeatures = annotationSchemaService.listAnnotationFeature(tokenLayer);
    AnnotationFeature tokenPosFeature = null;
    for (AnnotationFeature feature : tokenFeatures) {
        if (feature.getName().equals("pos")) {
            tokenPosFeature = feature;
            break;
        }
    }
    depLayer.setAttachType(tokenLayer);
    depLayer.setAttachFeature(tokenPosFeature);
    annotationSchemaService.createLayer(depLayer);
    annotationSchemaService.createFeature(new AnnotationFeature(aProject, depLayer, "DependencyType", "Relation", CAS.TYPE_NAME_STRING, "Dependency relation", aTagset));
    String[] flavors = { DependencyFlavor.BASIC, DependencyFlavor.ENHANCED };
    String[] flavorDesc = { DependencyFlavor.BASIC, DependencyFlavor.ENHANCED };
    TagSet flavorsTagset = annotationSchemaService.createTagSet("Dependency flavors", "Dependency flavors", "mul", flavors, flavorDesc, aProject);
    annotationSchemaService.createFeature(new AnnotationFeature(aProject, depLayer, "flavor", "Flavor", CAS.TYPE_NAME_STRING, "Dependency relation", flavorsTagset));
}
Also used : TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Dependency(de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)73 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)34 Feature (org.apache.uima.cas.Feature)20 ArrayList (java.util.ArrayList)16 Type (org.apache.uima.cas.Type)16 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)15 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)12 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)11 JCas (org.apache.uima.jcas.JCas)10 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)9 File (java.io.File)9 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)8 LinkWithRoleModel (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel)6 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)6 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)6 List (java.util.List)6 FeatureStructure (org.apache.uima.cas.FeatureStructure)6 ArcAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter)5 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)5 FeatureSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry)5