use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class ImportUtil method createV1Layer.
private static Map<String, AnnotationFeature> createV1Layer(Project aProject, de.tudarmstadt.ukp.clarin.webanno.export.model.Project aImportedProjectSetting, AnnotationSchemaService aAnnotationService, User aUser) throws IOException {
Map<String, AnnotationFeature> featuresMap = new HashMap<>();
Map<de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer, AnnotationLayer> layersMap = new HashMap<>();
for (de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer exLayer : aImportedProjectSetting.getLayers()) {
if (aAnnotationService.existsLayer(exLayer.getName(), exLayer.getType(), aProject)) {
AnnotationLayer layer = aAnnotationService.getLayer(exLayer.getName(), aProject);
setLayer(aAnnotationService, layer, exLayer, aProject, aUser);
layersMap.put(exLayer, layer);
for (de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature exfeature : exLayer.getFeatures()) {
if (aAnnotationService.existsFeature(exfeature.getName(), layer)) {
AnnotationFeature feature = aAnnotationService.getFeature(exfeature.getName(), layer);
setFeature(aAnnotationService, feature, exfeature, aProject, aUser);
featuresMap.put(exfeature.getName(), feature);
continue;
}
AnnotationFeature feature = new AnnotationFeature();
feature.setLayer(layer);
setFeature(aAnnotationService, feature, exfeature, aProject, aUser);
featuresMap.put(exfeature.getName(), feature);
}
} else {
AnnotationLayer layer = new AnnotationLayer();
setLayer(aAnnotationService, layer, exLayer, aProject, aUser);
layersMap.put(exLayer, layer);
for (de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature exfeature : exLayer.getFeatures()) {
AnnotationFeature feature = new AnnotationFeature();
feature.setLayer(layer);
setFeature(aAnnotationService, feature, exfeature, aProject, aUser);
featuresMap.put(exfeature.getName(), feature);
}
}
}
for (ExportedTagSet exTagSet : aImportedProjectSetting.getTagSets()) {
TagSet tagSet = new TagSet();
createTagSet(tagSet, exTagSet, aProject, aUser, aAnnotationService);
}
for (de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer exLayer : aImportedProjectSetting.getLayers()) {
if (exLayer.getAttachType() != null) {
AnnotationLayer layer = aAnnotationService.getLayer(exLayer.getName(), aProject);
AnnotationLayer attachLayer = aAnnotationService.getLayer(exLayer.getAttachType().getName(), aProject);
layer.setAttachType(attachLayer);
aAnnotationService.createLayer(layersMap.get(exLayer));
}
if (exLayer.getAttachFeature() != null) {
layersMap.get(exLayer).setAttachFeature(featuresMap.get(exLayer.getAttachFeature().getName()));
aAnnotationService.createLayer(layersMap.get(exLayer));
}
for (de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature eXFeature : exLayer.getFeatures()) {
if (eXFeature.getTagSet() != null) {
featuresMap.get(eXFeature.getName()).setTagset(aAnnotationService.getTagSet(eXFeature.getTagSet().getName(), aProject));
}
}
}
return featuresMap;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class LegacyProjectInitializer method createNeLayer.
private void createNeLayer(Project aProject, TagSet aTagSet) throws IOException {
AnnotationLayer neLayer = new AnnotationLayer(NamedEntity.class.getName(), "Named entity", SPAN_TYPE, aProject, true);
neLayer.setAllowStacking(true);
neLayer.setMultipleTokens(true);
neLayer.setLockToTokenOffset(false);
annotationSchemaService.createLayer(neLayer);
annotationSchemaService.createFeature(new AnnotationFeature(aProject, neLayer, "value", "value", CAS.TYPE_NAME_STRING, "Named entity type", aTagSet));
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class LegacyProjectInitializer method createLemmaLayer.
private void createLemmaLayer(Project aProject) throws IOException {
AnnotationLayer tokenLayer = annotationSchemaService.getLayer(Token.class.getName(), aProject);
AnnotationFeature tokenLemmaFeature = new AnnotationFeature(aProject, tokenLayer, "lemma", "lemma", Lemma.class.getName());
annotationSchemaService.createFeature(tokenLemmaFeature);
AnnotationLayer lemmaLayer = new AnnotationLayer(Lemma.class.getName(), "Lemma", SPAN_TYPE, aProject, true);
lemmaLayer.setAttachType(tokenLayer);
lemmaLayer.setAttachFeature(tokenLemmaFeature);
annotationSchemaService.createLayer(lemmaLayer);
AnnotationFeature lemmaFeature = new AnnotationFeature();
lemmaFeature.setDescription("lemma Annotation");
lemmaFeature.setName("value");
lemmaFeature.setType(CAS.TYPE_NAME_STRING);
lemmaFeature.setProject(aProject);
lemmaFeature.setUiName("Lemma");
lemmaFeature.setLayer(lemmaLayer);
annotationSchemaService.createFeature(lemmaFeature);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class AnnotationSchemaServiceImpl method generateFeatures.
private void generateFeatures(TypeSystemDescription aTSD, TypeDescription aTD, AnnotationLayer aLayer) {
List<AnnotationFeature> features = listAnnotationFeature(aLayer);
for (AnnotationFeature feature : features) {
FeatureSupport fs = featureSupportRegistry.getFeatureSupport(feature);
fs.generateFeature(aTSD, aTD, feature);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class RelationRenderer method render.
@Override
public void render(final JCas aJcas, List<AnnotationFeature> aFeatures, VDocument aResponse, AnnotatorState aBratAnnotatorModel) {
List<AnnotationFeature> visibleFeatures = aFeatures.stream().filter(f -> f.isVisible() && f.isEnabled()).collect(Collectors.toList());
ArcAdapter typeAdapter = getTypeAdapter();
Type type = getType(aJcas.getCas(), typeAdapter.getAnnotationTypeName());
int windowBegin = aBratAnnotatorModel.getWindowBeginOffset();
int windowEnd = aBratAnnotatorModel.getWindowEndOffset();
Feature dependentFeature = type.getFeatureByBaseName(typeAdapter.getTargetFeatureName());
Feature governorFeature = type.getFeatureByBaseName(typeAdapter.getSourceFeatureName());
Type spanType = getType(aJcas.getCas(), typeAdapter.getAttachTypeName());
Feature arcSpanFeature = spanType.getFeatureByBaseName(typeAdapter.getAttachFeatureName());
FeatureStructure dependentFs;
FeatureStructure governorFs;
Map<Integer, Set<Integer>> relationLinks = getRelationLinks(aJcas, windowBegin, windowEnd, type, dependentFeature, governorFeature, arcSpanFeature);
// if this is a governor for more than one dependent, avoid duplicate yield
List<Integer> yieldDeps = new ArrayList<>();
for (AnnotationFS fs : selectCovered(aJcas.getCas(), type, windowBegin, windowEnd)) {
if (typeAdapter.getAttachFeatureName() != null) {
dependentFs = fs.getFeatureValue(dependentFeature).getFeatureValue(arcSpanFeature);
governorFs = fs.getFeatureValue(governorFeature).getFeatureValue(arcSpanFeature);
} else {
dependentFs = fs.getFeatureValue(dependentFeature);
governorFs = fs.getFeatureValue(governorFeature);
}
String bratTypeName = TypeUtil.getUiTypeName(typeAdapter);
Map<String, String> features = getFeatures(typeAdapter, fs, visibleFeatures);
if (dependentFs == null || governorFs == null) {
RequestCycle requestCycle = RequestCycle.get();
IPageRequestHandler handler = PageRequestHandlerTracker.getLastHandler(requestCycle);
Page page = (Page) handler.getPage();
StringBuilder message = new StringBuilder();
message.append("Relation [" + typeAdapter.getLayer().getName() + "] with id [" + getAddr(fs) + "] has loose ends - cannot render.");
if (typeAdapter.getAttachFeatureName() != null) {
message.append("\nRelation [" + typeAdapter.getLayer().getName() + "] attached to feature [" + typeAdapter.getAttachFeatureName() + "].");
}
message.append("\nDependent: " + dependentFs);
message.append("\nGovernor: " + governorFs);
page.warn(message.toString());
continue;
}
aResponse.add(new VArc(typeAdapter.getLayer(), fs, bratTypeName, governorFs, dependentFs, features));
// Render errors if required features are missing
renderRequiredFeatureErrors(visibleFeatures, fs, aResponse);
if (relationLinks.keySet().contains(getAddr(governorFs)) && !yieldDeps.contains(getAddr(governorFs))) {
yieldDeps.add(getAddr(governorFs));
// sort the annotations (begin, end)
List<Integer> sortedDepFs = new ArrayList<>(relationLinks.get(getAddr(governorFs)));
sortedDepFs.sort(comparingInt(arg0 -> selectByAddr(aJcas, arg0).getBegin()));
String cm = getYieldMessage(aJcas, sortedDepFs);
aResponse.add(new VComment(governorFs, VCommentType.YIELD, cm));
}
}
}
Aggregations