org.apache.uima.cas.CAS Java Examples

The following examples show how to use org.apache.uima.cas.CAS. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CurationTestUtils.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static CAS readWebAnnoTSV(String aPath, TypeSystemDescription aType)
    throws UIMAException, IOException
{
    CollectionReader reader = createReader(WebannoTsv2Reader.class,
            WebannoTsv2Reader.PARAM_SOURCE_LOCATION, "src/test/resources/" + aPath);
    CAS cas;
    if (aType != null) {
        TypeSystemDescription builtInTypes = TypeSystemDescriptionFactory
                .createTypeSystemDescription();
        List<TypeSystemDescription> allTypes = new ArrayList<>();
        allTypes.add(builtInTypes);
        allTypes.add(aType);
        cas = JCasFactory.createJCas(CasCreationUtils.mergeTypeSystems(allTypes)).getCas();
    }
    else {
        cas = JCasFactory.createJCas().getCas();
    }

    reader.getNext(cas);

    return cas;
}
 
Example #2
Source File: DocumentMetadataAnnotationDetailPanel.java    From inception with Apache License 2.0 6 votes vote down vote up
private void actionAnnotate(AjaxRequestTarget aTarget)
{
    try {
        // When updating an annotation in the sidebar, we must not force a
        // re-focus after rendering
        getRequestCycle().setMetaData(IsSidebarAction.INSTANCE, true);
        
        // Load the boiler-plate
        CAS cas = jcasProvider.get();
        FeatureStructure fs = selectFsByAddr(cas, getModelObject().getId());
        AnnotationLayer layer = annotationService.findLayer(project.getObject(), fs);
        TypeAdapter adapter = annotationService.getAdapter(layer);

        // Update the features of the selected annotation from the values presently in
        // the feature editors
        writeFeatureEditorModelsToCas(adapter, cas);
        
        // persist changes
        annotationPage.writeEditorCas(cas);
    }
    catch (Exception e) {
        handleException(DocumentMetadataAnnotationDetailPanel.this, aTarget, e);
    }
}
 
