org.apache.uima.resource.metadata.TypeSystemDescription Java Examples

The following examples show how to use org.apache.uima.resource.metadata.TypeSystemDescription. 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: AnnotationSchemaServiceImpl.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSystemDescription getFullProjectTypeSystem(Project aProject,
        boolean aIncludeInternalTypes)
    throws ResourceInitializationException
{
    List<TypeSystemDescription> typeSystems = new ArrayList<>();
    
    // Types detected by uimaFIT
    typeSystems.add(createTypeSystemDescription());
    
    if (aIncludeInternalTypes) {
        // Types internally used by WebAnno (which we intentionally exclude from being detected
        // by uimaFIT because we want to have an easy way to create a type system excluding
        // these types when we export files from the project
        typeSystems.add(CasMetadataUtils.getInternalTypeSystem());
    }

    // Types declared within the project
    typeSystems.add(getCustomProjectTypes(aProject));

    return mergeTypeSystems(typeSystems);
}
 
Example #2
Source File: SerDesTest6.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testDocText() {
  try {
    CAS cas = CasCreationUtils.createCas((TypeSystemDescription) null, null, null);
    cas.setDocumentLanguage("latin");
    cas.setDocumentText("test");

    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);

    Serialization.serializeWithCompression(cas, baos, cas.getTypeSystem());

    CAS cas2 = CasCreationUtils.createCas((TypeSystemDescription) null, null, null);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    Serialization.deserializeCAS(cas2, bais);

    assertEquals("latin", cas2.getDocumentLanguage());
    assertEquals("test", cas2.getDocumentText());
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example #3
Source File: ComplexTypeTest.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
public void thatIntegerValueInConditionWorks() throws Exception
{
    TypeSystemDescription tsd = TypeSystemDescriptionFactory
            .createTypeSystemDescription("desc.types.TestTypeSystemDescriptor");

    CAS cas = createCas(tsd, null, null);
    cas.setDocumentText("blah");
    
    AnnotationFS continent = cas.createAnnotation(getType(cas, "de.Continent"), 0, 1);
    FSUtil.setFeature(continent, "area", 100);
    cas.addFsToIndexes(continent);

    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream(
            "src/test/resources/rules/region.rules"));
    ParsedConstraints constraints = parser.Parse().accept(new ParserVisitor());

    Evaluator constraintsEvaluator = new ValuesGenerator();
    List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(continent,
            "name", constraints);
    
    assertThat(possibleValues)
            .extracting(PossibleValue::getValue)
            .containsExactlyInAnyOrder("Fantasy Island");
}
 
Example #4
Source File: RoomNumberAnnotator1Test.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * This test is a bit better because we don't need a descriptor file for the analysis engine. We
 * still need a descriptor file for the type system but this isn't so bad as we expect there to be
 * a descriptor file for the type system as it is used to generate the Java jCas types. We are
 * still, unfortunately, creating a new JCas which is not so great.
 */
@Test
public void testRNA2() throws Exception {
  TypeSystemDescription typeSystemDescription = TypeSystemDescriptionFactory
          .createTypeSystemDescription("org.apache.uima.fit.examples.TypeSystem");
  AnalysisEngine roomNumberAnnotatorAE = AnalysisEngineFactory.createEngine(
          RoomNumberAnnotator.class, typeSystemDescription);
  JCas jCas = roomNumberAnnotatorAE.newJCas();
  jCas.setDocumentText("The meeting is over at Yorktown 01-144");
  roomNumberAnnotatorAE.process(jCas);

  RoomNumber roomNumber = JCasUtil.selectByIndex(jCas, RoomNumber.class, 0);
  assertNotNull(roomNumber);
  assertEquals("01-144", roomNumber.getCoveredText());
  assertEquals("Yorktown", roomNumber.getBuilding());
}
 
