Java Code Examples for org.apache.uima.fit.factory.JCasFactory#createText()

The following examples show how to use org.apache.uima.fit.factory.JCasFactory#createText() . 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: VisibilityCalculationTests.java    From inception with Apache License 2.0 6 votes vote down vote up
private CAS getTestCas() throws Exception
{
    String documentText = "Dies ist ein Testtext, ach ist der schoen, der schoenste von allen"
            + " Testtexten.";
    JCas jcas = JCasFactory.createText(documentText, "de");

    NamedEntity neLabel = new NamedEntity(jcas, 0, 3);
    neLabel.setValue("LOC");
    neLabel.addToIndexes();

    // the annotation's feature value is initialized as null
    NamedEntity neNoLabel = new NamedEntity(jcas, 13, 20);
    neNoLabel.addToIndexes();

    return jcas.getCas();
}
 
Example 2
Source File: CasStorageServiceImplTest.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteReadExistsDeleteCas() throws Exception
{
    SourceDocument doc = makeSourceDocument(1l, 1l);
    JCas cas = JCasFactory.createText("This is a test");
    casStorageSession.add("cas", EXCLUSIVE_WRITE_ACCESS, cas.getCas());
    String user = "test";
    
    sut.writeCas(doc, cas.getCas(), user);
    assertThat(sut.getCasFile(doc, user)).exists();
    assertThat(sut.existsCas(doc, user)).isTrue();
    
    CAS cas2 = sut.readCas(doc, user);
    assertThat(cas2.getDocumentText()).isEqualTo(cas.getDocumentText());
    
    sut.deleteCas(doc, user);
    assertThat(sut.getCasFile(doc, user)).doesNotExist();
    assertThat(sut.existsCas(doc, user)).isFalse();
}
 
Example 3
Source File: DataMajorityNerRecommenderTest.java    From inception with Apache License 2.0 5 votes vote down vote up
private List<CAS> getTestNECas(String aText, String[] aVals, int[][] aIndices) throws Exception
{
    JCas jcas = JCasFactory.createText(aText, "de");

    for (int i = 0; i < aVals.length; i++) {
        NamedEntity newNE = new NamedEntity(jcas, aIndices[i][0], aIndices[i][1]);
        newNE.setValue(aVals[i]);
        newNE.addToIndexes();
    }

    List<CAS> casses = new ArrayList<>();
    casses.add(jcas.getCas());

    return casses;
}
 
Example 4
Source File: StringMatchingRecommenderTest.java    From inception with Apache License 2.0 5 votes vote down vote up
private List<CAS> getTestNECas(String aText, String[] aVals, int[][] aNEIndices,
        int[][] aSentIndices, int[][] aTokenIndices)
    throws Exception
{
    JCas jcas = JCasFactory.createText(aText, "de");

    for (int j = 0; j < aSentIndices.length; j++) {
        Sentence newSent = new Sentence(jcas, aSentIndices[j][0], aSentIndices[j][1]);
        newSent.addToIndexes();
    }

    for (int k = 0; k < aTokenIndices.length; k++) {
        Token newToken = new Token(jcas, aTokenIndices[k][0], aTokenIndices[k][1]);
        newToken.addToIndexes();
    }

    for (int i = 0; i < aVals.length; i++) {
        NamedEntity newNE = new NamedEntity(jcas, aNEIndices[i][0], aNEIndices[i][1]);
        newNE.setValue(aVals[i]);
        newNE.addToIndexes();
    }

    List<CAS> casses = new ArrayList<>();
    casses.add(jcas.getCas());

    return casses;
}
 
Example 5
Source File: RecommendationServiceImplIntegrationTest.java    From inception with Apache License 2.0 5 votes vote down vote up
@Test
public void monkeyPatchTypeSystem_WithNer_CreatesScoreFeatures() throws Exception
{
    try (CasStorageSession session = CasStorageSession.open()) {
        JCas jCas = JCasFactory.createText("I am text CAS", "de");
        session.add("jCas", CasAccessMode.EXCLUSIVE_WRITE_ACCESS, jCas.getCas());
        
        when(annoService.getFullProjectTypeSystem(project))
                .thenReturn(typeSystem2TypeSystemDescription(jCas.getTypeSystem()));
        when(annoService.listAnnotationLayer(project))
                .thenReturn(asList(layer));
        doCallRealMethod().when(annoService)
                .upgradeCas(any(CAS.class), any(TypeSystemDescription.class));
        doCallRealMethod().when(annoService)
                .upgradeCas(any(CAS.class), any(CAS.class), any(TypeSystemDescription.class));

        sut.cloneAndMonkeyPatchCAS(project, jCas.getCas(), jCas.getCas());

        Type type = CasUtil.getType(jCas.getCas(), layer.getName());

        assertThat(type.getFeatures())
                .extracting(Feature::getShortName)
                .contains(feature.getName() + FEATURE_NAME_SCORE_SUFFIX)
                .contains(feature.getName() + FEATURE_NAME_SCORE_EXPLANATION_SUFFIX)
                .contains(FEATURE_NAME_IS_PREDICTION);
    }
}
 
