Search in sources :

Example 11 with Tag

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

the class AutomationPage method createDetailEditor.

private AnnotationDetailEditorPanel createDetailEditor() {
    return new AnnotationDetailEditorPanel("annotationDetailEditorPanel", getModel()) {

        private static final long serialVersionUID = 2857345299480098279L;

        @Override
        protected void onChange(AjaxRequestTarget aTarget) {
            AnnotatorState state = getModelObject();
            aTarget.addChildren(getPage(), IFeedback.class);
            try {
                annotationEditor.requestRender(aTarget);
            } catch (Exception e) {
                handleException(this, aTarget, e);
                return;
            }
            try {
                SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
                curationContainer = builder.buildCurationContainer(state);
                setCurationSegmentBeginEnd(getEditorCas());
                curationContainer.setBratAnnotatorModel(state);
                suggestionView.updatePanel(aTarget, curationContainer, annotationSelectionByUsernameAndAddress, curationSegment);
                update(aTarget);
            } catch (Exception e) {
                handleException(this, aTarget, e);
            }
        }

        @Override
        public void onAnnotate(AjaxRequestTarget aTarget) {
            AnnotatorState state = getModelObject();
            if (state.isForwardAnnotation()) {
                return;
            }
            AnnotationLayer layer = state.getSelectedAnnotationLayer();
            int address = state.getSelection().getAnnotation().getId();
            try {
                JCas jCas = getEditorCas();
                AnnotationFS fs = selectByAddr(jCas, address);
                for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
                    Type type = CasUtil.getType(fs.getCAS(), layer.getName());
                    Feature feat = type.getFeatureByBaseName(f.getName());
                    if (!automationService.existsMiraTemplate(f)) {
                        continue;
                    }
                    if (!automationService.getMiraTemplate(f).isAnnotateAndRepeat()) {
                        continue;
                    }
                    TagSet tagSet = f.getTagset();
                    boolean isRepeatable = false;
                    // repeat only if the value is in the tagset
                    for (Tag tag : annotationService.listTags(tagSet)) {
                        if (fs.getFeatureValueAsString(feat) == null) {
                            // this is new annotation without values
                            break;
                        }
                        if (fs.getFeatureValueAsString(feat).equals(tag.getName())) {
                            isRepeatable = true;
                            break;
                        }
                    }
                    if (automationService.getMiraTemplate(f) != null && isRepeatable) {
                        if (layer.getType().endsWith(WebAnnoConst.RELATION_TYPE)) {
                            AutomationUtil.repeateRelationAnnotation(state, documentService, correctionDocumentService, annotationService, fs, f, fs.getFeatureValueAsString(feat));
                            update(aTarget);
                            break;
                        } else if (layer.getType().endsWith(WebAnnoConst.SPAN_TYPE)) {
                            AutomationUtil.repeateSpanAnnotation(state, documentService, correctionDocumentService, annotationService, fs.getBegin(), fs.getEnd(), f, fs.getFeatureValueAsString(feat));
                            update(aTarget);
                            break;
                        }
                    }
                }
            } catch (Exception e) {
                handleException(this, aTarget, e);
            }
        }

        @Override
        protected void onAutoForward(AjaxRequestTarget aTarget) {
            annotationEditor.requestRender(aTarget);
        }

        @Override
        public void onDelete(AjaxRequestTarget aTarget, AnnotationFS aFS) {
            AnnotatorState state = getModelObject();
            AnnotationLayer layer = state.getSelectedAnnotationLayer();
            for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
                if (!automationService.existsMiraTemplate(f)) {
                    continue;
                }
                if (!automationService.getMiraTemplate(f).isAnnotateAndRepeat()) {
                    continue;
                }
                try {
                    Type type = CasUtil.getType(aFS.getCAS(), layer.getName());
                    Feature feat = type.getFeatureByBaseName(f.getName());
                    if (layer.getType().endsWith(WebAnnoConst.RELATION_TYPE)) {
                        AutomationUtil.deleteRelationAnnotation(state, documentService, correctionDocumentService, annotationService, aFS, f, aFS.getFeatureValueAsString(feat));
                    } else {
                        AutomationUtil.deleteSpanAnnotation(state, documentService, correctionDocumentService, annotationService, aFS.getBegin(), aFS.getEnd(), f, aFS.getFeatureValueAsString(feat));
                    }
                    update(aTarget);
                } catch (Exception e) {
                    handleException(this, aTarget, e);
                }
            }
        }
    };
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) AnnotationDetailEditorPanel(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) ProjectType(de.tudarmstadt.ukp.clarin.webanno.api.ProjectType) KeyType(wicket.contrib.input.events.key.KeyType) EventType(wicket.contrib.input.events.EventType) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) SuggestionBuilder(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 12 with Tag

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

the class AnnotationSchemaServiceImpl method createTagSet.

@Override
public TagSet createTagSet(String aDescription, String aTagSetName, String aLanguage, String[] aTags, String[] aTagDescription, Project aProject) throws IOException {
    TagSet tagSet = new TagSet();
    tagSet.setDescription(aDescription);
    tagSet.setLanguage(aLanguage);
    tagSet.setName(aTagSetName);
    tagSet.setProject(aProject);
    createTagSet(tagSet);
    int i = 0;
    for (String tagName : aTags) {
        Tag tag = new Tag();
        tag.setTagSet(tagSet);
        tag.setDescription(aTagDescription[i]);
        tag.setName(tagName);
        createTag(tag);
        i++;
    }
    return tagSet;
}
Also used : TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag)

