Search in sources :

Example 6 with Tag

use of de.tudarmstadt.ukp.clarin.webanno.model.Tag 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)

Example 7 with Tag

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

the class ImportUtil method createTagSet.

private static TagSet createTagSet(Project project, User user, 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 = JsonImportUtil.copyTagSetName(aAnnotationService, importedTagSetName, project);
    }
    TagSet newTagSet = new TagSet();
    newTagSet.setDescription(importedTagSet.getDescription());
    newTagSet.setName(importedTagSetName);
    newTagSet.setLanguage(importedTagSet.getLanguage());
    newTagSet.setProject(project);
    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) 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)

Example 8 with Tag

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

the class ImportUtil method createTagSet.

public static void createTagSet(TagSet aTagSet, ExportedTagSet aExTagSet, Project aProject, User aUser, AnnotationSchemaService aAnnotationService) throws IOException {
    aTagSet.setCreateTag(aExTagSet.isCreateTag());
    aTagSet.setDescription(aExTagSet.getDescription());
    aTagSet.setLanguage(aExTagSet.getLanguage());
    aTagSet.setName(aExTagSet.getName());
    aTagSet.setProject(aProject);
    aAnnotationService.createTagSet(aTagSet);
    for (ExportedTag exTag : aExTagSet.getTags()) {
        // do not duplicate tag
        if (aAnnotationService.existsTag(exTag.getName(), aTagSet)) {
            continue;
        }
        Tag tag = new Tag();
        tag.setDescription(exTag.getDescription());
        tag.setTagSet(aTagSet);
        tag.setName(exTag.getName());
        aAnnotationService.createTag(tag);
    }
}
Also used : 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)

Example 9 with Tag

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

the class LinkFeatureEditor method autoAddImportantTags.

private void autoAddImportantTags(List<Tag> aTagset, List<PossibleValue> aPossibleValues) {
    if (aTagset == null || aTagset.isEmpty() || aPossibleValues == null || aPossibleValues.isEmpty()) {
        return;
    }
    // Construct a quick index for tags
    Set<String> tagset = new HashSet<>();
    for (Tag t : aTagset) {
        tagset.add(t.getName());
    }
    // Get links list and build role index
    @SuppressWarnings("unchecked") List<LinkWithRoleModel> links = (List<LinkWithRoleModel>) getModelObject().value;
    Set<String> roles = new HashSet<>();
    for (LinkWithRoleModel l : links) {
        roles.add(l.role);
    }
    // Loop over values to see which of the tags are important and add them.
    for (PossibleValue value : aPossibleValues) {
        if (!value.isImportant() || !tagset.contains(value.getValue())) {
            continue;
        }
        // Check if there is already a slot with the given name
        if (roles.contains(value.getValue())) {
            continue;
        }
        // Add empty slot in UI with that name.
        LinkWithRoleModel m = new LinkWithRoleModel();
        m.role = value.getValue();
        // Marking so that can be ignored later.
        m.autoCreated = true;
        links.add(m);
    // NOT arming the slot here!
    }
}
Also used : LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) List(java.util.List) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue) HashSet(java.util.HashSet)

Example 10 with Tag

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

the class TextFeatureEditor method createFieldComboBox.

private AbstractTextComponent createFieldComboBox() {
    AbstractTextComponent field;
    if (getModelObject().feature.getTagset() != null) {
        field = new StyledComboBox<Tag>("value", PropertyModel.of(getModel(), "tagset")) {

            private static final long serialVersionUID = -1735694425658462932L;

            @Override
            protected void onInitialize() {
                super.onInitialize();
                // Ensure proper order of the initializing JS header items: first combo box
                // behavior (in super.onInitialize()), then tooltip.
                Options options = new Options(DescriptionTooltipBehavior.makeTooltipOptions());
                options.set("content", FUNCTION_FOR_TOOLTIP);
                add(new TooltipBehavior("#" + getMarkupId() + "_listbox *[title]", options) {

                    private static final long serialVersionUID = 1854141593969780149L;

                    @Override
                    protected String $() {
                        // with a slight delay hoping that all is set up after 1 second.
                        return "try {setTimeout(function () { " + super.$() + " }, 1000); } catch (err) {}; ";
                    }
                });
            }

            @Override
            protected void onConfigure() {
                super.onConfigure();
                // Trigger a re-loading of the tagset from the server as constraints may have
                // changed the ordering
                AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
                if (target != null) {
                    LOG.trace("onInitialize() requesting datasource re-reading");
                    target.appendJavaScript(String.format("var $w = %s; if ($w) { $w.dataSource.read(); }", KendoUIBehavior.widget(this, ComboBoxBehavior.METHOD)));
                }
            }
        };
    } else {
        field = new TextField<String>("value");
    }
    // Ensure that markup IDs of feature editor focus components remain constant across
    // refreshes of the feature editor panel. This is required to restore the focus.
    field.setOutputMarkupId(true);
    field.setMarkupId(ID_PREFIX + getModelObject().feature.getId());
    return field;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Options(com.googlecode.wicket.jquery.core.Options) TooltipBehavior(com.googlecode.wicket.jquery.ui.widget.tooltip.TooltipBehavior) DescriptionTooltipBehavior(de.tudarmstadt.ukp.clarin.webanno.support.DescriptionTooltipBehavior) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) AbstractTextComponent(org.apache.wicket.markup.html.form.AbstractTextComponent)

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