Example #3
Source File: AgreementTestUtils.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem(String... aFeatures)
    throws Exception
{
    List<TypeSystemDescription> typeSystems = new ArrayList<>();

    TypeSystemDescription tsd = new TypeSystemDescription_impl();

    // Link type
    TypeDescription linkTD = tsd.addType(LINK_TYPE, "", CAS.TYPE_NAME_TOP);
    linkTD.addFeature("role", "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature("target", "", Token.class.getName());

    // Link host
    TypeDescription hostTD = tsd.addType(HOST_TYPE, "", CAS.TYPE_NAME_ANNOTATION);
    hostTD.addFeature("links", "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);
    for (String feature : aFeatures) {
        hostTD.addFeature(feature, "", CAS.TYPE_NAME_STRING);
    }

    typeSystems.add(tsd);
    typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());

    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
 
Example #4
Source File: NewPrimitiveTypesTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
private void reinitTypeSystem(TypeSystemImpl tsa) {
  annotationType = tsa.getType(CAS.TYPE_NAME_ANNOTATION);

  // new primitive types
  exampleType = tsa.refreshType(exampleType);

  floatFeature = tsa.refreshFeature(floatFeature);
  stringFeature = tsa.refreshFeature(stringFeature);
  booleanFeature = tsa.refreshFeature(booleanFeature);
  byteFeature = tsa.refreshFeature(byteFeature);
  shortFeature = tsa.refreshFeature(shortFeature);
  longFeature = tsa.refreshFeature(longFeature);
  doubleFeature = tsa.refreshFeature(doubleFeature);

  intArrayFeature = tsa.refreshFeature(intArrayFeature);
  floatArrayFeature = tsa.refreshFeature(floatArrayFeature);
  stringArrayFeature = tsa.refreshFeature(stringArrayFeature);
  booleanArrayFeature = tsa.refreshFeature(booleanArrayFeature);
  byteArrayFeature = tsa.refreshFeature(byteArrayFeature);
  shortArrayFeature = tsa.refreshFeature(shortArrayFeature);
  longArrayFeature = tsa.refreshFeature(longArrayFeature);
  doubleArrayFeature = tsa.refreshFeature(doubleArrayFeature);
}
 
Example #5
Source File: CasStorageSession.java    From webanno with Apache License 2.0 6 votes vote down vote up
/**
 * Register the given CAS for a special purpose into the session.
 * 
 * @param aSpecialPurpose
 *            the unique purpose identifier - unique with respect to the current session.
 * @param aMode
 *            the access mode.
 * @param aCas
 *            the CAS itself.
 * @return the managed CAS state.
 */
public SessionManagedCas add(String aSpecialPurpose, CasAccessMode aMode, CAS aCas)
{
    Validate.notNull(aSpecialPurpose, "The purpose cannot be null");
    Validate.notNull(aMode, "The access mode cannot be null");
    Validate.notNull(aCas, "The CAS cannot be null");

    SessionManagedCas managedCas = new SessionManagedCas(SPECIAL_PURPOSE, aSpecialPurpose,
            aMode, aCas);

    Map<String, SessionManagedCas> casByUser = managedCases
            .computeIfAbsent(SPECIAL_PURPOSE, key -> new LinkedHashMap<>());
    casByUser.put(aSpecialPurpose, managedCas);
    
    LOGGER.trace("CAS storage session [{}]: added {}", hashCode(), managedCas);
    
    return managedCas;
}
 
Example #6
Source File: CurationPage.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Override
public CAS getEditorCas()
    throws IOException
{
    AnnotatorState state = CurationPage.this.getModelObject();
    
    if (state.getDocument() == null) {
        throw new IllegalStateException("Please open a document first!");
    }

    // If we have a timestamp, then use it to detect if there was a concurrent access
    verifyAndUpdateDocumentTimestamp(state, curationDocumentService
            .getCurationCasTimestamp(state.getDocument()));

    return curationDocumentService.readCurationCas(state.getDocument());
}
 
Example #7
Source File: CasDiffTest.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
public void singleEmptyCasTest()
    throws Exception
{
    String text = "";
    
    CAS user1Cas = JCasFactory.createJCas().getCas();
    user1Cas.setDocumentText(text);
    
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(user1Cas));

    List<SpanDiffAdapter> diffAdapters = asList(new SpanDiffAdapter(Token.class.getName()));

    DiffResult result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
    
    // result.print(System.out);
    
    assertEquals(0, result.size());
    assertEquals(0, result.getDifferingConfigurationSets().size());
}
 
Example #8
Source File: BratAnnotationEditor.java    From webanno with Apache License 2.0 6 votes vote down vote up
private String actionGetDocument(CAS aCas)
{
    StopWatch timer = new StopWatch();
    timer.start();
    
    GetDocumentResponse response = new GetDocumentResponse();
    String json;
    if (getModelObject().getProject() != null) {
        render(response, aCas);
        json = toJson(response);
        lastRenderedJson = json;
    }
    else {
        json = toJson(response);
    }
    
    timer.stop();
    metrics.renderComplete(RenderType.FULL, timer.getTime(), json, null);
    
    return json;
}
 
Example #9
Source File: SerializationNoMDTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * @see junit.framework.TestCase#setUp()
 */
public void setUp() throws Exception {
  super.setUp();
  casMgr = initCAS();
  cas = (CASImpl)casMgr;

  TypeSystem ts = cas.getTypeSystem();
  wordType = ts.getType(WORD_TYPE);
  // assert(wordType != null);
  separatorType = ts.getType(SEP_TYPE);
  eosType = ts.getType(EOS_TYPE);
  tokenType = ts.getType(TOKEN_TYPE);
  tokenTypeFeature = ts.getFeatureByFullName(TOKEN_TYPE_FEAT_Q);
  startFeature = ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_BEGIN);
  endFeature = ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_END);
  sentenceType = ts.getType(SENT_TYPE);
}
 
