Skip to content

Commit

Permalink
Merge pull request #5179 from inception-project/bugfix/5178-Resizing-…
Browse files Browse the repository at this point in the history
…a-span-does-not-update-offsets-of-attached-relations

#5178 - Resizing a span does not update offsets of attached relations
  • Loading branch information
reckart authored Nov 23, 2024
2 parents f43470b + 4b036f5 commit 9a2f86c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.annotation.layer.relation;

import org.apache.uima.jcas.tcas.Annotation;
import org.springframework.context.event.EventListener;

import de.tudarmstadt.ukp.inception.annotation.layer.span.SpanMovedEvent;
import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService;

public class RelationEndpointChangeListener
{
private final AnnotationSchemaService schemaService;

public RelationEndpointChangeListener(AnnotationSchemaService aSchemaService)
{
schemaService = aSchemaService;
}

@EventListener
public void onSpanMovedEvent(SpanMovedEvent aEvent)
{
var span = aEvent.getAnnotation();
var cas = span.getCAS();

for (var relLayer : schemaService.listAttachedRelationLayers(aEvent.getLayer())) {
var relAdapter = (RelationAdapter) schemaService.getAdapter(relLayer);
var maybeRelType = relAdapter.getAnnotationType(cas);
if (!maybeRelType.isPresent()) {
continue;
}

var relCandidates = cas.<Annotation> select(maybeRelType.get()) //
.at(aEvent.getOldBegin(), aEvent.getOldEnd()) //
.asList();

for (var relCandidate : relCandidates) {
if (!span.equals(relAdapter.getTargetAnnotation(relCandidate))) {
continue;
}

relCandidate.removeFromIndexes();
relCandidate.setBegin(span.getBegin());
relCandidate.setEnd(span.getEnd());
relCandidate.addToIndexes();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import de.tudarmstadt.ukp.inception.annotation.layer.chain.ChainLayerSupport;
import de.tudarmstadt.ukp.inception.annotation.layer.relation.RelationAttachmentBehavior;
import de.tudarmstadt.ukp.inception.annotation.layer.relation.RelationCrossSentenceBehavior;
import de.tudarmstadt.ukp.inception.annotation.layer.relation.RelationEndpointChangeListener;
import de.tudarmstadt.ukp.inception.annotation.layer.relation.RelationLayerSupport;
import de.tudarmstadt.ukp.inception.annotation.layer.relation.RelationOverlapBehavior;
import de.tudarmstadt.ukp.inception.annotation.layer.span.SpanAnchoringModeBehavior;
Expand Down Expand Up @@ -151,6 +152,13 @@ public RelationLayerSupport relationLayerSupport(FeatureSupportRegistry aFeature
aLayerBehaviorsRegistry, aConstraintsService);
}

@Bean
public RelationEndpointChangeListener relationEndpointChangeListener(
AnnotationSchemaService aSchemaService)
{
return new RelationEndpointChangeListener(aSchemaService);
}

@Bean
public ChainLayerSupport chainLayerSupport(FeatureSupportRegistry aFeatureSupportRegistry,
ApplicationEventPublisher aEventPublisher,
Expand Down

0 comments on commit 9a2f86c

Please sign in to comment.