From 9d74fa4fe018134df0a511c0d11cd4b43a2f8a16 Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Tue, 7 Nov 2023 20:48:46 +0100 Subject: [PATCH] Revert "#4285 - Upgrade dependencies" This reverts commit 10d6be2258e7846e73429a7bb5329b906661451f. --- .../annotation/layer/span/SpanRenderer.java | 38 +++++++++++++++-- .../casdiff/span/SpanDiffAdapter.java | 41 +++++++++++++++++-- ...ationsStartAndEndWithinSentencesCheck.java | 18 ++++++-- .../inception/io/bioc/model/CasToBioC.java | 18 ++++++-- .../io/bioc/xml/Cas2BioCSaxEvents.java | 7 +++- .../pdfeditor2/format/VisualPdfReader.java | 8 +++- .../service/RecommendationServiceImpl.java | 40 ++++++++++++------ .../detail/AnnotationDetailEditorPanel.java | 11 ++++- 8 files changed, 149 insertions(+), 32 deletions(-) diff --git a/inception/inception-api-annotation/src/main/java/de/tudarmstadt/ukp/inception/annotation/layer/span/SpanRenderer.java b/inception/inception-api-annotation/src/main/java/de/tudarmstadt/ukp/inception/annotation/layer/span/SpanRenderer.java index 050b2d41c57..0aa9c4dba39 100644 --- a/inception/inception-api-annotation/src/main/java/de/tudarmstadt/ukp/inception/annotation/layer/span/SpanRenderer.java +++ b/inception/inception-api-annotation/src/main/java/de/tudarmstadt/ukp/inception/annotation/layer/span/SpanRenderer.java @@ -30,6 +30,7 @@ import java.util.Optional; import org.apache.uima.cas.CAS; +import org.apache.uima.cas.FSIterator; import org.apache.uima.cas.FeatureStructure; import org.apache.uima.cas.Type; import org.apache.uima.cas.TypeSystem; @@ -92,9 +93,40 @@ protected boolean typeSystemInit(TypeSystem aTypeSystem) @Override public List selectAnnotationsInWindow(CAS aCas, int aWindowBegin, int aWindowEnd) { - return aCas.select(type).coveredBy(0, aWindowEnd).includeAnnotationsWithEndBeyondBounds() - .map(fs -> (AnnotationFS) fs) - .filter(ann -> AnnotationPredicates.overlapping(ann, aWindowBegin, aWindowEnd)) + // https://github.com/apache/uima-uimaj/issues/345 + // return aCas.select(type).coveredBy(0, aWindowEnd).includeAnnotationsWithEndBeyondBounds() + // .map(fs -> (AnnotationFS) fs) + // .filter(ann -> AnnotationPredicates.overlapping(ann, aWindowBegin, aWindowEnd)) + // .collect(toList()); + + List list = new ArrayList(); + + // withSnapshotIterators() not needed here since we copy the FSes to a list anyway + FSIterator it = aCas.getAnnotationIndex(type).iterator(); + + // Skip annotations whose start is before the start parameter. + while (it.isValid() && (it.get()).getBegin() < 0) { + it.moveToNext(); + } + + boolean strict = false; + while (it.isValid()) { + AnnotationFS a = it.get(); + // If the start of the current annotation is past the end parameter, we're done. + if (a.getBegin() > aWindowEnd) { + break; + } + it.moveToNext(); + if (strict && a.getEnd() > aWindowEnd) { + continue; + } + + list.add(a); + } + + return list.stream() // + .map(fs -> (AnnotationFS) fs) // + .filter(ann -> AnnotationPredicates.overlapping(ann, aWindowBegin, aWindowEnd)) // .collect(toList()); } diff --git a/inception/inception-curation-legacy/src/main/java/de/tudarmstadt/ukp/clarin/webanno/curation/casdiff/span/SpanDiffAdapter.java b/inception/inception-curation-legacy/src/main/java/de/tudarmstadt/ukp/clarin/webanno/curation/casdiff/span/SpanDiffAdapter.java index 4ad640c22bc..e17a522228e 100644 --- a/inception/inception-curation-legacy/src/main/java/de/tudarmstadt/ukp/clarin/webanno/curation/casdiff/span/SpanDiffAdapter.java +++ b/inception/inception-curation-legacy/src/main/java/de/tudarmstadt/ukp/clarin/webanno/curation/casdiff/span/SpanDiffAdapter.java @@ -20,14 +20,17 @@ import static java.util.Arrays.asList; import static java.util.stream.Collectors.toList; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.uima.cas.CAS; +import org.apache.uima.cas.FSIterator; import org.apache.uima.cas.FeatureStructure; import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.cas.text.AnnotationPredicates; +import org.apache.uima.fit.util.CasUtil; import org.apache.uima.fit.util.FSUtil; import de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil; @@ -71,9 +74,41 @@ public SpanDiffAdapter(String aType, Set aLabelFeatures) @Override public List selectAnnotationsInWindow(CAS aCas, int aWindowBegin, int aWindowEnd) { - return aCas.select(getType()).coveredBy(0, aWindowEnd) - .includeAnnotationsWithEndBeyondBounds().map(fs -> (AnnotationFS) fs) - .filter(ann -> AnnotationPredicates.overlapping(ann, aWindowBegin, aWindowEnd)) + // https://github.com/apache/uima-uimaj/issues/345 + // return aCas.select(type).coveredBy(0, aWindowEnd).includeAnnotationsWithEndBeyondBounds() + // .map(fs -> (AnnotationFS) fs) + // .filter(ann -> AnnotationPredicates.overlapping(ann, aWindowBegin, aWindowEnd)) + // .collect(toList()); + + List list = new ArrayList(); + + // withSnapshotIterators() not needed here since we copy the FSes to a list anyway + FSIterator it = aCas.getAnnotationIndex(CasUtil.getType(aCas, getType())) + .iterator(); + + // Skip annotations whose start is before the start parameter. + while (it.isValid() && (it.get()).getBegin() < aWindowBegin) { + it.moveToNext(); + } + + boolean strict = false; + while (it.isValid()) { + AnnotationFS a = it.get(); + // If the start of the current annotation is past the end parameter, we're done. + if (a.getBegin() > aWindowEnd) { + break; + } + it.moveToNext(); + if (strict && a.getEnd() > aWindowEnd) { + continue; + } + + list.add(a); + } + + return list.stream() // + .map(fs -> (AnnotationFS) fs) // + .filter(ann -> AnnotationPredicates.overlapping(ann, aWindowBegin, aWindowEnd)) // .collect(toList()); } diff --git a/inception/inception-diag/src/main/java/de/tudarmstadt/ukp/clarin/webanno/diag/checks/AllAnnotationsStartAndEndWithinSentencesCheck.java b/inception/inception-diag/src/main/java/de/tudarmstadt/ukp/clarin/webanno/diag/checks/AllAnnotationsStartAndEndWithinSentencesCheck.java index f17ba3e1434..d68d344e0cf 100644 --- a/inception/inception-diag/src/main/java/de/tudarmstadt/ukp/clarin/webanno/diag/checks/AllAnnotationsStartAndEndWithinSentencesCheck.java +++ b/inception/inception-diag/src/main/java/de/tudarmstadt/ukp/clarin/webanno/diag/checks/AllAnnotationsStartAndEndWithinSentencesCheck.java @@ -27,6 +27,7 @@ import org.apache.uima.cas.CAS; import org.apache.uima.cas.Type; import org.apache.uima.cas.text.AnnotationFS; +import org.apache.uima.fit.util.CasUtil; import org.springframework.util.CollectionUtils; import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer; @@ -76,10 +77,19 @@ public boolean check(Project aProject, CAS aCas, List aMessages) } for (AnnotationFS ann : select(aCas, type)) { - var startsOutside = aCas.select(Sentence._TypeName) - .covering(ann.getBegin(), ann.getBegin()).isEmpty(); - var endsOutside = aCas.select(Sentence._TypeName) - .covering(ann.getEnd(), ann.getEnd()).isEmpty(); + // https://github.com/apache/uima-uimaj/issues/345 + // var startsOutside = aCas.select(Sentence._TypeName) + // .covering(ann.getBegin(), ann.getBegin()).isEmpty(); + var startsOutside = CasUtil + .selectCovering(ann.getCAS(), CasUtil.getType(ann.getCAS(), Sentence.class), + ann.getBegin(), ann.getBegin()) + .isEmpty(); + // https://github.com/apache/uima-uimaj/issues/345 + // var endsOutside = aCas.select(Sentence._TypeName) + // .covering(ann.getEnd(), ann.getEnd()).isEmpty(); + var endsOutside = CasUtil.selectCovering(ann.getCAS(), + CasUtil.getType(ann.getCAS(), Sentence.class), ann.getEnd(), ann.getEnd()) + .isEmpty(); if (!startsOutside && !endsOutside) { continue; diff --git a/inception/inception-io-bioc/src/main/java/de/tudarmstadt/ukp/inception/io/bioc/model/CasToBioC.java b/inception/inception-io-bioc/src/main/java/de/tudarmstadt/ukp/inception/io/bioc/model/CasToBioC.java index d61aa34634c..8e389b28220 100644 --- a/inception/inception-io-bioc/src/main/java/de/tudarmstadt/ukp/inception/io/bioc/model/CasToBioC.java +++ b/inception/inception-io-bioc/src/main/java/de/tudarmstadt/ukp/inception/io/bioc/model/CasToBioC.java @@ -40,6 +40,7 @@ import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.fit.util.FSUtil; +import org.apache.uima.fit.util.JCasUtil; import org.apache.uima.jcas.JCas; import org.apache.uima.jcas.tcas.Annotation; import org.dkpro.core.api.xml.type.XmlElement; @@ -81,8 +82,12 @@ public void convert(JCas aJCas, BioCCollection aCollection) bioCPassage.addInfon(I_TYPE, div.getDivType()); } - var sentences = aJCas.select(Sentence.class).coveredBy(div).asList(); - var annotations = aJCas.select(Annotation.class).coveredBy(div); + // https://github.com/apache/uima-uimaj/issues/345 + // var sentences = aJCas.select(Sentence.class).coveredBy(div).asList(); + var sentences = JCasUtil.selectCovered(Sentence.class, div); + // https://github.com/apache/uima-uimaj/issues/345 + // var annotations = aJCas.select(Annotation.class).coveredBy(div); + var annotations = JCasUtil.selectCovered(Annotation.class, div); if (sentences.isEmpty()) { bioCPassage.setText(div.getCoveredText()); processAnnotations(bioCPassage, bioCPassage.getOffset(), annotations); @@ -91,7 +96,10 @@ public void convert(JCas aJCas, BioCCollection aCollection) var bioCSentences = processSentences(div.getBegin(), sentences); bioCPassage.setSentences(bioCSentences); processAnnotations(bioCPassage, bioCPassage.getOffset(), - annotations.filter(a -> aJCas.select(Sentence.class).covering(a).isEmpty()) + annotations.stream().filter(a -> + // https://github.com/apache/uima-uimaj/issues/345 + // aJCas.select(Sentence.class).covering(a).isEmpty() + JCasUtil.selectCovering(Sentence.class, a).isEmpty()) .collect(Collectors.toList())); } } @@ -128,7 +136,9 @@ private List processSentences(int aPassageOffset, List s bioCSentence.setText(sentence.getCoveredText()); processAnnotations(bioCSentence, sentence.getBegin(), - sentence.getCAS().select(Annotation.class).coveredBy(sentence)); + // https://github.com/apache/uima-uimaj/issues/345 + // sentence.getCAS().select(Annotation.class).coveredBy(sentence) + JCasUtil.selectCovered(Annotation.class, sentence)); bioCSentences.add(bioCSentence); } diff --git a/inception/inception-io-bioc/src/main/java/de/tudarmstadt/ukp/inception/io/bioc/xml/Cas2BioCSaxEvents.java b/inception/inception-io-bioc/src/main/java/de/tudarmstadt/ukp/inception/io/bioc/xml/Cas2BioCSaxEvents.java index 31854625b8d..d2a7351539c 100644 --- a/inception/inception-io-bioc/src/main/java/de/tudarmstadt/ukp/inception/io/bioc/xml/Cas2BioCSaxEvents.java +++ b/inception/inception-io-bioc/src/main/java/de/tudarmstadt/ukp/inception/io/bioc/xml/Cas2BioCSaxEvents.java @@ -58,6 +58,7 @@ import org.apache.uima.cas.CAS; import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.fit.util.FSUtil; +import org.apache.uima.fit.util.JCasUtil; import org.apache.uima.jcas.JCas; import org.apache.uima.jcas.tcas.Annotation; import org.dkpro.core.api.xml.type.XmlElement; @@ -139,8 +140,10 @@ private void processSentenceElement(XmlElement aSentenceElement) throws SAXExcep return; } - var annotations = aSentenceElement.getCAS().select(Annotation.class) - .coveredBy(aSentenceElement); + // https://github.com/apache/uima-uimaj/issues/345 + // var annotations = aSentenceElement.getCAS().select(Annotation.class) + // .coveredBy(aSentenceElement); + var annotations = JCasUtil.selectCovered(Annotation.class, aSentenceElement); for (var annotation : annotations) { serializeAnnotation(sentenceTextElement.get().getBegin(), annotation); } diff --git a/inception/inception-pdf-editor2/src/main/java/de/tudarmstadt/ukp/inception/pdfeditor2/format/VisualPdfReader.java b/inception/inception-pdf-editor2/src/main/java/de/tudarmstadt/ukp/inception/pdfeditor2/format/VisualPdfReader.java index b661be7b457..318683c6fa1 100644 --- a/inception/inception-pdf-editor2/src/main/java/de/tudarmstadt/ukp/inception/pdfeditor2/format/VisualPdfReader.java +++ b/inception/inception-pdf-editor2/src/main/java/de/tudarmstadt/ukp/inception/pdfeditor2/format/VisualPdfReader.java @@ -27,6 +27,7 @@ import org.apache.uima.cas.CAS; import org.apache.uima.collection.CollectionException; import org.apache.uima.fit.descriptor.ConfigurationParameter; +import org.apache.uima.fit.util.CasUtil; import org.apache.uima.jcas.JCas; import org.apache.uima.jcas.cas.FloatArray; import org.apache.uima.jcas.cas.IntegerArray; @@ -116,8 +117,11 @@ public static VModel visualModelFromCas(CAS cas, List pdfPages) VModel vModel; List vPages = new ArrayList<>(); for (PdfPage pdfPage : pdfPages) { - var vChunks = new ArrayList(); - var coveredBy = cas.select(PdfChunk.class).coveredBy(pdfPage); + List vChunks = new ArrayList<>(); + // https://github.com/apache/uima-uimaj/issues/345 + // SelectFSs coveredBy = cas.select(PdfChunk.class).coveredBy(pdfPage); + List coveredBy = (List) CasUtil + .selectCovered(CasUtil.getType(cas, PdfChunk.class), pdfPage); for (var pdfChunk : coveredBy) { float d = pdfChunk.getD(); List vGlyphs = new ArrayList<>(); diff --git a/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/service/RecommendationServiceImpl.java b/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/service/RecommendationServiceImpl.java index fa7e72568d6..7d6ba5421c2 100644 --- a/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/service/RecommendationServiceImpl.java +++ b/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/service/RecommendationServiceImpl.java @@ -1081,9 +1081,12 @@ private AnnotationFS acceptOrCorrectSuggestion(String aSessionOwner, SourceDocum var aEnd = aSuggestion.getEnd(); var aValue = aSuggestion.getLabel(); - var candidates = aCas. select(aAdapter.getAnnotationTypeName()) // - .at(aBegin, aEnd) // - .asList(); + // https://github.com/apache/uima-uimaj/issues/345 + // var candidates = aCas. select(aAdapter.getAnnotationTypeName()) // + // .at(aBegin, aEnd) // + // .asList(); + var candidates = CasUtil.selectAt(aCas, + CasUtil.getType(aCas, aAdapter.getAnnotationTypeName()), aBegin, aEnd); var candidateWithEmptyLabel = candidates.stream() // .filter(c -> aAdapter.getFeatureValue(aFeature, c) == null) // @@ -2084,9 +2087,15 @@ private static Optional getOffsetsAnchoredOnSingleTokens(CAS aOriginalCa Annotation aPredictedAnnotation) { Type tokenType = getType(aOriginalCas, Token.class); - var tokens = aOriginalCas. select(tokenType) // - .coveredBy(aPredictedAnnotation) // - .limit(2).asList(); + // https://github.com/apache/uima-uimaj/issues/345 + // var tokens = aOriginalCas. select(tokenType) // + // .coveredBy(aPredictedAnnotation) // + // .limit(2).asList(); + var tokens = CasUtil + .selectCovered(aOriginalCas, tokenType, aPredictedAnnotation.getBegin(), + aPredictedAnnotation.getEnd()) + .stream() // + .limit(2).collect(toList()); if (tokens.isEmpty()) { // This can happen if a recommender uses different token boundaries (e.g. if a @@ -2113,9 +2122,13 @@ private static Optional getOffsetsAnchoredOnSingleTokens(CAS aOriginalCa private static Optional getOffsetsAnchoredOnSentences(CAS aOriginalCas, Annotation aPredictedAnnotation) { - var sentences = aOriginalCas.select(Sentence.class) // - .coveredBy(aPredictedAnnotation) // - .asList(); + // https://github.com/apache/uima-uimaj/issues/345 + // var sentences = aOriginalCas.select(Sentence.class) // + // .coveredBy(aPredictedAnnotation) // + // .asList(); + var sentences = CasUtil.selectCovered(aOriginalCas, + CasUtil.getType(aOriginalCas, Sentence.class), aPredictedAnnotation.getBegin(), + aPredictedAnnotation.getEnd()); if (sentences.isEmpty()) { // This can happen if a recommender uses different token boundaries (e.g. if a @@ -2134,9 +2147,12 @@ private static Optional getOffsetsAnchoredOnSentences(CAS aOriginalCas, static Optional getOffsetsAnchoredOnTokens(CAS aOriginalCas, Annotation aPredictedAnnotation) { - var tokens = aOriginalCas.select(Token.class) // - .coveredBy(aPredictedAnnotation) // - .asList(); + // https://github.com/apache/uima-uimaj/issues/345 + // var tokens = aOriginalCas.select(Token.class) // + // .coveredBy(aPredictedAnnotation) // + // .asList(); + var tokens = CasUtil.selectCovered(aOriginalCas, CasUtil.getType(aOriginalCas, Token.class), + aPredictedAnnotation.getBegin(), aPredictedAnnotation.getEnd()); if (tokens.isEmpty()) { if (aPredictedAnnotation.getBegin() == aPredictedAnnotation.getEnd()) { diff --git a/inception/inception-ui-annotation/src/main/java/de/tudarmstadt/ukp/clarin/webanno/ui/annotation/detail/AnnotationDetailEditorPanel.java b/inception/inception-ui-annotation/src/main/java/de/tudarmstadt/ukp/clarin/webanno/ui/annotation/detail/AnnotationDetailEditorPanel.java index be0a6215088..5c6344ed73b 100644 --- a/inception/inception-ui-annotation/src/main/java/de/tudarmstadt/ukp/clarin/webanno/ui/annotation/detail/AnnotationDetailEditorPanel.java +++ b/inception/inception-ui-annotation/src/main/java/de/tudarmstadt/ukp/clarin/webanno/ui/annotation/detail/AnnotationDetailEditorPanel.java @@ -1235,8 +1235,15 @@ public void onBulkAnnotationEvent(BulkAnnotationEvent aEvent) try { var selection = getModelObject().getSelection(); int id = selection.getAnnotation().getId(); - boolean annotationStillExists = getEditorCas().select(Annotation.class) // - .at(selection.getBegin(), selection.getEnd()) // + // https://github.com/apache/uima-uimaj/issues/345 + // boolean annotationStillExists = getEditorCas().select(Annotation.class) // + // .at(selection.getBegin(), selection.getEnd()) // + // .anyMatch(ann -> ann._id() == id); + var cas = getEditorCas(); + boolean annotationStillExists = CasUtil + .selectAt(cas, CasUtil.getType(cas, Annotation.class), selection.getBegin(), + selection.getEnd()) + .stream() // .anyMatch(ann -> ann._id() == id); if (!annotationStillExists) {