Example #10
Source File: LegacyProjectInitializer.java    From webanno with Apache License 2.0 6 votes vote down vote up
private void createChunkLayer(Project aProject)
    throws IOException
{
    AnnotationLayer chunkLayer = new AnnotationLayer(Chunk.class.getName(), "Chunk", SPAN_TYPE,
            aProject, true, TOKENS, NO_OVERLAP);
    annotationSchemaService.createLayer(chunkLayer);

    AnnotationFeature chunkValueFeature = new AnnotationFeature();
    chunkValueFeature.setDescription("Chunk tag");
    chunkValueFeature.setName("chunkValue");
    chunkValueFeature.setType(CAS.TYPE_NAME_STRING);
    chunkValueFeature.setProject(aProject);
    chunkValueFeature.setUiName("Tag");
    chunkValueFeature.setLayer(chunkLayer);
    annotationSchemaService.createFeature(chunkValueFeature);
}
 
Example #11
Source File: OpenNlpPosRecommenderTest.java    From inception with Apache License 2.0 6 votes vote down vote up
@Test
public void thatIncrementalPosEvaluationWorks() throws Exception
{
    IncrementalSplitter splitStrategy = new IncrementalSplitter(0.8, 250, 10);
    OpenNlpPosRecommender sut = new OpenNlpPosRecommender(recommender, traits);
    List<CAS> casList = loadAllData();

    int i = 0;
    while (splitStrategy.hasNext() && i < 3) {
        splitStrategy.next();
        
        double score = sut.evaluate(casList, splitStrategy).computeF1Score();

        assertThat(score).isStrictlyBetween(0.0, 1.0);
        
        i++;
    }
}
 
Example #12
Source File: BratRenderer.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static void renderTokens(CAS aCas, GetDocumentResponse aResponse, AnnotatorState aState)
{
    int winBegin = aState.getWindowBeginOffset();
    int winEnd = aState.getWindowEndOffset();
    Type tokenType = CasUtil.getType(aCas, Token.class);

    List<AnnotationFS> tokens = selectCovered(aCas, tokenType, winBegin, winEnd);
    for (AnnotationFS fs : tokens) {
        // attach type such as POS adds non-existing token element for ellipsis annotation
        if (fs.getBegin() == fs.getEnd()) {
            continue;
        }
        
        split(aResponse.getSentenceOffsets(), fs.getCoveredText(), fs.getBegin() - winBegin,
                fs.getEnd() - winBegin)                    
                .forEach(range -> {
                    aResponse.addToken(range.getBegin(), range.getEnd());
                    if (DEBUG) {
                        aResponse.addEntity(new Entity(new VID(fs), "Token",
                                new Offsets(range.getBegin(), range.getEnd()),
                                fs.getCoveredText(), "#d9d9d9",
                                "[" + fs.getBegin() + "-" + fs.getEnd() + "]"));
                    }
                });
    }
}
 
Example #13
Source File: XmiCasDeserializerTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testOutOfTypeSystemDataComplexCas() throws Exception {
   // deserialize a complex XCAS
   CAS originalCas = CasCreationUtils.createCas(typeSystem, null, indexes);
   InputStream serCasStream = new FileInputStream(JUnitExtension.getFile("ExampleCas/cas.xml"));
   XCASDeserializer.deserialize(serCasStream, originalCas);
   serCasStream.close();
   
   //serialize to XMI
   String xmiStr = serialize(originalCas, null);
   
   //deserialize into a CAS with no type system
   CAS casWithNoTs = CasCreationUtils.createCas(new TypeSystemDescription_impl(),
           new TypePriorities_impl(), new FsIndexDescription[0]);
   XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
   deserialize(xmiStr, casWithNoTs, sharedData, true, -1);
       
   // now reserialize including OutOfTypeSystem data
   String xmiStr2 = serialize(casWithNoTs, sharedData);
   
   //deserialize into a new CAS that has the full type system
   CAS newCas = CasCreationUtils.createCas(typeSystem, null, indexes);
   deserialize(xmiStr2, newCas, null, false, -1);
   
   //compare
   CasComparer.assertEquals(originalCas, newCas);
   
   //Test a partial type system with a missing some missing features and
   //missing "Organization" type
   File partialTypeSystemFile = JUnitExtension.getFile("ExampleCas/partialTestTypeSystem.xml");
   TypeSystemDescription partialTypeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
           new XMLInputSource(partialTypeSystemFile));
   CAS partialTsCas = CasCreationUtils.createCas(partialTypeSystem, null, indexes);
   XmiSerializationSharedData sharedData2 = new XmiSerializationSharedData();
   deserialize(xmiStr, partialTsCas, sharedData2, true, -1);
       
   String xmiStr3 = serialize(partialTsCas, sharedData2);
   newCas.reset();
   deserialize(xmiStr3, newCas, null, false, -1);
   CasComparer.assertEquals(originalCas, newCas);    
}
 
