Search in sources :

Example 6 with AnnotationFeature

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

the class OrthographyLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    AnnotationLayer orthography = new AnnotationLayer(SofaChangeAnnotation.class.getName(), "Orthography Correction", SPAN_TYPE, aProject, true);
    orthography.setAllowStacking(false);
    orthography.setMultipleTokens(false);
    orthography.setLockToTokenOffset(true);
    annotationSchemaService.createLayer(orthography);
    AnnotationFeature correction = new AnnotationFeature();
    correction.setDescription("Correct this token using the specified operation.");
    correction.setName("value");
    correction.setType(CAS.TYPE_NAME_STRING);
    correction.setProject(aProject);
    correction.setUiName("Correction");
    correction.setLayer(orthography);
    annotationSchemaService.createFeature(correction);
    TagSet operationTagset = annotationSchemaService.createTagSet("operation to be done with specified in tokenIDs token/tokens in order to correct", "Operation", "en", new String[] { "replace", "insert_before", "insert_after", "delete" }, new String[] { "replace", "insert before", "insert after", "delete" }, aProject);
    AnnotationFeature operation = new AnnotationFeature();
    operation.setDescription("An operation taken to change this token.");
    operation.setName("operation");
    operation.setType(CAS.TYPE_NAME_STRING);
    operation.setProject(aProject);
    operation.setUiName("Operation");
    operation.setLayer(orthography);
    operation.setVisible(false);
    operation.setTagset(operationTagset);
    annotationSchemaService.createFeature(operation);
}
Also used : SofaChangeAnnotation(de.tudarmstadt.ukp.dkpro.core.api.transform.type.SofaChangeAnnotation) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 7 with AnnotationFeature

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

the class PartOfSpeechLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    TagSet posTagSet = JsonImportUtil.importTagSetFromJson(aProject, new ClassPathResource("/tagsets/mul-pos-ud.json").getInputStream(), annotationSchemaService);
    AnnotationLayer tokenLayer = annotationSchemaService.getLayer(Token.class.getName(), aProject);
    AnnotationLayer posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE, aProject, true);
    AnnotationFeature tokenPosFeature = new AnnotationFeature(aProject, tokenLayer, "pos", "pos", POS.class.getName());
    annotationSchemaService.createFeature(tokenPosFeature);
    posLayer.setAttachType(tokenLayer);
    posLayer.setAttachFeature(tokenPosFeature);
    annotationSchemaService.createLayer(posLayer);
    annotationSchemaService.createFeature(new AnnotationFeature(aProject, posLayer, "PosValue", "PosValue", CAS.TYPE_NAME_STRING, "Part-of-speech tag", posTagSet));
}
Also used : POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ClassPathResource(org.springframework.core.io.ClassPathResource) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 8 with AnnotationFeature

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

the class ChunkLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    AnnotationLayer chunkLayer = new AnnotationLayer(Chunk.class.getName(), "Chunk", SPAN_TYPE, aProject, true);
    chunkLayer.setAllowStacking(false);
    chunkLayer.setMultipleTokens(true);
    chunkLayer.setLockToTokenOffset(false);
    annotationSchemaService.createLayer(chunkLayer);
    AnnotationFeature chunkValueFeature = new AnnotationFeature();
    chunkValueFeature.setDescription("Chunk tag");
    chunkValueFeature.setName("chunkValue");
    chunkValueFeature.setType(CAS.TYPE_NAME_STRING);
    chunkValueFeature.setProject(aProject);
    chunkValueFeature.setUiName("Tag");
    chunkValueFeature.setLayer(chunkLayer);
    annotationSchemaService.createFeature(chunkValueFeature);
}
Also used : AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Chunk(de.tudarmstadt.ukp.dkpro.core.api.syntax.type.chunk.Chunk) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 9 with AnnotationFeature

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

