Java Code Examples for org.apache.uima.util.CasCreationUtils

The following examples show how to use org.apache.uima.util.CasCreationUtils. These examples are extracted from open source projects. 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 Project: webanno   Source File: WebAnnoTsv3WriterTestBase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoSentencesWithNoSpaceInBetween() throws Exception
{
    TypeSystemDescription global = TypeSystemDescriptionFactory.createTypeSystemDescription();
    TypeSystemDescription local = TypeSystemDescriptionFactory
            .createTypeSystemDescriptionFromPath(
                    "src/test/resources/desc/type/webannoTestTypes.xml");
   
    TypeSystemDescription merged = CasCreationUtils.mergeTypeSystems(asList(global, local));
    
    JCas jcas = JCasFactory.createJCas(merged);
    
    DocumentMetaData.create(jcas).setDocumentId("doc");
    jcas.setDocumentText("onetwo");
    new Token(jcas, 0, 3).addToIndexes();
    new Sentence(jcas, 0, 3).addToIndexes();
    new Token(jcas, 3, 6).addToIndexes();
    new Sentence(jcas, 3, 6).addToIndexes();
    
    writeAndAssertEquals(jcas);
}
 
Example 2
Source Project: webanno   Source File: ConstraintsGeneratorTest.java    License: Apache License 2.0 6 votes vote down vote up
private JCas makeJCasOneSentence() throws UIMAException
{
    TypeSystemDescription global = TypeSystemDescriptionFactory.createTypeSystemDescription();
    TypeSystemDescription local = TypeSystemDescriptionFactory
            .createTypeSystemDescriptionFromPath(
                    "src/test/resources/desc/types/webannoTestTypes.xml");
   
    TypeSystemDescription merged = CasCreationUtils.mergeTypeSystems(asList(global, local));
    
    JCas jcas = JCasFactory.createJCas(merged);
    
    DocumentMetaData.create(jcas).setDocumentId("doc");
    
    TokenBuilder<Token, Sentence> tb = new TokenBuilder<>(Token.class,
            Sentence.class);
    tb.buildTokens(jcas, "This is a test .");
    
    return jcas;
}
 
Example 3
Source Project: uima-uimaj   Source File: XCASDeserializerTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testStringArrayWithNullValues() throws Exception {
  CAS cas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes);
  StringArrayFS strArray = cas.createStringArrayFS(3);
  strArray.set(1, "value");
  cas.getIndexRepository().addFS(strArray);
  
  assertEquals(null, strArray.get(0));
  assertEquals("value", strArray.get(1));
  assertEquals(null, strArray.get(2));
  
  //serialize to XCAS and back
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  XCASSerializer.serialize(cas,baos);
  ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
  XCASDeserializer.deserialize(bais, cas);

  //check
  Iterator iter = cas.getIndexRepository().getAllIndexedFS(cas.getTypeSystem().getType("uima.cas.StringArray"));
  StringArrayFS strArrayOut = (StringArrayFS)iter.next();
  assertEquals(null, strArrayOut.get(0));
  assertEquals("value", strArrayOut.get(1));
  assertEquals(null, strArrayOut.get(2));
}
 
Example 4
Source Project: webanno   Source File: CurationTestUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static CAS readXMI(String aPath, TypeSystemDescription aType)
    throws UIMAException, IOException
{
    CollectionReader reader = createReader(XmiReader.class, XmiReader.PARAM_SOURCE_LOCATION,
            "src/test/resources/" + aPath);
    CAS jcas;
    if (aType != null) {
        TypeSystemDescription builtInTypes = TypeSystemDescriptionFactory
                .createTypeSystemDescription();
        List<TypeSystemDescription> allTypes = new ArrayList<>();
        allTypes.add(builtInTypes);
        allTypes.add(aType);
        jcas = JCasFactory.createJCas(CasCreationUtils.mergeTypeSystems(allTypes)).getCas();
    }
    else {
        jcas = JCasFactory.createJCas().getCas();
    }

    reader.getNext(jcas);

    return jcas;
}
 