Example #5
Source File: AgreementTestUtils.java    From webanno with 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 File: JcasSofaTest.java    From uima-uimaj with 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 #7
Source File: ExternalRecommenderIntegrationTest.java    From inception with Apache License 2.0 6 votes vote down vote up
private List<CAS> loadData(Dataset ds, File ... files) throws UIMAException, IOException
{
    CollectionReader reader = createReader(Conll2002Reader.class,
        Conll2002Reader.PARAM_PATTERNS, files,
        Conll2002Reader.PARAM_LANGUAGE, ds.getLanguage(),
        Conll2002Reader.PARAM_COLUMN_SEPARATOR, Conll2002Reader.ColumnSeparators.TAB.getName(),
        Conll2002Reader.PARAM_HAS_TOKEN_NUMBER, true,
        Conll2002Reader.PARAM_HAS_HEADER, true,
        Conll2002Reader.PARAM_HAS_EMBEDDED_NAMED_ENTITY, true);

    List<CAS> casList = new ArrayList<>();
    while (reader.hasNext()) {
        // Add the CasMetadata type to the CAS
        List<TypeSystemDescription> typeSystems = new ArrayList<>();
        typeSystems.add(createTypeSystemDescription());
        typeSystems.add(CasMetadataUtils.getInternalTypeSystem());
        JCas cas = JCasFactory.createJCas(mergeTypeSystems(typeSystems));
        reader.getNext(cas.getCas());
        casList.add(cas.getCas());
    }
    return casList;
}
 
Example #8
Source File: TypeSystemUtil.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Convert a {@link TypeSystem} to an equivalent {@link TypeSystemDescription}.
 * 
 * @param aTypeSystem
 *          type system object to convert
 * @return a TypeSystemDescription that is equivalent to <code>aTypeSystem</code>
 */
public static TypeSystemDescription typeSystem2TypeSystemDescription(TypeSystem aTypeSystem) {
  ResourceSpecifierFactory fact = UIMAFramework.getResourceSpecifierFactory();
  TypeSystemDescription tsDesc = fact.createTypeSystemDescription();
  Iterator<Type> typeIter = aTypeSystem.getTypeIterator();
  List<TypeDescription> typeDescs = new ArrayList<>();
  while (typeIter.hasNext()) {
    Type type = typeIter.next();
    if (!type.getName().startsWith("uima.cas") && !type.getName().equals("uima.tcas.Annotation") &&
        !type.isArray()) {
      typeDescs.add(type2TypeDescription(type, aTypeSystem));
    }
  }
  TypeDescription[] typeDescArr = new TypeDescription[typeDescs.size()];
  typeDescs.toArray(typeDescArr);
  tsDesc.setTypes(typeDescArr);

  return tsDesc;
}
 
Example #9
Source File: RecommenderTestHelper.java    From inception with Apache License 2.0 6 votes vote down vote up
public static void addScoreFeature(CAS aCas, String aTypeName, String aFeatureName)
        throws IOException, UIMAException
{
    String scoreFeatureName = aFeatureName + FEATURE_NAME_SCORE_SUFFIX;
    String scoreExplanationFeatureName = aFeatureName + FEATURE_NAME_SCORE_EXPLANATION_SUFFIX;

    TypeSystemDescription tsd = typeSystem2TypeSystemDescription(aCas.getTypeSystem());
    TypeDescription typeDescription = tsd.getType(aTypeName);
    typeDescription.addFeature(scoreFeatureName, "Confidence feature", TYPE_NAME_DOUBLE);
    typeDescription.addFeature(scoreExplanationFeatureName, "Confidence explanation feature", 
            TYPE_NAME_STRING);
    typeDescription.addFeature(FEATURE_NAME_IS_PREDICTION, "Is prediction", TYPE_NAME_BOOLEAN);

    AnnotationSchemaService schemaService = new AnnotationSchemaServiceImpl();
    schemaService.upgradeCas(aCas, tsd);
}
 
Example #10
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void refresh() {
  super.refresh();

  tt.removeAll();

  TypeSystemDescription tsdFull = getMergedTypeSystemDescription();

  TypeDescription[] tdsFull = tsdFull.getTypes();
  if (null != tdsFull) {
    for (int i = 0; i < tdsFull.length; i++) {
      addTypeToGUI(tdsFull[i]);
    }
  }

  if (tt.getItemCount() > 0)
    tt.setSelection(tt.getItems()[0]);
  packTree(tt);
  enable();
}
 
Example #11
Source File: AgreementTestUtils.java    From webanno with 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 #12
Source File: DefinedTypesWithSupers.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Update.
 */
