Skip to content

Commit

Permalink
Merge branch 'main' into feature/1321-Importing-.ann-files-from-BRAT
Browse files Browse the repository at this point in the history
* main:
  [maven-release-plugin] prepare for next development iteration
  [maven-release-plugin] prepare release inception-31.3
  #4622 - No helpful error message when recommender is not called due to feature being disabled
  #4550 - Clean up code
  • Loading branch information
reckart committed Mar 12, 2024
2 parents 6ec028d + d6337bd commit 5c522da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

import org.apache.commons.lang3.tuple.Pair;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.fit.util.CasUtil;
import org.slf4j.Logger;
Expand Down Expand Up @@ -99,8 +97,7 @@ public AnnotationFS add(SourceDocument aDocument, String aDataOwner, CAS aCas, i
int aEnd)
throws AnnotationException
{
return handle(
new CreateSpanAnnotationRequest(aDocument, aDataOwner, aCas, aBegin, aEnd));
return handle(new CreateSpanAnnotationRequest(aDocument, aDataOwner, aCas, aBegin, aEnd));
}

public AnnotationFS handle(CreateSpanAnnotationRequest aRequest) throws AnnotationException
Expand Down Expand Up @@ -152,16 +149,16 @@ public AnnotationFS move(SourceDocument aDocument, String aDocumentOwner, CAS aC

public AnnotationFS handle(MoveSpanAnnotationRequest aRequest) throws AnnotationException
{
MoveSpanAnnotationRequest request = aRequest;
var request = aRequest;

// Adjust the move request (e.g. adjust offsets to the configured granularity) or
// reject the request (e.g. reject cross-sentence annotations)
for (SpanLayerBehavior behavior : behaviors) {
for (var behavior : behaviors) {
request = behavior.onMove(this, request);
}

int oldBegin = request.getAnnotation().getBegin();
int oldEnd = request.getAnnotation().getEnd();
var oldBegin = request.getAnnotation().getBegin();
var oldEnd = request.getAnnotation().getEnd();
moveSpanAnnotation(request.getCas(), request.getAnnotation(), request.getBegin(),
request.getEnd());

Expand All @@ -176,8 +173,8 @@ public AnnotationFS handle(MoveSpanAnnotationRequest aRequest) throws Annotation
private AnnotationFS createSpanAnnotation(CAS aCas, int aBegin, int aEnd)
throws AnnotationException
{
Type type = CasUtil.getType(aCas, getAnnotationTypeName());
AnnotationFS newAnnotation = aCas.createAnnotation(type, aBegin, aEnd);
var type = CasUtil.getType(aCas, getAnnotationTypeName());
var newAnnotation = aCas.createAnnotation(type, aBegin, aEnd);

log.trace("Created span annotation {}-{} [{}]", newAnnotation.getBegin(),
newAnnotation.getEnd(), newAnnotation.getCoveredText());
Expand Down Expand Up @@ -216,7 +213,7 @@ private AnnotationFS moveSpanAnnotation(CAS aCas, AnnotationFS aAnnotation, int
@Override
public void delete(SourceDocument aDocument, String aDocumentOwner, CAS aCas, VID aVid)
{
AnnotationFS fs = selectByAddr(aCas, AnnotationFS.class, aVid.getId());
var fs = selectByAddr(aCas, AnnotationFS.class, aVid.getId());
aCas.removeFsFromIndexes(fs);

// delete associated attachFeature
Expand All @@ -230,7 +227,7 @@ public void delete(SourceDocument aDocument, String aDocumentOwner, CAS aCas, VI
public AnnotationFS restore(SourceDocument aDocument, String aDocumentOwner, CAS aCas, VID aVid)
throws AnnotationException
{
AnnotationFS fs = selectByAddr(aCas, AnnotationFS.class, aVid.getId());
var fs = selectByAddr(aCas, AnnotationFS.class, aVid.getId());

if (getAttachFeatureName() != null) {
attach(aCas, fs.getBegin(), fs.getEnd(), fs);
Expand All @@ -246,8 +243,8 @@ public AnnotationFS restore(SourceDocument aDocument, String aDocumentOwner, CAS
private void attach(CAS aCas, int aBegin, int aEnd, AnnotationFS newAnnotation)
throws IllegalPlacementException
{
Type theType = getType(aCas, getAttachTypeName());
Feature attachFeature = theType.getFeatureByBaseName(getAttachFeatureName());
var theType = getType(aCas, getAttachTypeName());
var attachFeature = theType.getFeatureByBaseName(getAttachFeatureName());
if (selectCovered(aCas, theType, aBegin, aEnd).isEmpty()) {
throw new IllegalPlacementException("No annotation of type [" + getAttachTypeName()
+ "] to attach to at location [" + aBegin + "-" + aEnd + "].");
Expand All @@ -258,8 +255,8 @@ private void attach(CAS aCas, int aBegin, int aEnd, AnnotationFS newAnnotation)

private void detatch(CAS aCas, AnnotationFS fs)
{
Type theType = getType(aCas, getAttachTypeName());
Feature attachFeature = theType.getFeatureByBaseName(getAttachFeatureName());
var theType = getType(aCas, getAttachTypeName());
var attachFeature = theType.getFeatureByBaseName(getAttachFeatureName());
if (attachFeature != null) {
selectCovered(aCas, theType, fs.getBegin(), fs.getEnd()).get(0)
.setFeatureValue(attachFeature, null);
Expand All @@ -269,20 +266,22 @@ private void detatch(CAS aCas, AnnotationFS fs)
@Override
public List<Pair<LogMessage, AnnotationFS>> validate(CAS aCas)
{
List<Pair<LogMessage, AnnotationFS>> messages = new ArrayList<>();
for (SpanLayerBehavior behavior : behaviors) {
long startTime = currentTimeMillis();
var messages = new ArrayList<Pair<LogMessage, AnnotationFS>>();

for (var behavior : behaviors) {
var startTime = currentTimeMillis();
messages.addAll(behavior.onValidate(this, aCas));
log.trace("Validation for [{}] on [{}] took {}ms", behavior.getClass().getSimpleName(),
getLayer().getUiName(), currentTimeMillis() - startTime);
}

return messages;
}

@Override
public Selection select(VID aVid, AnnotationFS aAnno)
{
Selection selection = new Selection();
var selection = new Selection();
selection.selectSpan(aAnno);
return selection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ private void logTrainingOverallEnd(long overallStartTime)

private void logUnsupportedRecommenderType(Recommender aRecommender)
{
warn("Recommender [%s] uses unsupported tool [%s] - skipping", aRecommender.getName(),
aRecommender.getTool());
LOG.warn("[{}][{}]: No factory found - skipping recommender",
getSessionOwner().getUsername(), aRecommender.getName());
}
Expand All @@ -270,18 +272,22 @@ private void logTrainingNotSupported(Recommender aRecommender)

private void logRecommenderDisabled(Recommender aRecommender)
{
LOG.debug("[{}][{}][{}]: Recommenderdisabled - skipping", getSessionOwner().getUsername(),
LOG.debug("[{}][{}][{}]: Recommender disabled - skipping", getSessionOwner().getUsername(),
getId(), aRecommender.getName());
}

private void logLayerDisabled(Recommender aRecommender)
{
warn("Recommender [%s] uses disabled layer [%s] disabled - skipping recommender.",
aRecommender.getName(), aRecommender.getLayer().getUiName());
LOG.debug("[{}][{}][{}]: Layer disabled - skipping", getSessionOwner().getUsername(),
getId(), aRecommender.getLayer().getUiName());
}

private void logFeatureDisabled(Recommender aRecommender)
{
warn("Recommender [%s] uses disabled feature [%s] - skipping recommender.",
aRecommender.getName(), aRecommender.getFeature().getUiName());
LOG.debug("[{}][{}][{}]: Feature disabled - skipping", getSessionOwner().getUsername(),
getId(), aRecommender.getFeature().getUiName());
}
Expand Down

0 comments on commit 5c522da

Please sign in to comment.