Java Code Examples for org.apache.uima.jcas.JCas#getCasType()

The following examples show how to use org.apache.uima.jcas.JCas#getCasType() . 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: Tsv3XSerializerTest.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleSubTokenWithValue() throws Exception
{
    // Create test document
    JCas cas = makeJCasOneSentence("This is a test .");
    addNamedEntity(cas, 1, 3, "PER");
    
    // Set up TSV schema
    TsvSchema schema = new TsvSchema();
    Type namedEntityType = cas.getCasType(NamedEntity.type);
    schema.addColumn(
            new TsvColumn(namedEntityType, LayerType.SPAN, "value", FeatureType.PRIMITIVE));

    // Convert test document content to TSV model
    TsvDocument doc = Tsv3XCasDocumentBuilder.of(schema, cas);

    String expectedSentence = 
            "#Text=This is a test .\n" + 
            "1-1\t0-4\tThis\t_\t\n" + 
            "1-1.1\t1-3\thi\tPER\t\n" + 
            "1-2\t5-7\tis\t_\t\n" + 
            "1-3\t8-9\ta\t_\t\n" + 
            "1-4\t10-14\ttest\t_\t\n" + 
            "1-5\t15-16\t.\t_\t\n";
    assertEquals(expectedSentence, doc.getSentences().get(0).toString());
}
 
Example 2
Source File: Tsv3XSerializerTest.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleZeroWidthTokenWithoutValue() throws Exception
{
    // Create test document
    JCas cas = makeJCasOneSentence("This is a test .");
    addNamedEntity(cas, 0, 0, null);
    
    // Set up TSV schema
    TsvSchema schema = new TsvSchema();
    Type namedEntityType = cas.getCasType(NamedEntity.type);
    schema.addColumn(
            new TsvColumn(namedEntityType, LayerType.SPAN, "value", FeatureType.PRIMITIVE));

    // Convert test document content to TSV model
    TsvDocument doc = Tsv3XCasDocumentBuilder.of(schema, cas);

    String expectedSentence = 
            "#Text=This is a test .\n" + 
            "1-1\t0-4\tThis\t_\t\n" + 
            "1-1.1\t0-0\t\t*\t\n" + 
            "1-2\t5-7\tis\t_\t\n" + 
            "1-3\t8-9\ta\t_\t\n" + 
            "1-4\t10-14\ttest\t_\t\n" + 
            "1-5\t15-16\t.\t_\t\n";
    assertEquals(expectedSentence, doc.getSentences().get(0).toString());
}
 
Example 3
Source File: JCasTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testUndefinedType() throws Exception {
  //create jcas with no type system
  JCas localJcas = CasCreationUtils.createCas(new TypeSystemDescription_impl(), null, null).getJCas();
  localJcas.setDocumentText("This is a test.");
  try {
    //this should throw an exception
    localJcas.getCasType(Sentence.type);
    fail(); 
  } catch(CASRuntimeException e) {
    assertEquals(CASRuntimeException.JCAS_TYPE_NOT_IN_CAS, e.getMessageKey());
  }
  //check that this does not leave JCAS in an inconsistent state
  //(a check for bug UIMA-738)
  Iterator<Annotation> iter = localJcas.getAnnotationIndex().iterator();
  assertTrue(iter.hasNext());
  Annotation annot = iter.next();
  assertEquals("This is a test.", annot.getCoveredText());
}
 
Example 4
Source File: Tsv3XSerializerTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void testStackedSingleTokenWithValue() throws Exception
{
    // Create test document
    JCas cas = makeJCasOneSentence("This is a test .");
    NamedEntity ne1 = addNamedEntity(cas, 0, 4, "PER");
    NamedEntity ne2 = addNamedEntity(cas, 0, 4, "ORG");
    
    // Set up TSV schema
    TsvSchema schema = new TsvSchema();
    Type namedEntityType = cas.getCasType(NamedEntity.type);
    schema.addColumn(
            new TsvColumn(namedEntityType, LayerType.SPAN, "value", FeatureType.PRIMITIVE));

    // Convert test document content to TSV model
    TsvDocument doc = Tsv3XCasDocumentBuilder.of(schema, cas);
    doc.getSentences().get(0).getTokens().get(0).addUimaAnnotation(ne1, true);
    doc.getSentences().get(0).getTokens().get(0).addUimaAnnotation(ne2, true);

    assertEquals("1-1\t0-4\tThis\tPER[1]|ORG[2]\t",
            doc.getSentences().get(0).getTokens().get(0).toString());
    
    String expectedSentence = 
            "#Text=This is a test .\n" + 
            "1-1\t0-4\tThis\tPER[1]|ORG[2]\t\n" + 
            "1-2\t5-7\tis\t_\t\n" + 
            "1-3\t8-9\ta\t_\t\n" + 
            "1-4\t10-14\ttest\t_\t\n" + 
            "1-5\t15-16\t.\t_\t\n";
    assertEquals(expectedSentence, doc.getSentences().get(0).toString());
}
 
Example 5
Source File: Tsv3XSerializerTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void testRelation() throws Exception
{
    // Create test document
    JCas cas = makeJCasOneSentence("This is a test .");
    List<Token> tokens = new ArrayList<>(select(cas, Token.class));
    Dependency dep = new Dependency(cas);
    dep.setGovernor(tokens.get(0));
    dep.setDependent(tokens.get(1));
    dep.setDependencyType("dep");
    dep.setBegin(dep.getDependent().getBegin());
    dep.setEnd(dep.getDependent().getEnd());
    dep.addToIndexes();
    
    // Set up TSV schema
    TsvSchema schema = new TsvSchema();
    Type dependencyType = cas.getCasType(Dependency.type);
    schema.addColumn(new TsvColumn(dependencyType, LayerType.RELATION, "DependencyType",
            FeatureType.PRIMITIVE));
    schema.addColumn(new TsvColumn(dependencyType, LayerType.RELATION, "Governor",
            FeatureType.RELATION_REF));

    // Convert test document content to TSV model
    TsvDocument doc = Tsv3XCasDocumentBuilder.of(schema, cas);
    doc.getSentences().get(0).getTokens().get(1).addUimaAnnotation(dep, false);

    assertEquals(
            join(asList("1-1\t0-4\tThis\t_\t_\t", "1-2\t5-7\tis\tdep\t1-1\t"), "\n"),
            join(asList(doc.getToken(0, 0), doc.getToken(0, 1)), "\n"));
    
    String expectedSentence = 
            "#Text=This is a test .\n" + 
            "1-1\t0-4\tThis\t_\t_\t\n" + 
            "1-2\t5-7\tis\tdep\t1-1\t\n" + 
            "1-3\t8-9\ta\t_\t_\t\n" + 
            "1-4\t10-14\ttest\t_\t_\t\n" + 
            "1-5\t15-16\t.\t_\t_\t\n";
    assertEquals(expectedSentence, doc.getSentences().get(0).toString());
}
 
Example 6
Source File: FSArray.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance of a subtype of FSArray having the component type clazz
 * Note: the array with this component type must already be specified in the 
 * type system declaration as a feature whose range is FSArray with the specified elementType.
 * @param clazz - the FSArray's element's class
 * @param jcas -
 * @param length -
 */
public FSArray(Class<? extends TOP> clazz, JCas jcas, int length) {
 this((TypeImpl)jcas.getCasType(clazz), jcas.getCasImpl(), length);
}