Example #14
Source File: OpenNlpNerRecommenderFactory.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accepts(AnnotationLayer aLayer, AnnotationFeature aFeature)
{
    if (aLayer == null || aFeature == null) {
        return false;
    }
    
    return (asList(SINGLE_TOKEN, TOKENS).contains(aLayer.getAnchoringMode()))
            && !aLayer.isCrossSentence() && SPAN_TYPE.equals(aLayer.getType())
            && (CAS.TYPE_NAME_STRING.equals(aFeature.getType()) || aFeature.isVirtualFeature());
}
 
Example #15
Source File: TestCasMultiplier.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public boolean hasNext() throws AnalysisEngineProcessException {
  CAS outputCas = getEmptyCAS();
  try {
    Assert.assertTrue(((TypeSystemImpl)mInputCAS.getTypeSystem()).getLargestTypeCode() ==
      ((TypeSystemImpl)outputCas.getTypeSystem()).getLargestTypeCode());
    Assert.assertTrue(mInputCAS.getTypeSystem() == outputCas.getTypeSystem());
  }
  finally {
    outputCas.release();
  }
  return false;
}
 
Example #16
Source File: ChainAdapter.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public List<Pair<LogMessage, AnnotationFS>> validate(CAS aCas)
{
    List<Pair<LogMessage, AnnotationFS>> messages = new ArrayList<>();
    for (SpanLayerBehavior behavior : behaviors) {
        long startTime = currentTimeMillis();
        messages.addAll(behavior.onValidate(this, aCas));
        log.trace("Validation for [{}] on [{}] took {}ms", behavior.getClass().getSimpleName(),
                getLayer().getUiName(), currentTimeMillis() - startTime);
    }
    return messages;
}
 
Example #17
Source File: CasMergeTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
private AnnotationFS createNEAnno(CAS aCas, String aValue, int aBegin, int aEnd)
{
    Type type = aCas.getTypeSystem().getType(NamedEntity.class.getTypeName());
    AnnotationFS clickedFs = aCas.createAnnotation(type, aBegin, aEnd);
    Feature value = type.getFeatureByBaseName("value");
    clickedFs.setStringValue(value, aValue);
    aCas.addFsToIndexes(clickedFs);
    return clickedFs;
}
 
Example #18
Source File: AllAnnotationsIndexedCheckTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void testOK()
    throws Exception
{
    TypeSystemDescription tsd = UIMAFramework.getResourceSpecifierFactory()
            .createTypeSystemDescription();
    
    String refTypeName = "RefType";
    
    TypeDescription refTypeDesc = tsd.addType(refTypeName, null, CAS.TYPE_NAME_ANNOTATION);
    refTypeDesc.addFeature("ref", null, CAS.TYPE_NAME_ANNOTATION);
    
    CAS cas = CasCreationUtils.createCas(tsd, null, null);
    
    Type refType = cas.getTypeSystem().getType(refTypeName);
    
    // A regular index annotation
    AnnotationFS anno1 = cas.createAnnotation(cas.getAnnotationType(), 0, 1);
    cas.addFsToIndexes(anno1);

    // An indexed annotation but reachable through an indexe one (below)
    AnnotationFS anno2 = cas.createAnnotation(cas.getAnnotationType(), 0, 1);
    cas.addFsToIndexes(anno2);

    // An indexed annotation that references the non-indexed annotation above
    AnnotationFS anno3 = cas.createAnnotation(refType, 0, 1);
    anno3.setFeatureValue(refType.getFeatureByBaseName("ref"), anno2);
    cas.addFsToIndexes(anno3);
    
    List<LogMessage> messages = new ArrayList<>();
    CasDoctor cd = new CasDoctor(AllFeatureStructuresIndexedCheck.class);
    // A project is not required for this check
    boolean result = cd.analyze(null, cas, messages);
    
    messages.forEach(System.out::println);
    
    assertTrue(result);
}
 