Example 13 with Tag

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

the class JsonImportUtil method createTagSet.

public static TagSet createTagSet(Project project, ExportedTagSet importedTagSet, AnnotationSchemaService aAnnotationService) throws IOException {
    String importedTagSetName = importedTagSet.getName();
    if (aAnnotationService.existsTagSet(importedTagSetName, project)) {
        // aAnnotationService.removeTagSet(aAnnotationService.getTagSet(
        // importedTagSet.getName(), project));
        // Rename Imported TagSet instead of deleting the old one.
        importedTagSetName = copyTagSetName(aAnnotationService, importedTagSetName, project);
    }
    TagSet newTagSet = new TagSet();
    newTagSet.setDescription(importedTagSet.getDescription());
    newTagSet.setName(importedTagSetName);
    newTagSet.setLanguage(importedTagSet.getLanguage());
    newTagSet.setProject(project);
    newTagSet.setCreateTag(importedTagSet.isCreateTag());
    aAnnotationService.createTagSet(newTagSet);
    for (ExportedTag tag : importedTagSet.getTags()) {
        Tag newTag = new Tag();
        newTag.setDescription(tag.getDescription());
        newTag.setName(tag.getName());
        newTag.setTagSet(newTagSet);
        aAnnotationService.createTag(newTag);
    }
    return newTagSet;
}
Also used : TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) ExportedTagSet(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag)

Example 14 with Tag

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

the class AnnotationDetailEditorPanel method compareSortAndAdd.

/*
     * Compares existing tagset with possible values resulted from rule evaluation Adds only which
     * exist in tagset and is suggested by rules. The remaining values from tagset are added
     * afterwards.
     */
private static List<Tag> compareSortAndAdd(List<PossibleValue> possibleValues, List<Tag> valuesFromTagset, RulesIndicator rulesIndicator) {
    // if no possible values, means didn't satisfy conditions
    if (possibleValues.isEmpty()) {
        rulesIndicator.didntMatchAnyRule();
    }
    List<Tag> returnList = new ArrayList<>();
    // tagset and adding them first in list.
    for (PossibleValue value : possibleValues) {
        for (Tag tag : valuesFromTagset) {
            if (value.getValue().equalsIgnoreCase(tag.getName())) {
                // Matching values found in tagset and shown in dropdown
                rulesIndicator.rulesApplied();
                // HACK BEGIN
                tag.setReordered(true);
                // Avoid duplicate entries
                if (!returnList.contains(tag)) {
                    returnList.add(tag);
                }
            }
        }
    }
    // If no matching tags found
    if (returnList.isEmpty()) {
        rulesIndicator.didntMatchAnyTag();
    }
    return returnList;
}
Also used : ArrayList(java.util.ArrayList) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue)