Example 5
Source Project: webanno   Source File: CurationTestUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSystem(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", "", CAS.TYPE_NAME_ANNOTATION);

    // 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 6
Source Project: webanno   Source File: DiffTestUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static JCas readWebAnnoTSV(String aPath, TypeSystemDescription aType)
    throws UIMAException, IOException
{
    CollectionReader reader = createReader(WebannoTsv2Reader.class,
            WebannoTsv2Reader.PARAM_SOURCE_LOCATION, "src/test/resources/" + aPath);
    JCas jcas;
    if (aType != null) {
        TypeSystemDescription builtInTypes = TypeSystemDescriptionFactory
                .createTypeSystemDescription();
        List<TypeSystemDescription> allTypes = new ArrayList<>();
        allTypes.add(builtInTypes);
        allTypes.add(aType);
        jcas = JCasFactory.createJCas(CasCreationUtils.mergeTypeSystems(allTypes));
    }
    else {
        jcas = JCasFactory.createJCas();
    }

    reader.getNext(jcas.getCas());

    return jcas;
}
 
Example 7
Source Project: uima-uimaj   Source File: JsonCasSerializerTest.java    License: Apache License 2.0 6 votes vote down vote up
private void setupTypeSystem(String tsdName) throws InvalidXMLException, IOException, ResourceInitializationException, CASException {
    File tsdFile = JUnitExtension.getFile("CasSerialization/desc/" + tsdName);
    tsd = parser.parseTypeSystemDescription(new XMLInputSource(tsdFile));
    cas = (CASImpl) CasCreationUtils.createCas(tsd, null, null);
//    cas.getSofaRef();  // creates the default sofa
    jcas = cas.getJCas();
    tsi = cas.getTypeSystemImpl();
    topType = (TypeImpl) tsi.getTopType();
    annotationType = (TypeImpl) tsi.getType("uima.tcas.Annotation"); 
    allTypesType = (TypeImpl) tsi.getType("org.apache.uima.test.AllTypes");
    tokenType = (TypeImpl) tsi.getType("org.apache.uima.test.Token");
    emptyIntListType = (TypeImpl) tsi.getType("uima.cas.EmptyIntegerList");
//    nonEmptyIntListType = (TypeImpl) tsi.getType("uima.cas.NonEmptyIntegerList");
//    emptyFSListType = (TypeImpl) tsi.getType("uima.cas.EmptyFSList");
//    nonEmptyFSListType = (TypeImpl) tsi.getType("uima.cas.NonEmptyFSList");
    
  }
 
Example 8
Source Project: webanno   Source File: DiffTestUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem()
    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);

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

    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
 
Example 9
Source Project: webanno   Source File: AgreementTestUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static JCas readWebAnnoTSV(String aPath, TypeSystemDescription aType)
    throws UIMAException, IOException
{
    CollectionReader reader = createReader(WebannoTsv2Reader.class,
            WebannoTsv2Reader.PARAM_SOURCE_LOCATION, "src/test/resources/" + aPath);
    JCas jcas;
    if (aType != null) {
        TypeSystemDescription builtInTypes = TypeSystemDescriptionFactory
                .createTypeSystemDescription();
        List<TypeSystemDescription> allTypes = new ArrayList<>();
        allTypes.add(builtInTypes);
        allTypes.add(aType);
        jcas = JCasFactory.createJCas(CasCreationUtils.mergeTypeSystems(allTypes));
    }
    else {
        jcas = JCasFactory.createJCas();
    }

    reader.getNext(jcas.getCas());

    return jcas;
}
 
Example 10
Source Project: webanno   Source File: AgreementTestUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static JCas readXMI(String aPath, TypeSystemDescription aType)
    throws UIMAException, IOException
{
    CollectionReader reader = createReader(XmiReader.class, XmiReader.PARAM_SOURCE_LOCATION,
            "src/test/resources/" + aPath);
    JCas jcas;
    if (aType != null) {
        TypeSystemDescription builtInTypes = TypeSystemDescriptionFactory
                .createTypeSystemDescription();
        List<TypeSystemDescription> allTypes = new ArrayList<>();
        allTypes.add(builtInTypes);
        allTypes.add(aType);
        jcas = JCasFactory.createJCas(CasCreationUtils.mergeTypeSystems(allTypes));
    }
    else {
        jcas = JCasFactory.createJCas();
    }

    reader.getNext(jcas.getCas());

    return jcas;
}
 