the class LemmaLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    AnnotationLayer tokenLayer = annotationSchemaService.getLayer(Token.class.getName(), aProject);
    AnnotationFeature tokenLemmaFeature = new AnnotationFeature(aProject, tokenLayer, "lemma", "lemma", Lemma.class.getName());
    annotationSchemaService.createFeature(tokenLemmaFeature);
    AnnotationLayer lemmaLayer = new AnnotationLayer(Lemma.class.getName(), "Lemma", SPAN_TYPE, aProject, true);
    lemmaLayer.setAttachType(tokenLayer);
    lemmaLayer.setAttachFeature(tokenLemmaFeature);
    annotationSchemaService.createLayer(lemmaLayer);
    AnnotationFeature lemmaFeature = new AnnotationFeature();
    lemmaFeature.setDescription("lemma Annotation");
    lemmaFeature.setName("value");
    lemmaFeature.setType(CAS.TYPE_NAME_STRING);
    lemmaFeature.setProject(aProject);
    lemmaFeature.setUiName("Lemma");
    lemmaFeature.setLayer(lemmaLayer);
    annotationSchemaService.createFeature(lemmaFeature);
}
Also used : Lemma(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 10 with AnnotationFeature

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

the class ExportUtil method exportProjectSettings.

public static de.tudarmstadt.ukp.clarin.webanno.export.model.Project exportProjectSettings(AnnotationSchemaService annotationService, Optional<AutomationService> automationService, DocumentService documentService, ProjectService projectService, Project aProject, File aProjectSettings, File aExportTempDir) {
    de.tudarmstadt.ukp.clarin.webanno.export.model.Project exProjekt = new de.tudarmstadt.ukp.clarin.webanno.export.model.Project();
    exProjekt.setDescription(aProject.getDescription());
    exProjekt.setName(aProject.getName());
    // In older versions of WebAnno, the mode was an enum which was serialized as upper-case
    // during export but as lower-case in the database. This is compensating for this case.
    exProjekt.setMode(StringUtils.upperCase(aProject.getMode(), Locale.US));
    exProjekt.setScriptDirection(aProject.getScriptDirection());
    exProjekt.setVersion(aProject.getVersion());
    exProjekt.setDisableExport(aProject.isDisableExport());
    exProjekt.setCreated(aProject.getCreated());
    exProjekt.setUpdated(aProject.getUpdated());
    List<de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer> exLayers = new ArrayList<>();
    // Store map of layer and its equivalent exLayer so that the attach type is attached later
    Map<AnnotationLayer, de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer> layerToExLayers = new HashMap<>();
    // Store map of feature and its equivalent exFeature so that the attach feature is attached
    // later
    Map<AnnotationFeature, de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature> featureToExFeatures = new HashMap<>();
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
        exLayers.add(ImportUtil.exportLayerDetails(layerToExLayers, featureToExFeatures, layer, annotationService));
    }
    // exported feature
    for (AnnotationLayer layer : layerToExLayers.keySet()) {
        if (layer.getAttachType() != null) {
            layerToExLayers.get(layer).setAttachType(layerToExLayers.get(layer.getAttachType()));
        }
        if (layer.getAttachFeature() != null) {
            layerToExLayers.get(layer).setAttachFeature(featureToExFeatures.get(layer.getAttachFeature()));
        }
    }
    exProjekt.setLayers(exLayers);
    List<ExportedTagSet> extTagSets = new ArrayList<>();
    for (TagSet tagSet : annotationService.listTagSets(aProject)) {
        ExportedTagSet exTagSet = new ExportedTagSet();
        exTagSet.setCreateTag(tagSet.isCreateTag());
        exTagSet.setDescription(tagSet.getDescription());
        exTagSet.setLanguage(tagSet.getLanguage());
        exTagSet.setName(tagSet.getName());
        List<ExportedTag> exTags = new ArrayList<>();
        for (Tag tag : annotationService.listTags(tagSet)) {
            ExportedTag exTag = new ExportedTag();
            exTag.setDescription(tag.getDescription());
            exTag.setName(tag.getName());
            exTags.add(exTag);
        }
        exTagSet.setTags(exTags);
        extTagSets.add(exTagSet);
    }
    exProjekt.setTagSets(extTagSets);
    List<SourceDocument> sourceDocuments = new ArrayList<>();
    List<AnnotationDocument> annotationDocuments = new ArrayList<>();
    // add source documents to a project
    List<de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument> documents = documentService.listSourceDocuments(aProject);
    for (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument sourceDocument : documents) {
        SourceDocument exDocument = new SourceDocument();
        exDocument.setFormat(sourceDocument.getFormat());
        exDocument.setName(sourceDocument.getName());
        exDocument.setState(sourceDocument.getState());
        exDocument.setTimestamp(sourceDocument.getTimestamp());
        exDocument.setSentenceAccessed(sourceDocument.getSentenceAccessed());
        exDocument.setCreated(sourceDocument.getCreated());
        exDocument.setUpdated(sourceDocument.getUpdated());
        // add annotation document to Project
        for (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument annotationDocument : documentService.listAnnotationDocuments(sourceDocument)) {
            AnnotationDocument annotationDocumentToExport = new AnnotationDocument();
            annotationDocumentToExport.setName(annotationDocument.getName());
            annotationDocumentToExport.setState(annotationDocument.getState());
            annotationDocumentToExport.setUser(annotationDocument.getUser());
            annotationDocumentToExport.setTimestamp(annotationDocument.getTimestamp());
            annotationDocumentToExport.setSentenceAccessed(annotationDocument.getSentenceAccessed());
            annotationDocumentToExport.setCreated(annotationDocument.getCreated());
            annotationDocumentToExport.setUpdated(annotationDocument.getUpdated());
            annotationDocuments.add(annotationDocumentToExport);
        }
        sourceDocuments.add(exDocument);
    }
    exProjekt.setSourceDocuments(sourceDocuments);
    exProjekt.setAnnotationDocuments(annotationDocuments);
    if (automationService.isPresent()) {
        List<de.tudarmstadt.ukp.clarin.webanno.export.model.TrainingDocument> trainDocuments = new ArrayList<>();
        List<TrainingDocument> trainingDocuments = automationService.get().listTrainingDocuments(aProject);
        Map<String, de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature> fm = new HashMap<>();
        for (de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature f : featureToExFeatures.values()) {
            fm.put(f.getName(), f);
        }
        for (TrainingDocument trainingDocument : trainingDocuments) {
            de.tudarmstadt.ukp.clarin.webanno.export.model.TrainingDocument exDocument = new de.tudarmstadt.ukp.clarin.webanno.export.model.TrainingDocument();
            exDocument.setFormat(trainingDocument.getFormat());
            exDocument.setName(trainingDocument.getName());
            exDocument.setState(trainingDocument.getState());
            exDocument.setTimestamp(trainingDocument.getTimestamp());
            exDocument.setSentenceAccessed(trainingDocument.getSentenceAccessed());
            if (trainingDocument.getFeature() != null) {
                exDocument.setFeature(fm.get(trainingDocument.getFeature().getName()));
            }
            trainDocuments.add(exDocument);
        }
        exProjekt.setTrainingDocuments(trainDocuments);
    } else {
        exProjekt.setTrainingDocuments(new ArrayList<>());
    }
    List<ProjectPermission> projectPermissions = new ArrayList<>();
    // add project permissions to the project
    for (User user : projectService.listProjectUsersWithPermissions(aProject)) {
        for (de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission permission : projectService.listProjectPermissionLevel(user, aProject)) {
            ProjectPermission permissionToExport = new ProjectPermission();
            permissionToExport.setLevel(permission.getLevel());
            permissionToExport.setUser(user.getUsername());
            projectPermissions.add(permissionToExport);
        }
    }
    exProjekt.setProjectPermissions(projectPermissions);
    // export automation Mira template
    if (automationService.isPresent()) {
        List<de.tudarmstadt.ukp.clarin.webanno.export.model.MiraTemplate> exTemplates = new ArrayList<>();
        for (MiraTemplate template : automationService.get().listMiraTemplates(aProject)) {
            de.tudarmstadt.ukp.clarin.webanno.export.model.MiraTemplate exTemplate = new de.tudarmstadt.ukp.clarin.webanno.export.model.MiraTemplate();
            exTemplate.setAnnotateAndPredict(template.isAnnotateAndRepeat());
            exTemplate.setAutomationStarted(template.isAutomationStarted());
            exTemplate.setCurrentLayer(template.isCurrentLayer());
            exTemplate.setResult(template.getResult());
            exTemplate.setTrainFeature(featureToExFeatures.get(template.getTrainFeature()));
            if (template.getOtherFeatures().size() > 0) {
                Set<de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature> exOtherFeatures = new HashSet<>();
                for (AnnotationFeature feature : template.getOtherFeatures()) {
                    exOtherFeatures.add(featureToExFeatures.get(feature));
                }
                exTemplate.setOtherFeatures(exOtherFeatures);
            }
            exTemplates.add(exTemplate);
        }
        exProjekt.setMiraTemplates(exTemplates);
    } else {
        exProjekt.setMiraTemplates(new ArrayList<>());
    }
    return exProjekt;
}
Also used : Mode(de.tudarmstadt.ukp.clarin.webanno.model.Mode) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationDocument) 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) ProjectPermission(de.tudarmstadt.ukp.clarin.webanno.export.model.ProjectPermission) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) HashSet(java.util.HashSet) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.export.model.SourceDocument) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) MiraTemplate(de.tudarmstadt.ukp.clarin.webanno.automation.model.MiraTemplate) 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) TrainingDocument(de.tudarmstadt.ukp.clarin.webanno.model.TrainingDocument)

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