Skip to content

Commit

Permalink
#4780 - Optionally include example documents in project templates
Browse files Browse the repository at this point in the history
- Include example documents with the named entity annotation project template
  • Loading branch information
reckart committed Apr 30, 2024
1 parent ac7910a commit 6fa31c0
Show file tree
Hide file tree
Showing 30 changed files with 7,788 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void execute() throws IOException, UIMAException
// deleting the users annotations!!!), currently fixed by warn message to user
// prepare merged CAS
curationMergeService.mergeCasses(doc, targetUser, targetCas, annotatorCasses,
mergeStrategy, annotationLayers);
mergeStrategy, annotationLayers, true);

var targetAnnDoc = documentService.createOrGetAnnotationDocument(doc, targetUser);
documentService.writeAnnotationCas(targetCas, targetAnnDoc,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Licensed to the Technische Universität Darmstadt under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The Technische Universität Darmstadt
* licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.tudarmstadt.ukp.inception.project.api;

import java.util.Objects;

import de.tudarmstadt.ukp.clarin.webanno.model.Project;

public class ProjectInitializationRequest
{
private final Project project;
private final boolean includeSampleData;

private ProjectInitializationRequest(Builder builder)
{
project = builder.project;
includeSampleData = builder.includeSampleData;
}

public static Builder builder()
{
return new Builder();
}

public Project getProject()
{
return project;
}

public boolean isIncludeSampleData()
{
return includeSampleData;
}

public static final class Builder
{
private Project project;
private boolean includeSampleData;

private Builder()
{
}

public Builder withProject(Project aProject)
{
project = aProject;
return this;
}

public Builder withIncludeSampleData(boolean aIncludeSampleData)
{
includeSampleData = aIncludeSampleData;
return this;
}

public ProjectInitializationRequest build()
{
Objects.requireNonNull(project, "Parameter [project] must be specified.");

return new ProjectInitializationRequest(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,21 @@ default boolean applyByDefault()

List<Class<? extends ProjectInitializer>> getDependencies();

void configure(Project aProject) throws IOException;
default void configure(ProjectInitializationRequest aRequest) throws IOException
{
configure(aRequest.getProject());
}

/**
* @param aProject
* the project to initialize.
* @throws IOException
* if there is a problem.
* @deprecated Implement {@link #configure(ProjectInitializationRequest)} instead.
*/
@Deprecated
default void configure(Project aProject) throws IOException
{
// Do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -568,16 +568,30 @@ boolean hasRole(String aUser, Project aProject, PermissionLevel aRole,
* Initialize the project with default {@link AnnotationLayer}, {@link TagSet}s, and {@link Tag}
* s. This is done per Project.
*
* @param aProject
* the project.
* @param aRequest
* the project initialization request.
* @throws IOException
* if an I/O error occurs.
*/
void initializeProject(Project aProject) throws IOException;
void initializeProject(ProjectInitializationRequest aRequest) throws IOException;

void initializeProject(Project aProject, List<ProjectInitializer> aInitializers)
void initializeProject(ProjectInitializationRequest aRequest,
List<ProjectInitializer> aInitializers)
throws IOException;

default void initializeProject(Project aProject) throws IOException
{
var request = ProjectInitializationRequest.builder().withProject(aProject).build();
initializeProject(request);
}

default void initializeProject(Project aProject, List<ProjectInitializer> aInitializers)
throws IOException
{
var request = ProjectInitializationRequest.builder().withProject(aProject).build();
initializeProject(request, aInitializers);
}

List<ProjectInitializer> listProjectInitializers();

static MDCContext withProjectLogger(Project aProject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.clarin.webanno.project.initializers.QuickProjectInitializer;
import de.tudarmstadt.ukp.inception.project.api.ProjectInitializationRequest;
import de.tudarmstadt.ukp.inception.project.api.ProjectInitializer;
import de.tudarmstadt.ukp.inception.project.initializers.basic.config.InceptionBasicProjectInitializersAutoConfiguration;

Expand Down Expand Up @@ -96,7 +97,7 @@ public List<Class<? extends ProjectInitializer>> getDependencies()
}

@Override
public void configure(Project aProject) throws IOException
public void configure(ProjectInitializationRequest aRequest) throws IOException
{
// Nothing to do - all initialization is already done by the dependencies
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature;
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;
import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.clarin.webanno.model.TagSet;
import de.tudarmstadt.ukp.clarin.webanno.project.initializers.LayerInitializer;
import de.tudarmstadt.ukp.inception.project.api.ProjectInitializationRequest;
import de.tudarmstadt.ukp.inception.project.api.ProjectInitializer;
import de.tudarmstadt.ukp.inception.project.initializers.doclabeling.config.InceptionDocumentLabelingProjectInitializersAutoConfiguration;
import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService;
Expand Down Expand Up @@ -109,21 +109,22 @@ public List<Class<? extends ProjectInitializer>> getDependencies()
}

@Override
public void configure(Project aProject) throws IOException
public void configure(ProjectInitializationRequest aRequest) throws IOException
{
AnnotationLayer docTagLayer = new AnnotationLayer(BASIC_DOCUMENT_LABEL_LAYER_NAME,
"Document Label", DocumentMetadataLayerSupport.TYPE, aProject, false, TOKENS,
ANY_OVERLAP);
var project = aRequest.getProject();

var docTagLayer = new AnnotationLayer(BASIC_DOCUMENT_LABEL_LAYER_NAME, "Document Label",
DocumentMetadataLayerSupport.TYPE, project, false, TOKENS, ANY_OVERLAP);
var traits = docLayerSupport.readTraits(docTagLayer);
traits.setSingleton(true);
docLayerSupport.writeTraits(docTagLayer, traits);
annotationSchemaService.createOrUpdateLayer(docTagLayer);

TagSet docLabelTagSet = annotationSchemaService.getTagSet(
BasicDocumentLabelTagSetInitializer.BASIC_DOCUMENT_LABEL_TAG_SET_NAME, aProject);
var docLabelTagSet = annotationSchemaService.getTagSet(
BasicDocumentLabelTagSetInitializer.BASIC_DOCUMENT_LABEL_TAG_SET_NAME, project);

annotationSchemaService.createFeature(new AnnotationFeature(aProject, docTagLayer,
BASIC_DOCUMENT_LABEL_LABEL_FEATURE_NAME, "Label", CAS.TYPE_NAME_STRING,
"Document label", docLabelTagSet));
annotationSchemaService.createFeature(
new AnnotationFeature(project, docTagLayer, BASIC_DOCUMENT_LABEL_LABEL_FEATURE_NAME,
"Label", CAS.TYPE_NAME_STRING, "Document label", docLabelTagSet));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import de.tudarmstadt.ukp.clarin.webanno.model.Tag;
import de.tudarmstadt.ukp.clarin.webanno.model.TagSet;
import de.tudarmstadt.ukp.clarin.webanno.project.initializers.TagSetInitializer;
import de.tudarmstadt.ukp.inception.project.api.ProjectInitializationRequest;
import de.tudarmstadt.ukp.inception.project.api.ProjectInitializer;
import de.tudarmstadt.ukp.inception.project.initializers.doclabeling.config.InceptionDocumentLabelingProjectInitializersAutoConfiguration;
import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService;
Expand Down Expand Up @@ -75,18 +76,20 @@ public boolean alreadyApplied(Project aProject)
}

@Override
public void configure(Project aProject) throws IOException
public void configure(ProjectInitializationRequest aRequest) throws IOException
{
TagSet tagSet = new TagSet();
tagSet.setProject(aProject);
var project = aRequest.getProject();

var tagSet = new TagSet();
tagSet.setProject(project);
tagSet.setName(getName());
tagSet.setDescription("Document labels");
tagSet.setLanguage("en");
tagSet.setCreateTag(false);

annotationSchemaService.createTagSet(tagSet);

Tag[] tags = new Tag[3];
var tags = new Tag[3];
for (int i = 0; i < tags.length; i++) {
tags[i] = new Tag(tagSet, "Label " + (i + 1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@
import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.clarin.webanno.project.initializers.QuickProjectInitializer;
import de.tudarmstadt.ukp.clarin.webanno.project.initializers.TokenLayerInitializer;
import de.tudarmstadt.ukp.clarin.webanno.ui.annotation.sidebar.AnnotationSidebarState;
import de.tudarmstadt.ukp.inception.preferences.PreferencesService;
import de.tudarmstadt.ukp.inception.project.api.ProjectInitializationRequest;
import de.tudarmstadt.ukp.inception.project.api.ProjectInitializer;
import de.tudarmstadt.ukp.inception.project.initializers.doclabeling.config.InceptionDocumentLabelingProjectInitializersAutoConfiguration;
import de.tudarmstadt.ukp.inception.support.wicket.resource.Strings;
import de.tudarmstadt.ukp.inception.ui.core.docanno.sidebar.DocumentMetadataSidebarFactory;
import de.tudarmstadt.ukp.inception.workload.matrix.MatrixWorkloadExtension;
import de.tudarmstadt.ukp.inception.workload.matrix.trait.MatrixWorkloadTraits;
import de.tudarmstadt.ukp.inception.workload.model.WorkloadManagementService;
import de.tudarmstadt.ukp.inception.workload.model.WorkloadManager;

/**
* <p>
Expand Down Expand Up @@ -106,9 +104,10 @@ public List<Class<? extends ProjectInitializer>> getDependencies()
}

@Override
public void configure(Project aProject) throws IOException
public void configure(ProjectInitializationRequest aRequest) throws IOException
{
aProject.setDescription(String.join("\n",
var project = aRequest.getProject();
project.setDescription(String.join("\n",
// Empty line to avoid the this text showing up in the short description of the
// project overview
"", //
Expand All @@ -124,17 +123,15 @@ public void configure(Project aProject) throws IOException
"this projects and annotators may also re-open a document for annotation if they", //
"want. You can change this setting in the settings on the **Montoring** page."));

AnnotationSidebarState sidebarState = prefService
.loadDefaultTraitsForProject(KEY_SIDEBAR_STATE, aProject);
var sidebarState = prefService.loadDefaultTraitsForProject(KEY_SIDEBAR_STATE, project);
sidebarState.setExpanded(true);
sidebarState.setSelectedTab(docMetaSidebar.getBeanName());
prefService.saveDefaultTraitsForProject(KEY_SIDEBAR_STATE, aProject, sidebarState);
prefService.saveDefaultTraitsForProject(KEY_SIDEBAR_STATE, project, sidebarState);

WorkloadManager manager = workloadManagementService
.loadOrCreateWorkloadManagerConfiguration(aProject);
MatrixWorkloadTraits traits = matrixWorkloadExtension.readTraits(manager);
var manager = workloadManagementService.loadOrCreateWorkloadManagerConfiguration(project);
var traits = matrixWorkloadExtension.readTraits(manager);
traits.setReopenableByAnnotator(true);
matrixWorkloadExtension.writeTraits(traits, aProject);
matrixWorkloadExtension.writeTraits(traits, project);
workloadManagementService.saveConfiguration(manager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-recommendation-api</artifactId>
</dependency>
<dependency>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-io-json</artifactId>
</dependency>

<dependency>
<groupId>org.apache.wicket</groupId>
Expand Down
Loading

0 comments on commit 6fa31c0

Please sign in to comment.