Example 11
Source Project: webanno   Source File: AgreementTestUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem()
    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);

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

    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
 
Example 12
Source Project: webanno   Source File: AgreementTestUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSystem(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", "", CAS.TYPE_NAME_ANNOTATION);

    // 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 13
Source Project: bluima   Source File: PubmedCentralCollectionReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
   @Ignore
   // FIXME
   public void testCount() throws Exception {

CollectionReader cr = PubmedCentralCollectionReader.getCR("pmc_test_archive");

int i = 0;
while (cr.hasNext()) {
    CAS cas = CasCreationUtils.createCas(cr
	    .getProcessingResourceMetaData());
    cr.getNext(cas);
    i++;
}
cr.close();
assertEquals(6, i);
   }
 
Example 14
Source Project: bluima   Source File: BioNLPGeniaEventsReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCount() throws Exception {

    CollectionReader cr = CollectionReaderFactory.createReader(
            BioNLPGeniaEventsCollectionReader.class,
            BlueUima.PARAM_INPUT_DIRECTORY, TEST_DIR);

    int i = 0;
    while (cr.hasNext()) {
        CAS cas = CasCreationUtils.createCas(cr
                .getProcessingResourceMetaData());
        cr.getNext(cas);
        LOG.debug(To.string("cas nr " + i, cas.getJCas()));
        i++;
    }
    cr.close();
    assertEquals(3, i);
}
 
Example 15
@Test
   public void test() throws Exception {

CollectionReader cr = CollectionReaderFactory.createReader(
	BioNLPGeniaEventsCollectionReader.class);

int i = 0;
while (cr.hasNext()) {
    CAS cas = CasCreationUtils.createCas(cr
	    .getProcessingResourceMetaData());
    cr.getNext(cas);

    // if (createHtml)
    // viewer.createHtml(cas.getJCas(), cas.getTypeSystem(),
    // styleMapFile, new File("target/" + i));

    i++;
}
cr.close();
assertEquals(259, i);

   }
 
Example 16
Source Project: bluima   Source File: XmlTestcaseCollectionReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {

    CollectionReader cr = createReader(XmlTestcaseCollectionReader.class,
            PARAM_INPUT_FILE, "testcases/example.xml");

    CAS cas = CasCreationUtils
            .createCas(cr.getProcessingResourceMetaData());
    cr.getNext(cas);
    cr.close();

    Collection<CellTypeProteinConcentration> prots = JCasUtil.select(
            cas.getJCas(), CellTypeProteinConcentration.class);
    assertTrue(prots.size() > 1);
    Prin.t(prots);
    // TODO assert on object
}
 
Example 17
Source Project: uima-uimafit   Source File: ExternalResourceFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiBinding() throws Exception {
  ExternalResourceDescription extDesc = createResourceDescription(ResourceWithAssert.class);

  // Binding external resource to each Annotator individually
  AnalysisEngineDescription aed1 = createEngineDescription(MultiBindAE.class,
          MultiBindAE.RES_KEY, extDesc);
  AnalysisEngineDescription aed2 = createEngineDescription(MultiBindAE.class,
          MultiBindAE.RES_KEY, extDesc);

  // Check the external resource was injected
  MultiBindAE.reset();
  AnalysisEngineDescription aed = createEngineDescription(aed1, aed2);
  AnalysisEngine ae = createEngine(aed);
  ae.process(ae.newJCas());


  // Check the external resource was injected
  MultiBindAE.reset();
  SimplePipeline.runPipeline(CasCreationUtils.createCas(aed), aed);
}
 
Example 18
Source Project: uima-uimaj   Source File: JcasSofaTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testGetSofa() throws Exception {
  try {
    File typeSystemFile = JUnitExtension.getFile("ExampleCas/testTypeSystem.xml");
    TypeSystemDescription typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
            new XMLInputSource(typeSystemFile));
    CAS newCas = CasCreationUtils.createCas(typeSystem, null, null);
    File xcasFile = JUnitExtension.getFile("ExampleCas/multiSofaCas.xml"); 
    XCASDeserializer.deserialize(new FileInputStream(xcasFile), newCas);
    JCas newJCas = newCas.getJCas();
    
    SofaID sofaId = new SofaID_impl("EnglishDocument");
    JCas view = newJCas.getView(newJCas.getSofa(sofaId));
  }
  catch (Exception e) {
    JUnitExtension.handleException(e);      
  }      
}
 