Example #19
Source File: CurationTestUtils.java    From webanno with Apache License 2.0 5 votes vote down vote up
public static Map<String, List<CAS>> loadWebAnnoTSV(TypeSystemDescription aTypes,
        String... aPaths)
    throws UIMAException, IOException
{
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    int n = 1;
    for (String path : aPaths) {
        CAS cas = readWebAnnoTSV(path, aTypes);
        casByUser.put("user" + n, asList(cas));
        n++;
    }
    return casByUser;
}
 
Example #20
Source File: DocumentServiceImpl.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public CAS createOrReadInitialCas(SourceDocument aDocument, CasUpgradeMode aUpgradeMode,
        CasAccessMode aAccessMode)
    throws IOException
{
    return createOrReadInitialCas(aDocument, aUpgradeMode, aAccessMode, null);
}
 
Example #21
Source File: Annotator1.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
  try {
    JCas parentheticalView = ViewCreatorAnnotator.createViewSafely(jCas,
            ViewNames.PARENTHESES_VIEW);
    jCas = jCas.getView(CAS.NAME_DEFAULT_SOFA);
    String initialText = jCas.getDocumentText();
    String parentheticalText = initialText.replaceAll("[aeiou]+", "($0)");
    parentheticalView.setDocumentText(parentheticalText);
  } catch (CASException e) {
    throw new AnalysisEngineProcessException(e);
  }

}
 
Example #22
Source File: UimaTokenizer.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
public UimaTokenizer(String tokens, UimaResource resource, boolean checkForLabel) {

        this.checkForLabel = checkForLabel;
        this.tokens = new ArrayList<>();
        try {
            CAS cas = resource.process(tokens);

            Collection<Token> tokenList = JCasUtil.select(cas.getJCas(), Token.class);

            for (Token t : tokenList) {

                if (!checkForLabel || valid(t.getCoveredText()))
                    if (t.getLemma() != null)
                        this.tokens.add(t.getLemma());
                    else if (t.getStem() != null)
                        this.tokens.add(t.getStem());
                    else
                        this.tokens.add(t.getCoveredText());
            }


            resource.release(cas);


        } catch (Exception e) {
            log.error("",e);
            throw new RuntimeException(e);
        }

    }
 
Example #23
Source File: CasMetadataUtils.java    From webanno with Apache License 2.0 5 votes vote down vote up
public static Optional<String> getSourceDocumentName(CAS aCas)
{
    try {
        FeatureStructure fs = CasUtil.selectSingle(aCas, getType(aCas, CASMetadata.class));
        return Optional.ofNullable(FSUtil.getFeature(fs, "sourceDocumentName", String.class));
    }
    catch (IllegalArgumentException e) {
        return Optional.empty();
    }
}
 
Example #24
Source File: CasPersistenceUtils.java    From webanno with Apache License 2.0 5 votes vote down vote up
public static void writeSerializedCas(CAS aCas, File aFile)
    throws IOException
{
    FileUtils.forceMkdir(aFile.getParentFile());

    try (ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(aFile))) {
        CASCompleteSerializer serializer = serializeCASComplete((CASImpl) aCas);
        os.writeObject(serializer);
    }
}
 
Example #25
Source File: CasMerge.java    From webanno with Apache License 2.0 5 votes vote down vote up
private static List<AnnotationFS> getCandidateAnnotations(CAS aTargetCas, AnnotationFS aSource)
{
    return selectCovered(aTargetCas, aSource.getType(), aSource.getBegin(), aSource.getEnd())
            .stream()
            .filter(fs -> isEquivalentAnnotation(fs, aSource))
            .collect(Collectors.toList());
}
 
Example #26
Source File: DiffTestUtils.java    From webanno with Apache License 2.0 5 votes vote down vote up
public static Map<String, List<CAS>> load(String... aPaths)
    throws UIMAException, IOException
{
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    int n = 1;
    for (String path : aPaths) {
        CAS cas = read(path);
        casByUser.put("user" + n, asList(cas));
        n++;
    }
    return casByUser;
}
 