private void update() {
  cachedResult.clear();

  // for aggregates, this is the fully-merged type system
  // for all systems, it is the type system with imports resolved
  TypeSystemDescription typeSystemDescription = modelRoot.getMergedTypeSystemDescription();

  if (typeSystemDescription == null)
    return; // cleared table

  TypeDescription[] types = typeSystemDescription.getTypes();
  TypeSystem typeSystem = modelRoot.descriptorCAS.get().getTypeSystem();

  String typeName;
  Map allTypes = modelRoot.allTypes.get();
  for (int i = 0; i < types.length; i++) {
    cachedResult.add(typeName = types[i].getName());
    Type nextType = (Type) allTypes.get(typeName);
    while (nextType != null) {
      nextType = typeSystem.getParent(nextType);
      if (nextType != null)
        cachedResult.add(nextType.getName());
    }
  }
}
 
Example #13
Source File: CasIOUtilsTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
protected void setUp() throws Exception {
  File indexesFile = JUnitExtension.getFile("ExampleCas/testIndexes.xml");
  FsIndexDescription[] indexes = UIMAFramework.getXMLParser()
          .parseFsIndexCollection(new XMLInputSource(indexesFile)).getFsIndexes();

  File typeSystemFile = JUnitExtension.getFile("ExampleCas/testTypeSystem.xml");
  TypeSystemDescription typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
          new XMLInputSource(typeSystemFile));
  
  cas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes);
  
  try (FileInputStream casInputStream = new FileInputStream(
          JUnitExtension.getFile("ExampleCas/simpleCas.xmi"))) {
    CasIOUtils.load(casInputStream, cas);
  }

  File typeSystemFile2 = JUnitExtension.getFile("ExampleCas/testTypeSystem_variation.xml");
  TypeSystemDescription typeSystem2 = UIMAFramework.getXMLParser().parseTypeSystemDescription(
          new XMLInputSource(typeSystemFile2));
  cas2 = CasCreationUtils.createCas(typeSystem2, new TypePriorities_impl(), indexes);
}
 
Example #14
Source File: WebAnnoTsv3WriterTestBase.java    From webanno with 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 #15
Source File: CurationTestUtils.java    From webanno with 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", "", 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);

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

    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
 