Example 19
Source Project: uima-uimaj   Source File: JCasCoverClassFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateJCasCoverClass() throws InvalidXMLException, IOException, ResourceInitializationException {
  File file = JUnitExtension.getFile("JCasGen/typeSystemAllKinds.xml");
  TypeSystemDescription tsDesc = UIMAFramework.getXMLParser().parseTypeSystemDescription(
          new XMLInputSource(file));
 
  CAS cas = CasCreationUtils.createCas(tsDesc, null, null);
  
  JCasCoverClassFactory jcf = new JCasCoverClassFactory();
  
  byte[] r = jcf.createJCasCoverClass((TypeImpl) cas.getTypeSystem().getType("pkg.sample.name.All"));

  Path root = Paths.get(".");  // should resolve to the project path
  Path dir = root.resolve("temp/test/JCasGen");
  dir.toFile().mkdirs();
  Files.write(dir.resolve("testOutputAllKinds.class"), r);
  
  System.out.println("debug: generated byte array");
}
 
Example 20
Source Project: uima-uimaj   Source File: AnnotatorTester.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * create a CAS object from the given XCAS and typesystem files.
 *
 * @param tsFile -
 *           a typesystem file
 * @param xcasFile -
 *           a xcas file
 * @return CAS - CAS object created from the given input data
 * @throws Exception passthru
 */
public static CAS getCASfromXCAS(File tsFile, File xcasFile)
      throws Exception {
   try {
      Object tsDescriptor = UIMAFramework.getXMLParser().parse(
            new XMLInputSource(tsFile));
      TypeSystemDescription tsDesc = (TypeSystemDescription) tsDescriptor;
      CAS cas = CasCreationUtils.createCas(tsDesc, null,
            new FsIndexDescription[0]);

      SAXParser parser = XMLUtils.createSAXParserFactory().newSAXParser();
      XCASDeserializer xcasDeserializer = new XCASDeserializer(cas
            .getTypeSystem());
      parser.parse(xcasFile, xcasDeserializer.getXCASHandler(cas));

      return cas;
   } catch (Exception ex) {
      JUnitExtension.handleException(ex);
   }

   return null;
}
 
Example 21
Source Project: uima-uimaj   Source File: XmiCasDeserializerTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testDuplicateNsPrefixes() throws Exception {
  TypeSystemDescription ts = new TypeSystemDescription_impl();
  ts.addType("org.bar.foo.Foo", "", "uima.tcas.Annotation");
  ts.addType("org.baz.foo.Foo", "", "uima.tcas.Annotation");
  CAS cas = CasCreationUtils.createCas(ts, null, null);
  cas.setDocumentText("Foo");
  Type t1 = cas.getTypeSystem().getType("org.bar.foo.Foo");
  Type t2 = cas.getTypeSystem().getType("org.baz.foo.Foo");
  AnnotationFS a1 = cas.createAnnotation(t1,0,3);
  cas.addFsToIndexes(a1);
  AnnotationFS a2 = cas.createAnnotation(t2,0,3);
  cas.addFsToIndexes(a2);

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  XmiCasSerializer.serialize(cas, baos);
  baos.close();
  byte[] bytes = baos.toByteArray();
  
  CAS cas2 = CasCreationUtils.createCas(ts, null, null);
  ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
  XmiCasDeserializer.deserialize(bais, cas2);
  bais.close();
  
  CasComparer.assertEquals(cas, cas2);
}
 
