Skip to content

Commit

Permalink
#4285 - Upgrade dependencies
Browse files Browse the repository at this point in the history
- Remove workaround for apache/uima-uimaj#345
  • Loading branch information
reckart committed Nov 7, 2023
1 parent 28e2775 commit 10d6be2
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
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;
Expand Down Expand Up @@ -93,40 +92,9 @@ protected boolean typeSystemInit(TypeSystem aTypeSystem)
@Override
public List<AnnotationFS> selectAnnotationsInWindow(CAS aCas, int aWindowBegin, int 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<AnnotationFS> list = new ArrayList<AnnotationFS>();

// withSnapshotIterators() not needed here since we copy the FSes to a list anyway
FSIterator<AnnotationFS> 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)) //
return aCas.select(type).coveredBy(0, aWindowEnd).includeAnnotationsWithEndBeyondBounds()
.map(fs -> (AnnotationFS) fs)
.filter(ann -> AnnotationPredicates.overlapping(ann, aWindowBegin, aWindowEnd))
.collect(toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@
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;
Expand Down Expand Up @@ -74,41 +71,9 @@ public SpanDiffAdapter(String aType, Set<String> aLabelFeatures)
@Override
public List<AnnotationFS> selectAnnotationsInWindow(CAS aCas, int aWindowBegin, int 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<AnnotationFS> list = new ArrayList<AnnotationFS>();

// withSnapshotIterators() not needed here since we copy the FSes to a list anyway
FSIterator<AnnotationFS> 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)) //
return aCas.select(getType()).coveredBy(0, aWindowEnd)
.includeAnnotationsWithEndBeyondBounds().map(fs -> (AnnotationFS) fs)
.filter(ann -> AnnotationPredicates.overlapping(ann, aWindowBegin, aWindowEnd))
.collect(toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
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;
Expand Down Expand Up @@ -77,19 +76,10 @@ public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages)
}

for (AnnotationFS ann : select(aCas, type)) {
// 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();
var startsOutside = aCas.select(Sentence._TypeName)
.covering(ann.getBegin(), ann.getBegin()).isEmpty();
var endsOutside = aCas.select(Sentence._TypeName)
.covering(ann.getEnd(), ann.getEnd()).isEmpty();

if (!startsOutside && !endsOutside) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

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;
Expand Down Expand Up @@ -82,12 +81,8 @@ public void convert(JCas aJCas, BioCCollection aCollection)
bioCPassage.addInfon(I_TYPE, div.getDivType());
}

// 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);
var sentences = aJCas.select(Sentence.class).coveredBy(div).asList();
var annotations = aJCas.select(Annotation.class).coveredBy(div);
if (sentences.isEmpty()) {
bioCPassage.setText(div.getCoveredText());
processAnnotations(bioCPassage, bioCPassage.getOffset(), annotations);
Expand All @@ -96,10 +91,7 @@ public void convert(JCas aJCas, BioCCollection aCollection)
var bioCSentences = processSentences(div.getBegin(), sentences);
bioCPassage.setSentences(bioCSentences);
processAnnotations(bioCPassage, bioCPassage.getOffset(),
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())
annotations.filter(a -> aJCas.select(Sentence.class).covering(a).isEmpty())
.collect(Collectors.toList()));
}
}
Expand Down Expand Up @@ -136,9 +128,7 @@ private List<BioCSentence> processSentences(int aPassageOffset, List<Sentence> s
bioCSentence.setText(sentence.getCoveredText());

processAnnotations(bioCSentence, sentence.getBegin(),
// https://github.com/apache/uima-uimaj/issues/345
// sentence.getCAS().select(Annotation.class).coveredBy(sentence)
JCasUtil.selectCovered(Annotation.class, sentence));
sentence.getCAS().select(Annotation.class).coveredBy(sentence));

bioCSentences.add(bioCSentence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
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;
Expand Down Expand Up @@ -140,10 +139,8 @@ private void processSentenceElement(XmlElement aSentenceElement) throws SAXExcep
return;
}

