From eb667835c5580dfa2e772b592a2cebc06793362e Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Tue, 26 Dec 2023 23:34:03 +0100 Subject: [PATCH] #2696 - Document-level recommendations - Removed a bunch of unused methods - Moved a bunch of methods only used once to the classes where they are used --- .../brat/render/BratSerializerImplTest.java | 29 +++- .../service/ConceptLinkingServiceImpl.java | 34 +++- .../checks/UnreachableAnnotationsCheck.java | 12 +- inception/inception-pdf-editor/pom.xml | 9 +- .../pdfeditor/PdfAnnotationEditor.java | 20 ++- .../relation/RelationSuggestionSupport.java | 7 +- ...onSuggestionVisibilityCalculationTest.java | 11 +- .../support/uima/WebAnnoCasUtil.java | 158 ------------------ 8 files changed, 99 insertions(+), 181 deletions(-) diff --git a/inception/inception-brat-editor/src/test/java/de/tudarmstadt/ukp/clarin/webanno/brat/render/BratSerializerImplTest.java b/inception/inception-brat-editor/src/test/java/de/tudarmstadt/ukp/clarin/webanno/brat/render/BratSerializerImplTest.java index 17b42b19d05..94a860d4ec3 100644 --- a/inception/inception-brat-editor/src/test/java/de/tudarmstadt/ukp/clarin/webanno/brat/render/BratSerializerImplTest.java +++ b/inception/inception-brat-editor/src/test/java/de/tudarmstadt/ukp/clarin/webanno/brat/render/BratSerializerImplTest.java @@ -23,6 +23,8 @@ import static java.util.Arrays.asList; import static org.apache.uima.fit.factory.AnalysisEngineFactory.createEngine; import static org.apache.uima.fit.factory.CollectionReaderFactory.createReader; +import static org.apache.uima.fit.util.CasUtil.getType; +import static org.apache.uima.fit.util.CasUtil.select; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.contentOf; import static org.mockito.ArgumentMatchers.any; @@ -32,6 +34,7 @@ import org.apache.uima.analysis_engine.AnalysisEngine; import org.apache.uima.cas.CAS; +import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.collection.CollectionReader; import org.apache.uima.fit.factory.JCasFactory; import org.dkpro.core.io.tcf.TcfReader; @@ -59,6 +62,7 @@ import de.tudarmstadt.ukp.clarin.webanno.model.Project; import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument; import de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS; +import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token; import de.tudarmstadt.ukp.inception.annotation.feature.bool.BooleanFeatureSupport; import de.tudarmstadt.ukp.inception.annotation.feature.link.LinkFeatureSupport; @@ -76,7 +80,6 @@ import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService; import de.tudarmstadt.ukp.inception.schema.service.FeatureSupportRegistryImpl; import de.tudarmstadt.ukp.inception.support.json.JSONUtil; -import de.tudarmstadt.ukp.inception.support.uima.WebAnnoCasUtil; @ExtendWith(MockitoExtension.class) public class BratSerializerImplTest @@ -180,7 +183,7 @@ public void thatSentenceOrientedStrategyRenderCorrectly() throws Exception state.setAllAnnotationLayers(schemaService.listAnnotationLayer(project)); state.setPagingStrategy(new SentenceOrientedPagingStrategy()); state.getPreferences().setWindowSize(10); - state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(cas)); + state.setFirstVisibleUnit(getFirstSentence(cas)); state.setProject(project); state.setDocument(sourceDocument, asList(sourceDocument)); @@ -219,7 +222,7 @@ public void thatLineOrientedStrategyRenderCorrectly() throws Exception AnnotatorState state = new AnnotatorStateImpl(Mode.ANNOTATION); state.setPagingStrategy(new LineOrientedPagingStrategy()); state.getPreferences().setWindowSize(10); - state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(cas)); + state.setFirstVisibleUnit(getFirstSentence(cas)); state.setProject(project); state.setDocument(sourceDocument, asList(sourceDocument)); @@ -258,7 +261,7 @@ public void thatTokenWrappingStrategyRenderCorrectly() throws Exception AnnotatorState state = new AnnotatorStateImpl(Mode.ANNOTATION); state.setPagingStrategy(new TokenWrappingPagingStrategy(80)); state.getPreferences().setWindowSize(10); - state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(cas)); + state.setFirstVisibleUnit(getFirstSentence(cas)); state.setProject(project); state.setDocument(sourceDocument, asList(sourceDocument)); @@ -281,4 +284,22 @@ public void thatTokenWrappingStrategyRenderCorrectly() throws Exception assertThat(contentOf(new File("src/test/resources/longlines.json"), UTF_8)) .isEqualToNormalizingNewlines(contentOf(new File(jsonFilePath), UTF_8)); } + + /** + * Get the internal address of the first sentence annotation from CAS. This will be used as a + * reference for moving forward/backward sentences positions + * + * @param aCas + * The CAS object assumed to contains some sentence annotations + * @return the sentence number or -1 if aCas don't have sentence annotation + */ + private static AnnotationFS getFirstSentence(CAS aCas) + { + AnnotationFS firstSentence = null; + for (AnnotationFS s : select(aCas, getType(aCas, Sentence.class))) { + firstSentence = s; + break; + } + return firstSentence; + } } diff --git a/inception/inception-concept-linking/src/main/java/de/tudarmstadt/ukp/inception/conceptlinking/service/ConceptLinkingServiceImpl.java b/inception/inception-concept-linking/src/main/java/de/tudarmstadt/ukp/inception/conceptlinking/service/ConceptLinkingServiceImpl.java index b3dd2550e95..deb162aa965 100644 --- a/inception/inception-concept-linking/src/main/java/de/tudarmstadt/ukp/inception/conceptlinking/service/ConceptLinkingServiceImpl.java +++ b/inception/inception-concept-linking/src/main/java/de/tudarmstadt/ukp/inception/conceptlinking/service/ConceptLinkingServiceImpl.java @@ -24,13 +24,13 @@ import static de.tudarmstadt.ukp.inception.conceptlinking.model.CandidateEntity.KEY_QUERY; import static de.tudarmstadt.ukp.inception.conceptlinking.model.CandidateEntity.KEY_QUERY_BEST_MATCH_TERM_NC; import static de.tudarmstadt.ukp.inception.conceptlinking.model.CandidateEntity.KEY_QUERY_NC; -import static de.tudarmstadt.ukp.inception.support.uima.WebAnnoCasUtil.selectSentenceCovering; -import static de.tudarmstadt.ukp.inception.support.uima.WebAnnoCasUtil.selectTokensCovered; import static java.lang.System.currentTimeMillis; import static java.util.Arrays.asList; import static java.util.Collections.unmodifiableList; import static java.util.Comparator.comparingInt; import static java.util.stream.Collectors.toCollection; +import static org.apache.uima.fit.util.CasUtil.getType; +import static org.apache.uima.fit.util.CasUtil.select; import java.io.File; import java.net.URISyntaxException; @@ -47,6 +47,7 @@ import org.apache.commons.lang3.Validate; import org.apache.uima.cas.CAS; import org.apache.uima.cas.text.AnnotationFS; +import org.apache.uima.fit.util.CasUtil; import org.eclipse.rdf4j.common.net.ParsedIRI; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,6 +59,8 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator; import de.tudarmstadt.ukp.clarin.webanno.model.Project; +import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; +import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token; import de.tudarmstadt.ukp.inception.conceptlinking.config.EntityLinkingProperties; import de.tudarmstadt.ukp.inception.conceptlinking.config.EntityLinkingPropertiesImpl; import de.tudarmstadt.ukp.inception.conceptlinking.config.EntityLinkingServiceAutoConfiguration; @@ -513,4 +516,31 @@ public List searchItems(KnowledgeBase aKB, String aQuery) { return disambiguate(aKB, null, ConceptFeatureValueType.ANY_OBJECT, aQuery, null, 0, null); } + + /** + * Get the sentence based on the annotation begin offset + * + * @param aCas + * the CAS. + * @param aBegin + * the begin offset. + * @return the sentence. + */ + private static AnnotationFS selectSentenceCovering(CAS aCas, int aBegin) + { + AnnotationFS currentSentence = null; + for (AnnotationFS sentence : select(aCas, getType(aCas, Sentence.class))) { + if (sentence.getBegin() <= aBegin && sentence.getEnd() > aBegin) { + currentSentence = sentence; + break; + } + } + return currentSentence; + } + + private static Collection selectTokensCovered(AnnotationFS aCover) + { + return CasUtil.selectCovered(aCover.getCAS(), getType(aCover.getCAS(), Token.class), + aCover); + } } diff --git a/inception/inception-diag/src/main/java/de/tudarmstadt/ukp/clarin/webanno/diag/checks/UnreachableAnnotationsCheck.java b/inception/inception-diag/src/main/java/de/tudarmstadt/ukp/clarin/webanno/diag/checks/UnreachableAnnotationsCheck.java index b49a7d5c443..32a784a45b2 100644 --- a/inception/inception-diag/src/main/java/de/tudarmstadt/ukp/clarin/webanno/diag/checks/UnreachableAnnotationsCheck.java +++ b/inception/inception-diag/src/main/java/de/tudarmstadt/ukp/clarin/webanno/diag/checks/UnreachableAnnotationsCheck.java @@ -24,10 +24,13 @@ import static org.apache.uima.cas.impl.Serialization.deserializeCASComplete; import static org.apache.uima.cas.impl.Serialization.serializeCASComplete; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.uima.cas.CAS; +import org.apache.uima.cas.FeatureStructure; import org.apache.uima.cas.impl.CASImpl; import org.apache.uima.resource.ResourceInitializationException; @@ -93,8 +96,15 @@ public static CASImpl makeDummyCas() public static Map countFeatureStructures(CASImpl casImpl) { - return WebAnnoCasUtil.findAllFeatureStructures(casImpl).stream() // + return findAllFeatureStructures(casImpl).stream() // .map(fs -> fs.getType().getName()) // .collect(groupingBy(identity(), counting())); } + + public static Set findAllFeatureStructures(CAS aCas) + { + Set allFSes = new LinkedHashSet<>(); + ((CASImpl) aCas).walkReachablePlusFSsSorted(allFSes::add, null, null, null); + return allFSes; + } } diff --git a/inception/inception-pdf-editor/pom.xml b/inception/inception-pdf-editor/pom.xml index 6f9f1d554a1..58a25cd4b06 100644 --- a/inception/inception-pdf-editor/pom.xml +++ b/inception/inception-pdf-editor/pom.xml @@ -87,6 +87,10 @@ org.dkpro.core dkpro-core-io-pdf-asl + + org.dkpro.core + dkpro-core-api-segmentation-asl + org.dkpro.core dkpro-core-api-resources-asl @@ -168,11 +172,6 @@ dkpro-core-api-lexmorph-asl test - - org.dkpro.core - dkpro-core-api-segmentation-asl - test - de.tudarmstadt.ukp.inception.app inception-schema diff --git a/inception/inception-pdf-editor/src/main/java/de/tudarmstadt/ukp/inception/pdfeditor/PdfAnnotationEditor.java b/inception/inception-pdf-editor/src/main/java/de/tudarmstadt/ukp/inception/pdfeditor/PdfAnnotationEditor.java index 40e802df021..5be00169704 100644 --- a/inception/inception-pdf-editor/src/main/java/de/tudarmstadt/ukp/inception/pdfeditor/PdfAnnotationEditor.java +++ b/inception/inception-pdf-editor/src/main/java/de/tudarmstadt/ukp/inception/pdfeditor/PdfAnnotationEditor.java @@ -20,10 +20,10 @@ import static de.tudarmstadt.ukp.inception.pdfeditor.pdfanno.render.PdfAnnoSerializer.convertToDocumentOffset; import static de.tudarmstadt.ukp.inception.pdfeditor.pdfanno.render.PdfAnnoSerializer.convertToDocumentOffsets; import static de.tudarmstadt.ukp.inception.rendering.vmodel.VID.NONE_ID; -import static de.tudarmstadt.ukp.inception.support.uima.WebAnnoCasUtil.selectSentenceAt; import static de.tudarmstadt.ukp.inception.support.wicket.ServletContextUtils.referenceToUrl; import static java.lang.String.join; import static java.util.Arrays.asList; +import static org.apache.uima.fit.util.CasUtil.getType; import java.io.IOException; import java.util.ArrayList; @@ -37,6 +37,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.uima.cas.CAS; import org.apache.uima.cas.text.AnnotationFS; +import org.apache.uima.fit.util.CasUtil; import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.feedback.IFeedback; @@ -48,6 +49,7 @@ import org.slf4j.LoggerFactory; import de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasProvider; +import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; import de.tudarmstadt.ukp.inception.documents.api.DocumentService; import de.tudarmstadt.ukp.inception.editor.AnnotationEditorExtensionRegistry; import de.tudarmstadt.ukp.inception.editor.action.AnnotationActionHandler; @@ -314,4 +316,20 @@ private String getAnnotationsJS(PdfAnnoModel aPdfAnnoModel) "'colorMap': {},", // "'annotations':[annoFile]}, true);"); } + + /** + * Get the sentence for this CAS based on the begin and end offsets. This is basically used to + * transform sentence address in one CAS to other sentence address for different CAS + * + * @param aCas + * the CAS. + * @param aBegin + * the begin offset. + * @return the sentence. + */ + private static AnnotationFS selectSentenceAt(CAS aCas, int aBegin) + { + return CasUtil.select(aCas, getType(aCas, Sentence.class)).stream() + .filter(s -> s.getBegin() == aBegin).findFirst().orElse(null); + } } diff --git a/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/relation/RelationSuggestionSupport.java b/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/relation/RelationSuggestionSupport.java index 1bad84ab702..be12d8aa938 100644 --- a/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/relation/RelationSuggestionSupport.java +++ b/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/relation/RelationSuggestionSupport.java @@ -20,7 +20,6 @@ import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_OVERLAP; import static de.tudarmstadt.ukp.inception.support.WebAnnoConst.FEAT_REL_SOURCE; import static de.tudarmstadt.ukp.inception.support.WebAnnoConst.FEAT_REL_TARGET; -import static java.util.stream.Collectors.toList; import static org.apache.uima.cas.text.AnnotationPredicates.colocated; import static org.apache.uima.fit.util.CasUtil.select; import static org.apache.uima.fit.util.CasUtil.selectAt; @@ -243,8 +242,8 @@ public void calculateSuggestionVisibility(Strin // Collect all suggestions of the given layer var groupedSuggestions = aRecommendations.stream() .filter(group -> group.getLayerId() == aLayer.getId()) // - .map(group -> (SuggestionGroup) group) // - .collect(toList()); + .map(group -> (SuggestionGroup) group) // + .toList(); // Get previously rejected suggestions var groupedRecordedAnnotations = new ArrayListValuedHashMap(); @@ -267,7 +266,7 @@ public void calculateSuggestionVisibility(Strin return; } - for (SuggestionGroup group : groupedSuggestions) { + for (var group : groupedSuggestions) { if (!feature.getName().equals(group.getFeature())) { continue; } diff --git a/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/relation/RelationSuggestionVisibilityCalculationTest.java b/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/relation/RelationSuggestionVisibilityCalculationTest.java index 7738e321921..35e431c88b4 100644 --- a/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/relation/RelationSuggestionVisibilityCalculationTest.java +++ b/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/relation/RelationSuggestionVisibilityCalculationTest.java @@ -21,14 +21,13 @@ import static de.tudarmstadt.ukp.inception.recommendation.service.Fixtures.getVisibleSuggestions; import static de.tudarmstadt.ukp.inception.recommendation.service.Fixtures.makeRelationSuggestionGroup; import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; import static java.util.stream.Collectors.toList; import static org.apache.uima.cas.CAS.TYPE_NAME_STRING; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; -import java.util.ArrayList; - import org.apache.uima.cas.CAS; import org.apache.uima.fit.factory.JCasFactory; import org.junit.jupiter.api.BeforeEach; @@ -82,8 +81,8 @@ public void setUp() throws Exception @Test public void testCalculateVisibilityNoRecordsAllHidden() throws Exception { - doReturn(new ArrayList<>()).when(learningRecordService).listLearningRecords(TEST_USER, - TEST_USER, layer); + doReturn(emptyList()).when(learningRecordService).listLearningRecords(TEST_USER, TEST_USER, + layer); var cas = getTestCas(); var suggestions = makeRelationSuggestionGroup(doc, feature, @@ -105,8 +104,8 @@ public void testCalculateVisibilityNoRecordsAllHidden() throws Exception @Test public void thatVisibilityIsRestoredWhenOverlappingAnnotationIsRemoved() throws Exception { - doReturn(new ArrayList<>()).when(learningRecordService).listLearningRecords(TEST_USER, - TEST_USER, layer); + doReturn(emptyList()).when(learningRecordService).listLearningRecords(TEST_USER, TEST_USER, + layer); var cas = getTestCas(); var suggestions = makeRelationSuggestionGroup(doc, feature, diff --git a/inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/uima/WebAnnoCasUtil.java b/inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/uima/WebAnnoCasUtil.java index af21c693acd..8f00c7254d4 100644 --- a/inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/uima/WebAnnoCasUtil.java +++ b/inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/uima/WebAnnoCasUtil.java @@ -26,7 +26,6 @@ import static org.apache.uima.cas.impl.Serialization.serializeCASComplete; import static org.apache.uima.fit.util.CasUtil.getType; import static org.apache.uima.fit.util.CasUtil.select; -import static org.apache.uima.fit.util.CasUtil.selectAt; import static org.apache.uima.fit.util.CasUtil.selectCovering; import static org.apache.uima.fit.util.CasUtil.selectSingle; @@ -39,9 +38,7 @@ import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedHashSet; import java.util.List; -import java.util.Set; import java.util.stream.StreamSupport; import org.apache.commons.lang3.Validate; @@ -222,22 +219,6 @@ public static boolean isBeginEndInSameSentence(CAS aCas, int aBegin, int aEnd) .findFirst().isPresent(); } - /** - * Get the sentence for this CAS based on the begin and end offsets. This is basically used to - * transform sentence address in one CAS to other sentence address for different CAS - * - * @param aCas - * the CAS. - * @param aBegin - * the begin offset. - * @return the sentence. - */ - public static AnnotationFS selectSentenceAt(CAS aCas, int aBegin) - { - return CasUtil.select(aCas, getType(aCas, Sentence.class)).stream() - .filter(s -> s.getBegin() == aBegin).findFirst().orElse(null); - } - public static AnnotationFS createToken(CAS aCas, int aBegin, int aEnd) { return aCas.createAnnotation(getType(aCas, Token.class), aBegin, aEnd); @@ -288,90 +269,6 @@ public static List selectOverlapping(CAS aCas, Type aType, int aBe return annotations; } - /** - * Get the internal address of the first sentence annotation from CAS. This will be used as a - * reference for moving forward/backward sentences positions - * - * @param aCas - * The CAS object assumed to contains some sentence annotations - * @return the sentence number or -1 if aCas don't have sentence annotation - */ - public static AnnotationFS getFirstSentence(CAS aCas) - { - AnnotationFS firstSentence = null; - for (AnnotationFS s : select(aCas, getType(aCas, Sentence.class))) { - firstSentence = s; - break; - } - return firstSentence; - } - - /** - * Get the current sentence based on the annotation begin/end offset - * - * @param aCas - * the CAS. - * @param aBegin - * the begin offset. - * @param aEnd - * the end offset. - * @return the sentence. - */ - public static AnnotationFS getCurrentSentence(CAS aCas, int aBegin, int aEnd) - { - AnnotationFS currentSentence = null; - for (AnnotationFS sentence : selectSentences(aCas)) { - if (sentence.getBegin() <= aBegin && sentence.getEnd() > aBegin - && sentence.getEnd() <= aEnd) { - currentSentence = sentence; - break; - } - } - return currentSentence; - } - - /** - * Get the sentence based on the annotation begin offset - * - * @param aCas - * the CAS. - * @param aBegin - * the begin offset. - * @return the sentence. - */ - public static AnnotationFS selectSentenceCovering(CAS aCas, int aBegin) - { - AnnotationFS currentSentence = null; - for (AnnotationFS sentence : select(aCas, getType(aCas, Sentence.class))) { - if (sentence.getBegin() <= aBegin && sentence.getEnd() > aBegin) { - currentSentence = sentence; - break; - } - } - return currentSentence; - } - - public static AnnotationFS getNextToken(CAS aCas, int aBegin, int aEnd) - { - Type tokenType = getType(aCas, Token.class); - - AnnotationFS currentToken = selectAt(aCas, tokenType, aBegin, aEnd).stream().findFirst() - .orElse(null); - // this happens when tokens such as Dr. OR Ms. selected with double - // click, which make seletected text as Dr OR Ms - if (currentToken == null) { - currentToken = selectAt(aCas, tokenType, aBegin, aEnd + 1).stream().findFirst() - .orElse(null); - } - AnnotationFS nextToken = null; - - for (AnnotationFS token : CasUtil.selectFollowing(aCas, tokenType, currentToken, 1)) { - nextToken = token; - } - - return nextToken; - } - @SuppressWarnings("unchecked") public static T getNext(T aRef) { @@ -491,42 +388,6 @@ public static Collection selectTokens(CAS aCas) return CasUtil.select(aCas, getType(aCas, Token.class)); } - public static Collection selectTokensCovered(CAS aCas, int aBegin, int aEnd) - { - return CasUtil.selectCovered(aCas, getType(aCas, Token.class), aBegin, aEnd); - } - - public static Collection selectTokensCovered(AnnotationFS aCover) - { - return CasUtil.selectCovered(aCover.getCAS(), getType(aCover.getCAS(), Token.class), - aCover); - } - - /** - * For a span annotation, if a sub-token is selected, display the whole text so that the user is - * aware of what is being annotated, based on - * {@link WebAnnoCasUtil#selectOverlapping(CAS, Type, int, int)} ISSUE - Affected text not - * correctly displayed in annotation dialog (Bug #272) - * - * @param aCas - * the CAS. - * @param aBeginOffset - * the begin offset. - * @param aEndOffset - * the end offset. - * @return the selected text. - */ - public static String getSelectedText(CAS aCas, int aBeginOffset, int aEndOffset) - { - List tokens = selectOverlapping(aCas, getType(aCas, Token.class), - aBeginOffset, aEndOffset); - StringBuilder seletedTextSb = new StringBuilder(); - for (AnnotationFS token : tokens) { - seletedTextSb.append(token.getCoveredText()).append(" "); - } - return seletedTextSb.toString(); - } - public static boolean isNativeUimaType(String aType) { Validate.notNull(aType, "Type must not be null"); @@ -574,18 +435,6 @@ public static boolean isNativeUimaType(String aType) return false; } - public static boolean isPrimitiveFeature(FeatureStructure aFS, String aFeatureName) - { - Feature feature = aFS.getType().getFeatureByBaseName(aFeatureName); - - if (feature == null) { - throw new IllegalArgumentException("Type [" + aFS.getType().getName() - + "] has no feature called [" + aFeatureName + "]"); - } - - return isPrimitiveType(feature.getRange()); - } - public static boolean isPrimitiveType(Type aType) { switch (aType.getName()) { @@ -731,13 +580,6 @@ public static String getDocumentTitle(CAS aCas) } } - public static Set findAllFeatureStructures(CAS aCas) - { - Set allFSes = new LinkedHashSet<>(); - ((CASImpl) aCas).walkReachablePlusFSsSorted(allFSes::add, null, null, null); - return allFSes; - } - public static byte[] casToByteArray(CASCompleteSerializer aSer) throws IOException { try (var bos = new ByteArrayOutputStream()) {