Example 6
Source File: SegmentationTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void testSplitSentences() throws Exception
{
    JCas jcas = JCasFactory.createText("I am one. I am two.", "en");
    
    ImportExportServiceImpl.splitSentences(jcas.getCas());
    
    assertEquals(asList("I am one.", "I am two."), toText(select(jcas, Sentence.class)));
}
 
Example 7
Source File: SegmentationTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void testTokenize() throws Exception
{
    JCas jcas = JCasFactory.createText("i am one.i am two.", "en");
    new Sentence(jcas, 0, 9).addToIndexes();;
    new Sentence(jcas, 9, 18).addToIndexes();
    
    ImportExportServiceImpl.tokenize(jcas.getCas());
    
    assertEquals(asList("i am one.", "i am two."), toText(select(jcas, Sentence.class)));
    assertEquals(asList("i", "am", "one", ".", "i", "am", "two", "."),
            toText(select(jcas, Token.class)));
}
 
Example 8
Source File: CasMergeTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
/**
 * If one annotator has provided an annotation at a given position and the other annotator did
 * not (i.e. the annotations are incomplete), then this should be detected as a disagreement. 
 */
@Test
public void thatIncompleteAnnotationIsNotMerged()
    throws Exception
{
    JCas user1 = JCasFactory.createText("word");
    token(user1, 0, 4, "X");
    
    JCas user2 = JCasFactory.createText("word");
    token(user2, 0, 4, null);
    
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(user1.getCas()));
    casByUser.put("user2", asList(user2.getCas()));
    
    JCas curatorCas = createText(casByUser.values().stream()
            .flatMap(Collection::stream).findFirst().get().getDocumentText());
    
    DiffResult result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser)
            .toResult();

    sut.reMergeCas(result, document, null, curatorCas.getCas(), getSingleCasByUser(casByUser));

    assertThat(result.getDifferingConfigurationSets()).isEmpty();
    assertThat(result.getIncompleteConfigurationSets().values())
            .extracting(set -> set.getPosition())
            .usingFieldByFieldElementComparator()
            .containsExactly(new SpanPosition(null, null, 0, POS.class.getName(), 0, 4, "word",
                    null, null, -1, -1, null, null));
    
    assertThat(select(curatorCas, POS.class)).isEmpty();
}
 
Example 9
Source File: CasMergeTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
/**
 * If one annotator has provided an annotation at a given position and the other annotator did
 * not (i.e. the annotations are incomplete), then this should be detected as a disagreement. 
 */
@Test
public void thatIncompleteAnnotationIsMerged()
    throws Exception
{
    JCas user1 = JCasFactory.createText("word");
    token(user1, 0, 4, "X");
    
    JCas user2 = JCasFactory.createText("word");
    token(user2, 0, 4, null);
    
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(user1.getCas()));
    casByUser.put("user2", asList(user2.getCas()));
    
    JCas curatorCas = createText(casByUser.values().stream()
            .flatMap(Collection::stream).findFirst().get().getDocumentText());
    
    DiffResult result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();

    sut.setMergeIncompleteAnnotations(true);
    sut.reMergeCas(result, document, null, curatorCas.getCas(), getSingleCasByUser(casByUser));

    assertThat(result.getDifferingConfigurationSets()).isEmpty();
    assertThat(result.getIncompleteConfigurationSets().values())
            .extracting(set -> set.getPosition())
            .usingFieldByFieldElementComparator()
            .containsExactly(new SpanPosition(null, null, 0, POS.class.getName(), 0, 4, "word",
                    null, null, -1, -1, null, null));
    
    assertThat(select(curatorCas, POS.class)).hasSize(1);
}
 
Example 10
Source File: FSUtilBenchmark.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setupOnce() throws Exception {
	jcas = JCasFactory.createText("test");
	fs = new Token(jcas, 0, 1);
	fs.addToIndexes();
}