// https://github.com/apache/uima-uimaj/issues/345
// var annotations = aSentenceElement.getCAS().select(Annotation.class)
// .coveredBy(aSentenceElement);
var annotations = JCasUtil.selectCovered(Annotation.class, aSentenceElement);
var annotations = aSentenceElement.getCAS().select(Annotation.class)
.coveredBy(aSentenceElement);
for (var annotation : annotations) {
serializeAnnotation(sentenceTextElement.get().getBegin(), annotation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
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;
Expand Down Expand Up @@ -117,11 +116,8 @@ public static VModel visualModelFromCas(CAS cas, List<PdfPage> pdfPages)
VModel vModel;
List<VPage> vPages = new ArrayList<>();
for (PdfPage pdfPage : pdfPages) {
List<VChunk> vChunks = new ArrayList<>();
// https://github.com/apache/uima-uimaj/issues/345
// SelectFSs<PdfChunk> coveredBy = cas.select(PdfChunk.class).coveredBy(pdfPage);
List<PdfChunk> coveredBy = (List) CasUtil
.selectCovered(CasUtil.getType(cas, PdfChunk.class), pdfPage);
var vChunks = new ArrayList<VChunk>();
var coveredBy = cas.select(PdfChunk.class).coveredBy(pdfPage);
for (var pdfChunk : coveredBy) {
float d = pdfChunk.getD();
List<VGlyph> vGlyphs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1081,12 +1081,9 @@ private AnnotationFS acceptOrCorrectSuggestion(String aSessionOwner, SourceDocum
var aEnd = aSuggestion.getEnd();
var aValue = aSuggestion.getLabel();

// https://github.com/apache/uima-uimaj/issues/345
// var candidates = aCas.<Annotation> select(aAdapter.getAnnotationTypeName()) //
// .at(aBegin, aEnd) //
// .asList();
var candidates = CasUtil.selectAt(aCas,
CasUtil.getType(aCas, aAdapter.getAnnotationTypeName()), aBegin, aEnd);
var candidates = aCas.<Annotation> select(aAdapter.getAnnotationTypeName()) //
.at(aBegin, aEnd) //
.asList();

var candidateWithEmptyLabel = candidates.stream() //
.filter(c -> aAdapter.getFeatureValue(aFeature, c) == null) //
Expand Down Expand Up @@ -2087,15 +2084,9 @@ private static Optional<Offset> getOffsetsAnchoredOnSingleTokens(CAS aOriginalCa
Annotation aPredictedAnnotation)
{
Type tokenType = getType(aOriginalCas, Token.class);
// https://github.com/apache/uima-uimaj/issues/345
// var tokens = aOriginalCas.<Annotation> select(tokenType) //
// .coveredBy(aPredictedAnnotation) //
// .limit(2).asList();
var tokens = CasUtil
.selectCovered(aOriginalCas, tokenType, aPredictedAnnotation.getBegin(),
aPredictedAnnotation.getEnd())
.stream() //
.limit(2).collect(toList());
var tokens = aOriginalCas.<Annotation> select(tokenType) //
.coveredBy(aPredictedAnnotation) //
.limit(2).asList();

if (tokens.isEmpty()) {
// This can happen if a recommender uses different token boundaries (e.g. if a
Expand All @@ -2122,13 +2113,9 @@ private static Optional<Offset> getOffsetsAnchoredOnSingleTokens(CAS aOriginalCa
private static Optional<Offset> getOffsetsAnchoredOnSentences(CAS aOriginalCas,
Annotation aPredictedAnnotation)
{
// 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());
var sentences = aOriginalCas.select(Sentence.class) //
.coveredBy(aPredictedAnnotation) //
.asList();

if (sentences.isEmpty()) {
// This can happen if a recommender uses different token boundaries (e.g. if a
Expand All @@ -2147,12 +2134,9 @@ private static Optional<Offset> getOffsetsAnchoredOnSentences(CAS aOriginalCas,
static Optional<Offset> getOffsetsAnchoredOnTokens(CAS aOriginalCas,
Annotation aPredictedAnnotation)
{
// 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());
var tokens = aOriginalCas.select(Token.class) //
.coveredBy(aPredictedAnnotation) //
.asList();

if (tokens.isEmpty()) {
if (aPredictedAnnotation.getBegin() == aPredictedAnnotation.getEnd()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,15 +1235,8 @@ public void onBulkAnnotationEvent(BulkAnnotationEvent aEvent)
try {
var selection = getModelObject().getSelection();
int id = selection.getAnnotation().getId();
// 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() //
boolean annotationStillExists = getEditorCas().select(Annotation.class) //
.at(selection.getBegin(), selection.getEnd()) //
.anyMatch(ann -> ann._id() == id);

if (!annotationStillExists) {
Expand Down

0 comments on commit 10d6be2

Please sign in to comment.