Example #27
Source File: XmiCollectionReader.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.apache.uima.collection.CollectionReader#getNext(org.apache.uima.cas.CAS)
 */
public void getNext(CAS aCAS) throws IOException, CollectionException {
  File currentFile = (File) mFiles.get(mCurrentIndex++);
  try (InputStream inputStream = new FileInputStream(currentFile)) {
    XmiCasDeserializer.deserialize(inputStream, aCAS, !mFailOnUnknownType);
  } catch (SAXException e) {
    throw new CollectionException(e);
  }
}
 
Example #28
Source File: IndexRepositoryTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * To test non-normal case, change Eclipse run config by adding the jvm arg:
 *   -Duima.allow_duplicate_add_to_indexes
 * @throws CASException
 */
public void testDupFsIndex() throws CASException {
  cas.setSofaDataString("something", "text"); // otherwise triggers failure in addFsToIndex - no sofa ref
  JCas jcas = cas.getJCas();
  Annotation a = new Annotation(jcas, 0, 4);
  cas.addFsToIndexes(a);
  cas.addFsToIndexes(a);
  cas.addFsToIndexes(a);
  int expected = /*FSIndexRepositoryImpl.IS_ALLOW_DUP_ADD_2_INDEXES ? 4 :*/ 2;
  assertEquals(expected, cas.getIndexRepository().getIndex(CASTestSetup.ANNOT_SORT_INDEX).size());
  assertEquals(expected, cas.getIndexRepository().getIndex(CASTestSetup.ANNOT_BAG_INDEX).size());
  assertEquals(expected, cas.getIndexRepository().getIndex(CAS.STD_ANNOTATION_INDEX).size());
}
 
Example #29
Source File: CasIOUtilsTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private static void assertCorrectlyLoaded(CAS cas, boolean leniently) throws Exception {
    // Check if all the annotations are there (mind the file contains FSes that are NOT annotations!)
    Assert.assertEquals(
            leniently ? SIMPLE_CAS_DEFAULT_INDEX_SIZE_LENIENT : SIMPLE_CAS_DEFAULT_INDEX_SIZE,
            cas.getAnnotationIndex().size());
    
    // Count ALL FSes now, including the ones that are not annotations!
    List<String> expectedTypes = new ArrayList<>(asList(
            "org.apache.uima.testTypeSystem.Entity", 
            "org.apache.uima.testTypeSystem.Organization", 
            "org.apache.uima.testTypeSystem.Owner", 
            "org.apache.uima.testTypeSystem.Person", 
            "uima.tcas.DocumentAnnotation"));
    
    if (leniently) {
      // This type was renamed to "org.apache.uima.testTypeSystem.OwnerRenamed"
      expectedTypes.remove("org.apache.uima.testTypeSystem.Owner");
    }
    
    List<String> fsTypes = new ArrayList<>();
//    FSIterator<FeatureStructure> fsi = cas.getIndexRepository()
//            .getAllIndexedFS(cas.getTypeSystem().getTopType());
    Collection<TOP> s = cas.getIndexedFSs();
    Iterator<TOP> fsi = s.iterator();
    int fsCount = 0;
    while (fsi.hasNext()) {
      TOP fs = (TOP) fsi.next();
      String typeName = fs.getType().getName();
      if (!fsTypes.contains(typeName)) {
        fsTypes.add(typeName);
      }
      fsCount++;
    }
    Collections.sort(fsTypes);
    
    Assert.assertEquals(
            leniently ? SIMPLE_CAS_ALL_INDEXED_SIZE_LENIENT : SIMPLE_CAS_ALL_INDEXED_SIZE, fsCount);
    
    Assert.assertEquals(expectedTypes, fsTypes);
  }
 
Example #30
Source File: AnnotationEditor.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves annotation editor adapters.
 *
 * @param adapter the adapter
 * @return an adapter or null
 */
@Override
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {

  if (IContentOutlinePage.class.equals(adapter) && getDocument() != null) {
    return mOutlinePage;
  }
  else if (CAS.class.equals(adapter) && getDocument() != null) {
    return getDocument().getCAS();
  }
  else {
    return super.getAdapter(adapter);
  }

}