Skip to content

Commit

Permalink
#4562 - Project template for named entity annotation
Browse files Browse the repository at this point in the history
- Added new entity annotation template
- Still need to add original thumbnail image for this
  • Loading branch information
reckart committed Feb 26, 2024
1 parent 3b19c9f commit be328e8
Show file tree
Hide file tree
Showing 9 changed files with 350 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-imls-stringmatch</artifactId>
</dependency>
<dependency>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-imls-opennlp</artifactId>
</dependency>
<dependency>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-kb</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* 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.initializers.wikidatalinking;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.request.resource.ResourceReference;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.Order;

import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.clarin.webanno.project.initializers.NamedEntityLayerInitializer;
import de.tudarmstadt.ukp.clarin.webanno.project.initializers.QuickProjectInitializer;
import de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity;
import de.tudarmstadt.ukp.inception.project.api.ProjectInitializer;
import de.tudarmstadt.ukp.inception.project.initializers.wikidatalinking.config.WikiDataLinkingProjectInitializersAutoConfiguration;
import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService;
import de.tudarmstadt.ukp.inception.support.wicket.resource.Strings;

/**
* <p>
* This class is exposed as a Spring Component via
* {@link WikiDataLinkingProjectInitializersAutoConfiguration#entityAnnotationProjectInitializer}.
* </p>
*/
@Order(5000)
public class EntityAnnotationProjectInitializer
implements QuickProjectInitializer
{
private static final PackageResourceReference THUMBNAIL = new PackageResourceReference(
MethodHandles.lookup().lookupClass(), "EntityLinkingProjectInitializer.svg");

private final AnnotationSchemaService annotationService;
private final ApplicationContext context;

public EntityAnnotationProjectInitializer(ApplicationContext aContext,
AnnotationSchemaService aAnnotationService)
{
context = aContext;
annotationService = aAnnotationService;
}

@Override
public String getName()
{
return "Entity annotation";
}

@Override
public Optional<String> getDescription()
{
return Optional.of(Strings.getString("entity-annotation-project.description"));
}

@Override
public Optional<ResourceReference> getThumbnail()
{
return Optional.of(THUMBNAIL);
}

@Override
public boolean alreadyApplied(Project aProject)
{
return false;
}

@Override
public List<Class<? extends ProjectInitializer>> getDependencies()
{
var dependencies = new ArrayList<Class<? extends ProjectInitializer>>();
dependencies.add(NamedEntityLayerInitializer.class);

if (context.getBeanNamesForType(NamedEntityStringRecommenderInitializer.class).length > 0) {
dependencies.add(NamedEntityStringRecommenderInitializer.class);
}

if (context.getBeanNamesForType(
NamedEntitySequenceClassifierRecommenderInitializer.class).length > 0) {
dependencies.add(NamedEntitySequenceClassifierRecommenderInitializer.class);
}

return dependencies;
}

@Override
public void configure(Project aProject) throws IOException
{
var layer = annotationService.findLayer(aProject, NamedEntity.class.getName());
var valueFeature = annotationService.getFeature(NamedEntity._FeatName_value, layer);
valueFeature.setEnabled(false);
annotationService.createFeature(valueFeature);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.Order;

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.project.initializers.NamedEntityLayerInitializer;
import de.tudarmstadt.ukp.clarin.webanno.project.initializers.QuickProjectInitializer;
Expand Down Expand Up @@ -90,7 +88,7 @@ public boolean alreadyApplied(Project aProject)
@Override
public List<Class<? extends ProjectInitializer>> getDependencies()
{
List<Class<? extends ProjectInitializer>> dependencies = new ArrayList<>();
var dependencies = new ArrayList<Class<? extends ProjectInitializer>>();
dependencies.add(NamedEntityLayerInitializer.class);
dependencies.add(NamedEntityIdentifierFeatureInitializer.class);
dependencies.add(WikiDataKnowledgeBaseInitializer.class);
Expand All @@ -106,9 +104,8 @@ public List<Class<? extends ProjectInitializer>> getDependencies()
@Override
public void configure(Project aProject) throws IOException
{
AnnotationLayer layer = annotationService.findLayer(aProject, NamedEntity.class.getName());
AnnotationFeature valueFeature = annotationService.getFeature(NamedEntity._FeatName_value,
layer);
var layer = annotationService.findLayer(aProject, NamedEntity.class.getName());
var valueFeature = annotationService.getFeature(NamedEntity._FeatName_value, layer);
valueFeature.setEnabled(false);
annotationService.createFeature(valueFeature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.io.IOException;
import java.util.List;

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.dkpro.core.api.ner.type.NamedEntity;
import de.tudarmstadt.ukp.inception.project.api.ProjectInitializer;
Expand Down Expand Up @@ -83,12 +81,11 @@ public List<Class<? extends ProjectInitializer>> getDependencies()
@Override
public void configure(Project aProject) throws IOException
{
AnnotationLayer spanLayer = annotationService.findLayer(aProject,
NamedEntity.class.getName());
AnnotationFeature labelFeature = annotationService
.getFeature(NamedEntity._FeatName_identifier, spanLayer);
var spanLayer = annotationService.findLayer(aProject, NamedEntity.class.getName());
var labelFeature = annotationService.getFeature(NamedEntity._FeatName_identifier,
spanLayer);

Recommender recommender = new Recommender(getName(), spanLayer);
var recommender = new Recommender(getName(), spanLayer);
recommender.setFeature(labelFeature);
recommender.setMaxRecommendations(3);
recommender.setThreshold(0.0d);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* 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.initializers.wikidatalinking;

import static java.util.Arrays.asList;

import java.io.IOException;
import java.util.List;

import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity;
import de.tudarmstadt.ukp.inception.project.api.ProjectInitializer;
import de.tudarmstadt.ukp.inception.project.initializers.wikidatalinking.config.WikiDataLinkingProjectInitializersAutoConfiguration;
import de.tudarmstadt.ukp.inception.recommendation.api.RecommendationService;
import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.imls.opennlp.ner.OpenNlpNerRecommenderFactory;
import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService;
import de.tudarmstadt.ukp.inception.ui.kb.initializers.NamedEntityIdentifierFeatureInitializer;

/**
* <p>
* This class is exposed as a Spring Component via
* {@link WikiDataLinkingProjectInitializersAutoConfiguration#namedEntitySequenceClassifierRecommenderInitializer}.
* </p>
*/
public class NamedEntitySequenceClassifierRecommenderInitializer
implements ProjectInitializer
{
private final AnnotationSchemaService annotationService;
private final RecommendationService recommendationService;
private final OpenNlpNerRecommenderFactory recommenderFactory;

public NamedEntitySequenceClassifierRecommenderInitializer(
RecommendationService aRecommenderService, AnnotationSchemaService aAnnotationService,
OpenNlpNerRecommenderFactory aRecommenderFactory)
{
recommendationService = aRecommenderService;
annotationService = aAnnotationService;
recommenderFactory = aRecommenderFactory;
}

@Override
public String getName()
{
return "Named entity sequence classifier recommender";
}

@Override
public boolean applyByDefault()
{
return false;
}

@Override
public boolean alreadyApplied(Project aProject)
{
return recommendationService.existsRecommender(aProject, getName());
}

@Override
public List<Class<? extends ProjectInitializer>> getDependencies()
{
return asList(NamedEntityIdentifierFeatureInitializer.class);
}

@Override
public void configure(Project aProject) throws IOException
{
var spanLayer = annotationService.findLayer(aProject, NamedEntity.class.getName());
var labelFeature = annotationService.getFeature(NamedEntity._FeatName_value, spanLayer);

var recommender = new Recommender(getName(), spanLayer);
recommender.setFeature(labelFeature);
recommender.setMaxRecommendations(3);
recommender.setThreshold(0.0d);
recommender.setTool(recommenderFactory.getId());

recommendationService.createOrUpdateRecommender(recommender);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* 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.initializers.wikidatalinking;

import static java.util.Arrays.asList;

import java.io.IOException;
import java.util.List;

import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity;
import de.tudarmstadt.ukp.inception.project.api.ProjectInitializer;
import de.tudarmstadt.ukp.inception.project.initializers.wikidatalinking.config.WikiDataLinkingProjectInitializersAutoConfiguration;
import de.tudarmstadt.ukp.inception.recommendation.api.RecommendationService;
import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender;
import de.tudarmstadt.ukp.inception.recommendation.imls.stringmatch.span.StringMatchingRecommenderFactory;
import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService;
import de.tudarmstadt.ukp.inception.ui.kb.initializers.NamedEntityIdentifierFeatureInitializer;

/**
* <p>
* This class is exposed as a Spring Component via
* {@link WikiDataLinkingProjectInitializersAutoConfiguration#namedEntityStringRecommenderInitializer}.
* </p>
*/
public class NamedEntityStringRecommenderInitializer
implements ProjectInitializer
{
private final AnnotationSchemaService annotationService;
private final RecommendationService recommendationService;
private final StringMatchingRecommenderFactory recommenderFactory;

public NamedEntityStringRecommenderInitializer(RecommendationService aRecommenderService,
AnnotationSchemaService aAnnotationService,
StringMatchingRecommenderFactory aRecommenderFactory)
{
recommendationService = aRecommenderService;
annotationService = aAnnotationService;
recommenderFactory = aRecommenderFactory;
}

@Override
public String getName()
{
return "Named entity string-matching recommender";
}

@Override
public boolean applyByDefault()
{
return false;
}

@Override
public boolean alreadyApplied(Project aProject)
{
return recommendationService.existsRecommender(aProject, getName());
}

@Override
public List<Class<? extends ProjectInitializer>> getDependencies()
{
return asList(NamedEntityIdentifierFeatureInitializer.class);
}

@Override
public void configure(Project aProject) throws IOException
{
var spanLayer = annotationService.findLayer(aProject, NamedEntity.class.getName());
var labelFeature = annotationService.getFeature(NamedEntity._FeatName_value, spanLayer);

var recommender = new Recommender(getName(), spanLayer);
recommender.setFeature(labelFeature);
recommender.setMaxRecommendations(3);
recommender.setThreshold(0.0d);
recommender.setTool(recommenderFactory.getId());

recommendationService.createOrUpdateRecommender(recommender);
}
}
Loading

0 comments on commit be328e8

Please sign in to comment.