-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#4562 - Project template for named entity annotation
- Added new entity annotation template - Still need to add original thumbnail image for this
- Loading branch information
Showing
9 changed files
with
350 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...kp/inception/project/initializers/wikidatalinking/EntityAnnotationProjectInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...ect/initializers/wikidatalinking/NamedEntitySequenceClassifierRecommenderInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
...ception/project/initializers/wikidatalinking/NamedEntityStringRecommenderInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.