Example 22
Source Project: uima-uimaj   Source File: DocumentAnnotationTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testDocMeta() throws Exception {
  File typeSystemFile = JUnitExtension.getFile("ExampleCas/testTypeSystem_docmetadata.xml");
  TypeSystemDescription typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
          new XMLInputSource(typeSystemFile));
  
  source = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), null);
  target = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), null);
  
  jcas = source.getJCas();
  
  tstSerdesB4Sofa(SerialFormat.XMI);
  tstSerdesB4Sofa(SerialFormat.XCAS);
  tstSerdesB4Sofa(SerialFormat.BINARY);
  tstSerdesB4Sofa(SerialFormat.COMPRESSED);
  tstSerdesB4Sofa(SerialFormat.COMPRESSED_FILTERED);    
}
 
Example 23
Source Project: uima-uimaj   Source File: SerDesTest4.java    License: Apache License 2.0 6 votes vote down vote up
public void setUp() {
//    long seed = 1_449_257_605_347_913_923L;
    // long seed = 949_754_466_380_345_024L;
//     long seed = 6_761_039_426_734_540_557L;
//    long seed = 1_217_808_400_762_898_611L;
//    random.setSeed(randomseed.nextLong());
//    System.out.format("SerDesTest4 setup RandomSeed: %,d%n", seed);

    try {
      CASTestSetup cts = new CASTestSetup();
      this.cas = (CASImpl) CASInitializer.initCas(cts, t -> cts.reinitTypeSystem(t));
      this.ts = (TypeSystemImpl) this.cas.getTypeSystem();
      this.cas2 = (CASImpl) CasCreationUtils.createCas(ts, null, null, null);
      deserCas = (CASImpl) CasCreationUtils.createCas(ts, null, null, null);
      deltaCas = (CASImpl) CasCreationUtils.createCas(ts, null, null, null);
      lfs = new ArrayList<>();
      lfs2 = new ArrayList<>();
    } catch (Exception e) {
      assertTrue(false);
    }
  }
 
Example 24
Source Project: uima-uimaj   Source File: CasManager_impl.java    License: Apache License 2.0 6 votes vote down vote up
public CAS createNewCas(Properties aPerformanceTuningSettings) throws ResourceInitializationException {

    if (mCurrentTypeSystem != null) {
      return CasCreationUtils.createCas(getCasDefinition(), aPerformanceTuningSettings, mCurrentTypeSystem);      
    } else {
      synchronized(this) {
        if (mCurrentTypeSystem != null) { // double check idiom
          return CasCreationUtils.createCas(getCasDefinition(), aPerformanceTuningSettings, mCurrentTypeSystem);      
        } else {
          CAS cas = CasCreationUtils.createCas(getCasDefinition(), aPerformanceTuningSettings);
          mCurrentTypeSystem = cas.getTypeSystem();
          return cas;
        }
      }
    }    
  }
 
Example 25
Source Project: uima-uimaj   Source File: UimacppAnalysisEngineImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * For an aggregate TAF AE, sets this aggregate AE's Type System, Type Priorities, and FS Index
 * Descriptions equal to the result of merging the information from its delegate AEs.
 * 
 * @throws ResourceInitializationException
 *           if an error occurs
 */
protected void mergeDelegateAnalysisEngineMetaData() throws ResourceInitializationException {
  // do the merge
  TypeSystemDescription aggTypeSystem = CasCreationUtils.mergeDelegateAnalysisEngineTypeSystems(
          (AnalysisEngineDescription) mDescription, getResourceManager());
  TypePriorities aggTypePriorities = CasCreationUtils.mergeDelegateAnalysisEngineTypePriorities(
          (AnalysisEngineDescription) mDescription, getResourceManager());
  FsIndexCollection aggIndexColl = CasCreationUtils
          .mergeDelegateAnalysisEngineFsIndexCollections((AnalysisEngineDescription)mDescription, getResourceManager());

  // assign results of merge to this aggregate AE's metadata
  ProcessingResourceMetaData aggregateMD = (ProcessingResourceMetaData) mDescription.getMetaData();
  aggregateMD.setTypeSystem(aggTypeSystem);
  aggregateMD.setTypePriorities(aggTypePriorities);
  aggregateMD.setFsIndexCollection(aggIndexColl);
}
 
