use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class SemPredArgLayerInitializer method configure.
@Override
public void configure(Project aProject) throws IOException {
AnnotationLayer semArgLayer = new AnnotationLayer(SemArg.class.getName(), "SemArg", SPAN_TYPE, aProject, true);
semArgLayer.setAllowStacking(true);
semArgLayer.setCrossSentence(false);
semArgLayer.setLockToTokenOffset(false);
semArgLayer.setMultipleTokens(true);
annotationSchemaService.createLayer(semArgLayer);
AnnotationLayer semPredLayer = new AnnotationLayer(SemPred.class.getName(), "SemPred", SPAN_TYPE, aProject, true);
semPredLayer.setAllowStacking(true);
semPredLayer.setCrossSentence(false);
semPredLayer.setLockToTokenOffset(false);
semPredLayer.setMultipleTokens(true);
annotationSchemaService.createFeature(new AnnotationFeature(aProject, semPredLayer, "category", "category", CAS.TYPE_NAME_STRING, "Category of the semantic predicate, e.g. the frame identifier.", null));
AnnotationFeature semPredArgumentsFeature = new AnnotationFeature();
semPredArgumentsFeature.setName("arguments");
semPredArgumentsFeature.setUiName("arguments");
semPredArgumentsFeature.setDescription("Arguments of the semantic predicate");
semPredArgumentsFeature.setType(SemArg.class.getName());
semPredArgumentsFeature.setProject(aProject);
semPredArgumentsFeature.setTagset(null);
semPredArgumentsFeature.setMode(MultiValueMode.ARRAY);
semPredArgumentsFeature.setLinkMode(LinkMode.WITH_ROLE);
semPredArgumentsFeature.setLinkTypeName(SemArgLink.class.getName());
semPredArgumentsFeature.setLinkTypeRoleFeatureName("role");
semPredArgumentsFeature.setLinkTypeTargetFeatureName("target");
semPredArgumentsFeature.setLayer(semPredLayer);
annotationSchemaService.createFeature(semPredArgumentsFeature);
annotationSchemaService.createLayer(semPredLayer);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class SurfaceFormLayerInitializer method configure.
@Override
public void configure(Project aProject) throws IOException {
AnnotationLayer surfaceFormLayer = new AnnotationLayer(SurfaceForm.class.getName(), "Surface form", SPAN_TYPE, aProject, true);
surfaceFormLayer.setAllowStacking(false);
// The surface form must be locked to tokens for CoNLL-U writer to work properly
surfaceFormLayer.setLockToTokenOffset(false);
surfaceFormLayer.setMultipleTokens(true);
annotationSchemaService.createLayer(surfaceFormLayer);
AnnotationFeature surfaceFormValueFeature = new AnnotationFeature();
surfaceFormValueFeature.setDescription("Original surface text");
surfaceFormValueFeature.setName("value");
surfaceFormValueFeature.setType(CAS.TYPE_NAME_STRING);
surfaceFormValueFeature.setProject(aProject);
surfaceFormValueFeature.setUiName("Form");
surfaceFormValueFeature.setLayer(surfaceFormLayer);
annotationSchemaService.createFeature(surfaceFormValueFeature);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class PrimitiveUimaFeatureSupport method getFeatureValue.
@Override
public <T> T getFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS) {
Feature feature = aFS.getType().getFeatureByBaseName(aFeature.getName());
final String effectiveType = aFeature.getType();
// Sanity check
if (!Objects.equals(effectiveType, feature.getRange().getName())) {
throw new IllegalArgumentException("Actual feature type [" + feature.getRange().getName() + "] does not match expected feature type [" + effectiveType + "].");
}
return WebAnnoCasUtil.getFeature(aFS, aFeature.getName());
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class AnnotationDetailEditorPanel method getAttachedLinks.
private Set<AnnotationFS> getAttachedLinks(AnnotationFS aFs, AnnotationLayer aLayer) {
CAS cas = aFs.getCAS();
Set<AnnotationFS> attachedLinks = new HashSet<>();
TypeAdapter adapter = annotationService.getAdapter(aLayer);
if (adapter instanceof SpanAdapter) {
for (AnnotationFeature linkFeature : annotationService.listAttachedLinkFeatures(aLayer)) {
if (MultiValueMode.ARRAY.equals(linkFeature.getMultiValueMode()) && LinkMode.WITH_ROLE.equals(linkFeature.getLinkMode())) {
// Fetch slot hosts that could link to the current FS and check if any of
// them actually links to the current FS
Type linkType = CasUtil.getType(cas, linkFeature.getLayer().getName());
for (AnnotationFS linkFS : CasUtil.select(cas, linkType)) {
List<LinkWithRoleModel> links = adapter.getFeatureValue(linkFeature, linkFS);
for (int li = 0; li < links.size(); li++) {
LinkWithRoleModel link = links.get(li);
AnnotationFS linkTarget = selectByAddr(cas, AnnotationFS.class, link.targetAddr);
// our list of attached links.
if (isSame(linkTarget, aFs)) {
attachedLinks.add(linkFS);
}
}
}
}
}
}
return attachedLinks;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class AnnotationDetailEditorPanel method deleteAnnotation.
private void deleteAnnotation(JCas jCas, AnnotatorState state, AnnotationFS fs, AnnotationLayer layer, TypeAdapter adapter) {
// is no longer set after UNATTACH SPANS!
if (adapter instanceof SpanAdapter) {
for (AnnotationFS attachedFs : getAttachedRels(fs, layer)) {
jCas.getCas().removeFsFromIndexes(attachedFs);
info("The attached annotation for relation type [" + annotationService.getLayer(attachedFs.getType().getName(), state.getProject()).getUiName() + "] is deleted");
}
}
// to look at span annotations that have the same offsets as the FS to be deleted.
if (adapter instanceof SpanAdapter && layer.getAttachType() != null && layer.getAttachFeature() != null) {
Type spanType = CasUtil.getType(jCas.getCas(), layer.getAttachType().getName());
Feature attachFeature = spanType.getFeatureByBaseName(layer.getAttachFeature().getName());
for (AnnotationFS attachedFs : getAttachedSpans(fs, layer)) {
attachedFs.setFeatureValue(attachFeature, null);
LOG.debug("Unattached [" + attachFeature.getShortName() + "] on annotation [" + getAddr(attachedFs) + "]");
}
}
// to be deleted: the link feature must be the type of the FS or it must be generic.
if (adapter instanceof SpanAdapter) {
for (AnnotationFeature linkFeature : annotationService.listAttachedLinkFeatures(layer)) {
Type linkType = CasUtil.getType(jCas.getCas(), linkFeature.getLayer().getName());
for (AnnotationFS linkFS : CasUtil.select(jCas.getCas(), linkType)) {
List<LinkWithRoleModel> links = adapter.getFeatureValue(linkFeature, linkFS);
Iterator<LinkWithRoleModel> i = links.iterator();
boolean modified = false;
while (i.hasNext()) {
LinkWithRoleModel link = i.next();
if (link.targetAddr == getAddr(fs)) {
i.remove();
LOG.debug("Cleared slot [" + link.role + "] in feature [" + linkFeature.getName() + "] on annotation [" + getAddr(linkFS) + "]");
modified = true;
}
}
if (modified) {
setFeature(linkFS, linkFeature, links);
}
}
}
}
// relation.
if (adapter instanceof ArcAdapter) {
// Do nothing ;)
}
// Actually delete annotation
adapter.delete(state, jCas, state.getSelection().getAnnotation());
}
Aggregations