Example 15 with Tag

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

the class TagSetEditorPanel method export.

private FileResourceStream export() {
    File exportFile = null;
    if (exportFormat.getObject().equals(ExportedTagSetConstant.JSON_FORMAT)) {
        try {
            exportFile = File.createTempFile("exportedtagsets", ".json");
        } catch (IOException e1) {
            error("Unable to create temporary File!!");
            return null;
        }
        if (isNull(selectedTagSet.getObject().getId())) {
            error("Project not yet created. Please save project details first!");
        } else {
            TagSet tagSet = selectedTagSet.getObject();
            ExportedTagSet exTagSet = new ExportedTagSet();
            exTagSet.setDescription(tagSet.getDescription());
            exTagSet.setLanguage(tagSet.getLanguage());
            exTagSet.setName(tagSet.getName());
            List<ExportedTag> exportedTags = new ArrayList<>();
            for (Tag tag : annotationSchemaService.listTags(tagSet)) {
                ExportedTag exportedTag = new ExportedTag();
                exportedTag.setDescription(tag.getDescription());
                exportedTag.setName(tag.getName());
                exportedTags.add(exportedTag);
            }
            exTagSet.setTags(exportedTags);
            try {
                JSONUtil.generatePrettyJson(exTagSet, exportFile);
            } catch (IOException e) {
                error("File Path not found or No permision to save the file!");
            }
            info("TagSets successfully exported to :" + exportFile.getAbsolutePath());
        }
    } else if (exportFormat.getObject().equals(ExportedTagSetConstant.TAB_FORMAT)) {
        TagSet tagSet = selectedTagSet.getObject();
        try {
            exportFile = File.createTempFile("exportedtagsets", ".txt");
        } catch (IOException e1) {
            error("Unable to create temporary File!!");
        }
        OutputStream os;
        OutputStreamWriter osw;
        BufferedWriter bw;
        try {
            String tagSetDescription = tagSet.getDescription() == null ? "" : tagSet.getDescription();
            os = new FileOutputStream(exportFile);
            osw = new OutputStreamWriter(os, "UTF-8");
            bw = new BufferedWriter(osw);
            bw.write(tagSet.getName() + "\t" + tagSetDescription.replace("\n", "\\n") + "\n");
            bw.write(tagSet.getLanguage() + "\t" + " \n");
            for (Tag tag : annotationSchemaService.listTags(tagSet)) {
                String tagDescription = tag.getDescription() == null ? "" : tag.getDescription();
                bw.write(tag.getName() + "\t" + tagDescription.replace("\n", "\\n") + "\n");
            }
            bw.flush();
            bw.close();
        } catch (FileNotFoundException e) {
            error("The file for export not found " + ExceptionUtils.getRootCauseMessage(e));
        } catch (UnsupportedEncodingException e) {
            error("Unsupported encoding " + ExceptionUtils.getRootCauseMessage(e));
        } catch (IOException e) {
            error(ExceptionUtils.getRootCause(e));
        }
    }
    return new FileResourceStream(exportFile);
}
Also used : FileResourceStream(org.apache.wicket.util.resource.FileResourceStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) 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) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) File(java.io.File) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag)

Aggregations

Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)17 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)11 ExportedTag (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag)7 ArrayList (java.util.ArrayList)7 ExportedTagSet (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet)5 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)5 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)4 IOException (java.io.IOException)4 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)3 PossibleValue (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue)3 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)2 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)2 File (java.io.File)2 HashSet (java.util.HashSet)2 UIMAException (org.apache.uima.UIMAException)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 Options (com.googlecode.wicket.jquery.core.Options)1 TooltipBehavior (com.googlecode.wicket.jquery.ui.widget.tooltip.TooltipBehavior)1 ProjectType (de.tudarmstadt.ukp.clarin.webanno.api.ProjectType)1 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)1