Example #16
Source File: CasCreationUtilsTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testCreateCasTypeSystemDescription() throws Exception {
  try {
    //parse type system description
    TypeSystemDescription tsDesc = UIMAFramework.getXMLParser().parseTypeSystemDescription(
            new XMLInputSource(JUnitExtension.getFile("CasCreationUtilsTest/SupertypeMergeTestMaster.xml")));

    // call method
    CAS cas = CasCreationUtils.createCas(tsDesc, null, null);
    
    //check that imports were resolved and supertype merged properly
    Type subType = cas.getTypeSystem().getType("uima.test.Sub");
    assertNotNull(subType);
    Type superType = cas.getTypeSystem().getType("uima.test.Super");
    assertNotNull(superType);
    assertTrue(cas.getTypeSystem().subsumes(superType,subType));      
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #17
Source File: RelationLayerSupport.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Override
public void generateTypes(TypeSystemDescription aTsd, AnnotationLayer aLayer,
        List<AnnotationFeature> aAllFeaturesInProject)
{
    TypeDescription td = aTsd.addType(aLayer.getName(), aLayer.getDescription(),
            TYPE_NAME_ANNOTATION);
    AnnotationLayer attachType = aLayer.getAttachType();

    td.addFeature(FEAT_REL_TARGET, "", attachType.getName());
    td.addFeature(FEAT_REL_SOURCE, "", attachType.getName());

    List<AnnotationFeature> featureForLayer = aAllFeaturesInProject.stream()
            .filter(feature -> aLayer.equals(feature.getLayer()))
            .collect(toList());
    generateFeatures(aTsd, td, featureForLayer);
}
 
Example #18
Source File: DiffTestUtils.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 #19
Source File: SpanLayerSupport.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public void generateTypes(TypeSystemDescription aTsd, AnnotationLayer aLayer,
        List<AnnotationFeature> aAllFeaturesInProject)
{
    TypeDescription td = aTsd.addType(aLayer.getName(), aLayer.getDescription(),
            CAS.TYPE_NAME_ANNOTATION);
    
    List<AnnotationFeature> featureForLayer = aAllFeaturesInProject.stream()
            .filter(feature -> aLayer.equals(feature.getLayer()))
            .collect(toList());
    generateFeatures(aTsd, td, featureForLayer);
}
 
Example #20
Source File: AnnotationSchemaServiceImpl.java    From webanno with Apache License 2.0 5 votes vote down vote up
/**
 * Load the contents from the source CAS, upgrade it to the target type system and write the
 * results to the target CAS. An in-place upgrade can be achieved by using the same CAS as
 * source and target.
 */
@Override
public void upgradeCas(CAS aSourceCas, CAS aTargetCas, TypeSystemDescription aTargetTypeSystem)
    throws UIMAException, IOException
{
    CasStorageSession.get().assertWritingPermitted(aTargetCas);
    
    // Save source CAS type system (do this early since we might do an in-place upgrade)
    TypeSystem sourceTypeSystem = aSourceCas.getTypeSystem();

    // Save source CAS contents
    ByteArrayOutputStream serializedCasContents = new ByteArrayOutputStream();
    CAS realSourceCas = getRealCas(aSourceCas);
    // UIMA-6162 Workaround: synchronize CAS during de/serialization
    synchronized (((CASImpl) realSourceCas).getBaseCAS()) {
        serializeWithCompression(realSourceCas, serializedCasContents, sourceTypeSystem);
    }

    // Re-initialize the target CAS with new type system
    CAS realTargetCas = getRealCas(aTargetCas);
    // UIMA-6162 Workaround: synchronize CAS during de/serialization
    synchronized (((CASImpl) realTargetCas).getBaseCAS()) {
        CAS tempCas = CasFactory.createCas(aTargetTypeSystem);
        CASCompleteSerializer serializer = serializeCASComplete((CASImpl) tempCas);
        deserializeCASComplete(serializer, (CASImpl) realTargetCas);

        // Leniently load the source CAS contents into the target CAS
        CasIOUtils.load(new ByteArrayInputStream(serializedCasContents.toByteArray()),
                getRealCas(aTargetCas), sourceTypeSystem);
    }
}
 
Example #21
Source File: TypeSystemAnalysisTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void testSpanWithSlotFeatures() throws Exception
{
    TypeSystemDescription tsd = createTypeSystemDescription("tsd/spanWithSlotFeatures");
    TypeSystemAnalysis analysis = TypeSystemAnalysis.of(tsd);
    
    AnnotationLayer slotSpanLayer = new AnnotationLayer();
    slotSpanLayer.setName("webanno.custom.SlotSpan");
    slotSpanLayer.setUiName("SlotSpan");
    slotSpanLayer.setType(WebAnnoConst.SPAN_TYPE);
    slotSpanLayer.setAnchoringMode(AnchoringMode.CHARACTERS);
    slotSpanLayer.setOverlapMode(OverlapMode.ANY_OVERLAP);
    slotSpanLayer.setCrossSentence(true);
    
    AnnotationFeature freeSlot = new AnnotationFeature(
            "freeSlot", CAS.TYPE_NAME_ANNOTATION);

    AnnotationFeature boundSlot = new AnnotationFeature(
            "boundSlot", "webanno.custom.SlotSpan");

    SoftAssertions softly = new SoftAssertions();
    softly.assertThat(analysis.getLayers())
        .containsExactly(slotSpanLayer)
        .usingFieldByFieldElementComparator();
    softly.assertThat(analysis.getFeatures(slotSpanLayer.getName()))
        .containsExactlyInAnyOrder(freeSlot, boundSlot)
        .usingFieldByFieldElementComparator();
    softly.assertAll();
}
 
Example #22
Source File: Conll2012FormatSupport.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public CollectionReaderDescription getReaderDescription(TypeSystemDescription aTSD)
    throws ResourceInitializationException
{
    return createReaderDescription(Conll2012Reader.class, aTSD,
            // Constituents are not supported by WebAnno and trying to read a file which does
            // not have them triggers an NPE in DKPro Core 1.11.0
            Conll2012Reader.PARAM_READ_CONSTITUENT, false);
}
 
Example #23
Source File: CasDefinition.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public CasDefinition(TypeSystemDescription aTypeSystem, TypePriorities aTypePriorities,
        FsIndexDescription[] aFsIndexes, ResourceManager aResourceManager,
        Properties aPerformanceTuningSettings) {
  this.typeSystemDescription = aTypeSystem;
  this.typePriorities = aTypePriorities;
  this.fsIndexDescriptions = aFsIndexes;
  this.resourceManager = aResourceManager;
}
 
Example #24
Source File: WebAnnoCasUtilTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void thatCreateDocumentMetadataUpgradesExistingDocumentAnnotation() throws Exception
{
    TypeSystemDescription tsd = createTypeSystemDescription();
    
    CAS cas = getRealCas(createCas(tsd));
    
    assertThat(cas.select(DocumentAnnotation.class).asList())
            .as("CAS has no DocumentAnnotation")
            .isEmpty();
    
    cas.setDocumentLanguage("en");
    
    assertThat(cas.select(DocumentAnnotation.class).asList())
            .as("CAS initialized with DocumentAnnotation")
            .extracting(fs -> fs.getType().getName())
            .containsExactly(TYPE_NAME_DOCUMENT_ANNOTATION);
    assertThat(cas.select(DocumentAnnotation.class).asList())
            .as("Language has been set")
            .extracting(DocumentAnnotation::getLanguage)
            .containsExactly("en");

    WebAnnoCasUtil.createDocumentMetadata(cas);

    assertThat(cas.select(DocumentAnnotation.class).asList())
            .as("DocumentAnnotation has been upgraded to DocumentMetaData")
            .extracting(fs -> fs.getType().getName())
            .containsExactly(DocumentMetaData.class.getName());
    assertThat(cas.select(DocumentAnnotation.class).asList())
            .as("Language survived upgrade")
            .extracting(DocumentAnnotation::getLanguage)
            .containsExactly("en");
}
 
Example #25
Source File: Tsv3XSerializerTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
private JCas makeJCasOneSentence(String aText) throws UIMAException
{
    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");
    
    TokenBuilder<Token, Sentence> tb = new TokenBuilder<>(Token.class,
            Sentence.class);
    tb.buildTokens(jcas, aText);
    
    // Remove the sentences generated by the token builder which treats the line break as a
    // sentence break
    for (Sentence s : select(jcas, Sentence.class)) {
        s.removeFromIndexes();
    }
    
    // Add a new sentence covering the whole text
    new Sentence(jcas, 0, jcas.getDocumentText().length()).addToIndexes();
    
    return jcas;
}
 
Example #26
Source File: CasCreationUtilsTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testStringSubtype() throws Exception {
  try {

    TypeSystemDescription ts1desc = UIMAFramework.getXMLParser()
        .parseTypeSystemDescription(
            new XMLInputSource(JUnitExtension
                .getFile("CasCreationUtilsTest/TypeSystemMergeStringSubtypeBasePlus.xml")));
    
    TypeSystemDescription result = checkMergeTypeSystem(ts1desc, "TypeSystemMergeStringSubtypeBase.xml",
        ResourceInitializationException.ALLOWED_VALUES_NOT_IDENTICAL);
    
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }    
}
 
Example #27
Source File: NifFormatSupport.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public AnalysisEngineDescription getWriterDescription(Project aProject,
        TypeSystemDescription aTSD, CAS aCAS)
    throws ResourceInitializationException
{
    return createEngineDescription(NifWriter.class, aTSD);
}
 
Example #28
Source File: DiffTestUtils.java    From webanno with Apache License 2.0 5 votes vote down vote up
public static Map<String, List<JCas>> loadXMI(TypeSystemDescription aTypes, String... aPaths)
    throws UIMAException, IOException
{
    Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
    int n = 1;
    for (String path : aPaths) {
        JCas cas = readXMI(path, aTypes);
        casByUser.put("user" + n, asList(cas));
        n++;
    }
    return casByUser;
}
 
Example #29
Source File: Conll2003FormatSupport.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public AnalysisEngineDescription getWriterDescription(Project aProject,
        TypeSystemDescription aTSD, CAS aCAS)
    throws ResourceInitializationException
{
    return createEngineDescription(Conll2003Writer.class, aTSD);
}
 
Example #30
Source File: XMLParser_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public TypeSystemDescription parseTypeSystemDescription(XMLInputSource aInput,
        ParsingOptions aOptions) throws InvalidXMLException {
  // attempt to locate resource specifier schema
  XMLizable object = parse(aInput, RESOURCE_SPECIFIER_NAMESPACE, SCHEMA_URL, aOptions);

  if (object instanceof TypeSystemDescription) {
    return (TypeSystemDescription) object;
  } else {
    throw new InvalidXMLException(InvalidXMLException.INVALID_CLASS, new Object[] {
        TypeSystemDescription.class.getName(), object.getClass().getName() });
  }
}