Example 26
Source Project: uima-uimaj   Source File: AnnotationIndexTest.java    License: Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
  long startTime = System.nanoTime();
  TypeSystemDescription typeSystemDescription = UIMAFramework.getXMLParser().parseTypeSystemDescription(
      new XMLInputSource(typeSystemFile1));
  System.out.format("time to parse ts: %,d%n", (System.nanoTime() - startTime)/ 1000000);
  startTime = System.nanoTime();
  cas = (CASImpl) CasCreationUtils.createCas(typeSystemDescription, new TypePriorities_impl(), null);
  jcas = cas.getJCas();
  ir = (FSIndexRepositoryImpl) cas.getIndexRepository();
  ai = cas.getAnnotationIndex(); 
  tsi = cas.getTypeSystemImpl();
  topType = tsi.getTopType();   
  System.out.format("time to create CAS: %,d%n", (System.nanoTime() - startTime)/ 1000000);
  startTime = System.nanoTime();
  
  //prefill
  int[] ttt = new int[SZp2];
  for (int i = 0; i < SZp2; i++) { ttt[i] = i;}
  ttt = shuffle(ttt);  
    
  
  for (int i = 0; i < SZp2; i++) {
    as[ttt[i]] = new Annotation(jcas, i, i + 200);
    ir.addFS(as[ttt[i]]);
  }

  System.out.format("time to create Annotations, add to indexes: %,d%n", (System.nanoTime() - startTime)/ 1000000);
  startTime = System.nanoTime();

}
 
Example 27
Source Project: webanno   Source File: AllAnnotationsIndexedCheckTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testFail()
    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);

    // A non-index annotation but reachable through an indexe one (below)
    AnnotationFS anno2 = cas.createAnnotation(cas.getAnnotationType(), 0, 1);

    // 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);
    
    assertFalse(result);
}
 
Example 28
Source Project: webanno   Source File: AllAnnotationsIndexedCheckTest.java    License: 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 29
Source Project: uima-uimaj   Source File: TypeSystemDescription_implTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testInvalidTypeSystem() throws Exception {
  File file = JUnitExtension.getFile("TypeSystemDescriptionImplTest/InvalidTypeSystem1.xml");
  TypeSystemDescription tsDesc = UIMAFramework.getXMLParser().parseTypeSystemDescription(
          new XMLInputSource(file));
  try {
    CasCreationUtils.createCas(tsDesc, null, null);
    // the above line should throw an exception
    fail();
  } catch (ResourceInitializationException e) {
    assertNotNull(e.getMessage());
    assertFalse(e.getMessage().startsWith("EXCEPTION MESSAGE LOCALIZATION FAILED"));
  }
}
 
Example 30
Source Project: uima-uimaj   Source File: XmiCasDeserializerTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testDeltaCasIndexing() throws Exception {
  try {
    CAS cas1 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
            indexes);
    CAS cas2 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
            indexes);
    cas1.setDocumentText("This is a test document in the initial view");
    FSIndexRepositoryImpl ir1 = (FSIndexRepositoryImpl) cas1.getIndexRepository();
    
    AnnotationFS anAnnotBefore = cas1.createAnnotation(cas1.getAnnotationType(), 0, 2);
    ir1.addFS(anAnnotBefore);
    
    cas1.createMarker();  // will start journaling index updates
    
    AnnotationFS anAnnot1 = cas1.createAnnotation(cas1.getAnnotationType(), 0, 4);
    ir1.addFS(anAnnot1);
    ir1.removeFS(anAnnot1);
    ir1.addFS(anAnnot1);
    
    assertTrue(ir1.getAddedFSs().size() == 1);
    assertTrue(ir1.getDeletedFSs().size() == 0);
    assertTrue(ir1.getReindexedFSs().size() == 0);
    
    ir1.removeFS(anAnnotBefore);
    ir1.addFS(anAnnotBefore);
    
    assertTrue(ir1.getAddedFSs().size() == 1);
    assertTrue(ir1.getDeletedFSs().size() == 0);
    assertTrue(ir1.getReindexedFSs().size() == 1);      
    
    ir1.removeFS(anAnnotBefore);
    assertTrue(ir1.getAddedFSs().size() == 1);
    assertTrue(ir1.getDeletedFSs().size() == 1);
    assertTrue(ir1.getReindexedFSs().size() == 0);      

    
  } catch (Exception e) {
  JUnitExtension.handleException(e);
  }
}