org.apache.uima.fit.factory.JCasFactory Java Examples

The following examples show how to use org.apache.uima.fit.factory.JCasFactory. 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: KafkaTransportsTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testKafkaTransportCanSend() throws UIMAException, IOException {

  MockKafkaResource mockKafkaResource = new MockKafkaResource();
  when(context.getResourceObject(SharedKafkaResource.RESOURCE_KEY)).thenReturn(locator);
  when(locator.getResource()).thenReturn(mockKafkaResource);

  KafkaTransportSender kafkaTransportSender = new KafkaTransportSender();
  kafkaTransportSender.initialize(context);

  JCas in = JCasFactory.createJCas();
  kafkaTransportSender.process(in);

  MockProducer<String, String> mockProducer = mockKafkaResource.getMockProducer();

  List<ProducerRecord<String, String>> history = mockProducer.history();
  assertTrue(history.size() == 1);
  assertEquals(JCasSerializationTester.EMPTY_JSON, history.get(0).value());
  kafkaTransportSender.closeQueue();
}
 
Example #2
Source File: StringMatchingRecommenderTest.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<>();
    int n = 1;
    while (reader.hasNext()) {
        JCas cas = JCasFactory.createJCas();
        reader.getNext(cas.getCas());
        casList.add(cas.getCas());
        casStorageSession.add("testDataCas" + n, EXCLUSIVE_WRITE_ACCESS, cas.getCas());
    }
    
    return casList;
}
 
Example #3
Source File: SentenceFactoryTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void canCreateMultipleSentenceWithOffsets() throws UIMAException {
  JCas jCas = JCasFactory.createJCas();
  jCas.setDocumentText("This is the first sentence. This is the second.");
  Annotations.createWordTokens(jCas);
  Annotations.createSentences(jCas);
  SentenceFactory factory = new SentenceFactory(jCas);

  List<OdinSentence> sentences = factory.create();
  Sentence sentence1 = sentences.get(0);
  Sentence sentence2 = sentences.get(1);

  assertTrue(
      Arrays.toString(sentence1.startOffsets()),
      Arrays.equals(new int[] {0, 5, 8, 12, 18, 26}, sentence1.startOffsets()));
  assertTrue(
      Arrays.toString(sentence1.endOffsets()),
      Arrays.equals(new int[] {4, 7, 11, 17, 26, 27}, sentence1.endOffsets()));
  assertTrue(
      Arrays.toString(sentence2.startOffsets()),
      Arrays.equals(new int[] {28, 33, 36, 40, 46}, sentence2.startOffsets()));
  assertTrue(
      Arrays.toString(sentence2.endOffsets()),
      Arrays.equals(new int[] {32, 35, 39, 46, 47}, sentence2.endOffsets()));
}
 
Example #4
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 #5
Source File: DiffTestUtils.java    From webanno with 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 #6
Source File: DocumentGraphFactoryTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testDocumentGraphWithoutEvents() throws UIMAException {

  DocumentGraphOptions options = DocumentGraphOptions.builder().withEvents(false).build();
  DocumentGraphFactory factory = createfactory(options);

  JCas jCas = JCasFactory.createJCas();
  JCasTestGraphUtil.populateJcas(jCas);
  Graph graph = factory.create(jCas);

  assertEquals(3, graph.traversal().V().hasLabel(REFERENCE_TARGET).count().next().intValue());
  assertEquals(0, graph.traversal().V().hasLabel(EVENT).count().next().intValue());
  assertEquals(4, graph.traversal().V().hasLabel(MENTION).count().next().intValue());
  assertEquals(2, graph.traversal().V().hasLabel(RELATION).count().next().intValue());
  assertEquals(4, graph.traversal().E().hasLabel(MENTION_OF).count().next().intValue());
  assertEquals(0, graph.traversal().E().hasLabel(PARTICIPANT_IN).count().next().intValue());

  assertNoDocumentNode(graph);
  assertNoRelationEdges(graph);

  assertEquals(9, IteratorUtils.count(graph.vertices()));
  assertEquals(8, IteratorUtils.count(graph.edges()));
}
 
Example #7
Source File: SentenceFactoryTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void canCreateSentenceFromAnnotations() throws UIMAException {
  JCas jCas = JCasFactory.createJCas();

  addWordTokens(jCas);

  SentenceFactory factory = new SentenceFactory(jCas);

  List<OdinSentence> sentences = factory.create();
  assertEquals(1, sentences.size());
  Sentence sentence = sentences.get(0);

  assertEquals(
      ImmutableSet.of("This", "is", "a", "sentence", "."), ImmutableSet.copyOf(sentence.words()));

  assertTrue(Arrays.equals(new int[] {0, 5, 8, 10, 18}, sentence.startOffsets()));
  assertTrue(Arrays.equals(new int[] {4, 7, 9, 18, 19}, sentence.endOffsets()));

  assertEquals(
      ImmutableSet.of("this", "is", "a", "lemma", "."),
      ImmutableSet.copyOf(sentence.lemmas().get()));
  assertEquals(
      ImmutableSet.of("DT", "VBZ", "DT", "NN", "."), ImmutableSet.copyOf(sentence.tags().get()));
}
 
Example #8
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 #9
Source File: OpenNlpDoccatRecommenderTest.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(Reader.class,
            Reader.PARAM_PATTERNS, files, 
            Reader.PARAM_LANGUAGE, ds.getLanguage());

    AnalysisEngine segmenter = createEngine(BreakIteratorSegmenter.class,
            BreakIteratorSegmenter.PARAM_WRITE_SENTENCE, false);
    
    List<CAS> casList = new ArrayList<>();
    while (reader.hasNext()) {
        JCas cas = JCasFactory.createJCas();
        reader.getNext(cas.getCas());
        segmenter.process(cas);
        casList.add(cas.getCas());
    }
    return casList;
}
 
Example #10
Source File: DocumentConverterTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void canConvertSentence() throws UIMAException {
  JCas jCas = JCasFactory.createJCas();
  jCas.setDocumentText("This is a test. This is another test.");

  String[] words = new String[] {"This", "is", "another", "test", "."};
  Sentence sentence2 =
      new Sentence(words, new int[] {16, 21, 24, 31, 35}, new int[] {20, 23, 30, 34, 36}, words);
  when(document.sentences()).thenReturn(new Sentence[] {sentence, sentence2});
  DocumentConverter converter = new DocumentConverter(jCas, document);
  converter.convert();

  Collection<uk.gov.dstl.baleen.types.language.Sentence> actual =
      JCasUtil.select(jCas, uk.gov.dstl.baleen.types.language.Sentence.class);
  assertEquals(2, actual.size());
  Iterator<uk.gov.dstl.baleen.types.language.Sentence> iterator = actual.iterator();

  uk.gov.dstl.baleen.types.language.Sentence next = iterator.next();
  assertEquals(0, next.getBegin());
  assertEquals(15, next.getEnd());
  next = iterator.next();
  assertEquals(16, next.getBegin());
  assertEquals(36, next.getEnd());
}
 
Example #11
Source File: OpenNlpNerRecommenderTest.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()) {
        JCas cas = JCasFactory.createJCas();
        reader.getNext(cas.getCas());
        casList.add(cas.getCas());
    }
    return casList;
}
 
Example #12
Source File: WebAnnoTsv3WriterTestBase.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
public void testAnnotationWithTrailingWhitespace() throws Exception
{
    JCas jcas = JCasFactory.createJCas();
    
    DocumentMetaData.create(jcas).setDocumentId("doc");
    jcas.setDocumentText("one  two");
    new Token(jcas, 0, 3).addToIndexes();
    new Token(jcas, 5, 8).addToIndexes();
    new Sentence(jcas, 0, 8).addToIndexes();
    
    // NE has trailing whitespace - on export this should be silently dropped
    new NamedEntity(jcas, 0, 4).addToIndexes();
    
    writeAndAssertEquals(jcas);
}
 
Example #13
Source File: CasMergeTest.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
public void copySpanWithSlotNoStackingTest()
    throws Exception
{
    slotLayer.setOverlapMode(OverlapMode.NO_OVERLAP);
    
    JCas jcasA = createJCas(CurationTestUtils.createMultiLinkWithRoleTestTypeSystem("f1"));
    Type type = jcasA.getTypeSystem().getType(CurationTestUtils.HOST_TYPE);
    Feature feature = type.getFeatureByBaseName("f1");

    AnnotationFS clickedFs = CurationTestUtils.makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A",
            CurationTestUtils.makeLinkFS(jcasA, "slot1", 0, 0));

    JCas mergeCAs = JCasFactory
            .createJCas(CurationTestUtils.createMultiLinkWithRoleTestTypeSystem("f1"));

    CurationTestUtils.makeLinkHostMultiSPanFeatureFS(mergeCAs, 0, 0, feature, "C",
            CurationTestUtils.makeLinkFS(mergeCAs, "slot1", 0, 0));

    sut.mergeSpanAnnotation(null, null, slotLayer, mergeCAs.getCas(), clickedFs, false);

    assertEquals(1, selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
 
Example #14
Source File: ImprovedLuceneInMemorySentenceRetrievalExecutor.java    From bioasq with Apache License 2.0 6 votes vote down vote up
private HashMap<String, String> sentenceAnalysis(String sentence) {
  HashMap<String, String> dependency = new HashMap<String, String>();
  try {
    JCas snippetJcas = JCasFactory.createJCas();
    snippetJcas.setDocumentText(sentence);
    List<Token> tokens = parserProvider.parseDependency(snippetJcas);
    for (Token tok : tokens) {
      if (tok.getHead() == null)
        continue;
      dependency.put(tok.getLemmaForm(), tok.getHead().getLemmaForm());
    }
    snippetJcas.release();
  } catch (UIMAException err) {
    err.printStackTrace();
  }
  return dependency;
}
 
Example #15
Source File: DocumentGraphFactoryTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testDocumentGraphWithoutReferents() throws UIMAException {

  DocumentGraphOptions options =
      DocumentGraphOptions.builder().withReferenceTargets(false).build();
  DocumentGraphFactory factory = createfactory(options);

  JCas jCas = JCasFactory.createJCas();
  JCasTestGraphUtil.populateJcas(jCas);

  Graph graph = factory.create(jCas);

  assertEquals(0, graph.traversal().V().hasLabel(REFERENCE_TARGET).count().next().intValue());
  assertEquals(1, graph.traversal().V().hasLabel(EVENT).count().next().intValue());
  assertEquals(4, graph.traversal().V().hasLabel(MENTION).count().next().intValue());
  assertEquals(2, graph.traversal().V().hasLabel(RELATION).count().next().intValue());
  assertEquals(0, graph.traversal().E().hasLabel(MENTION_OF).count().next().intValue());
  assertEquals(2, graph.traversal().E().hasLabel(PARTICIPANT_IN).count().next().intValue());

  assertNoDocumentNode(graph);

  assertEquals(7, IteratorUtils.count(graph.vertices()));
  assertEquals(6, IteratorUtils.count(graph.edges()));
}
 
Example #16
Source File: ConceptProvider.java    From bioasq with Apache License 2.0 6 votes vote down vote up
default List<Concept> getConcepts(List<String> texts, String viewNamePrefix)
        throws AnalysisEngineProcessException {
  JCas jcas;
  try {
    jcas = JCasFactory.createJCas();
  } catch (UIMAException e) {
    throw new AnalysisEngineProcessException(e);
  }
  List<JCas> views = texts.stream().map(text -> {
    String uuid = UUID.randomUUID().toString();
    JCas view = ViewType.createView(jcas, viewNamePrefix, uuid, text);
    InputElement ie = new InputElement(view, 0, text.length());
    ie.setDataset("N/A");
    ie.setQuuid(UUID.randomUUID().toString());
    ie.addToIndexes();
    return view;
  } ).collect(Collectors.toList());
  return getConcepts(views);
}
 
Example #17
Source File: BagOfWordsCandidateRankerTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws UIMAException {
  ranker = new BagOfWordsCandidateRanker<Person>();
  ranker.initialize(ImmutableSet.of());

  JCas jCas = JCasFactory.createJCas();

  jCas.setDocumentText(
      "Sir John Major was Prime Minister of the United Kingdom. Major became Prime Minister after Thatcher resigned.");

  List<Sentence> s = Annotations.createSentences(jCas);

  Person j1 = Annotations.createPerson(jCas, 0, 14, "Sir John Major");
  Person j2 = Annotations.createPerson(jCas, 59, 64, "Major");
  ReferenceTarget jRT = Annotations.createReferenceTarget(jCas, j1, j2);

  entityInformation =
      new EntityInformation<>(jRT, ImmutableSet.of(j1, j2), ImmutableSet.copyOf(s));
}
 
Example #18
Source File: TestMistAnalysisEngine.java    From ctakes-docker with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

//        TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescriptionFromPath("../desc/TypeSystem.xml");
        JCas jcas = JCasFactory.createJCas();
        jcas.setDocumentText("Patient is a 30-year-old man named Leroy Butler from Green Bay, WI.");
        AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription(MistAnalysisEngine.class,
                MistAnalysisEngine.PARAM_MODEL_PATH,
                "SHARP/model/model");
        SimplePipeline.runPipeline(jcas, aed);
        for(Annotation annot : JCasUtil.select(jcas, Annotation.class)){
            System.out.println("Found annotation: " + annot.getCoveredText());
        }
        JCas deidView = jcas.getView(MistAnalysisEngine.DEID_VIEW_NAME);
        System.out.println("Deidentified version:");
        System.out.println(deidView.getDocumentText());
    }
 
Example #19
Source File: CasStorageServiceImplTest.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
public void testCasMetadataGetsCreated() throws Exception
{
    List<TypeSystemDescription> typeSystems = new ArrayList<>();
    typeSystems.add(createTypeSystemDescription());
    typeSystems.add(CasMetadataUtils.getInternalTypeSystem());
    
    JCas cas = JCasFactory.createJCas(mergeTypeSystems(typeSystems));
    casStorageSession.add("cas", EXCLUSIVE_WRITE_ACCESS, cas.getCas());
    
    SourceDocument doc = makeSourceDocument(1l, 1l);
    String user = "test";
    
    sut.writeCas(doc, cas.getCas(), user);
    
    JCas cas2 = sut.readCas(doc, user).getJCas();
    
    List<CASMetadata> cmds = new ArrayList<>(select(cas2, CASMetadata.class));
    assertThat(cmds).hasSize(1);
    assertThat(cmds.get(0).getProjectId()).isEqualTo(doc.getProject().getId());
    assertThat(cmds.get(0).getSourceDocumentId()).isEqualTo(doc.getId());
    assertThat(cmds.get(0).getLastChangedOnDisk())
            .isEqualTo(sut.getCasTimestamp(doc, user).get());
}
 
Example #20
Source File: WebAnnoTsv3WriterTestBase.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
public void testAnnotationWithTrailingWhitespaceAtEnd() throws Exception
{
    JCas jcas = JCasFactory.createJCas();
    
    DocumentMetaData.create(jcas).setDocumentId("doc");
    jcas.setDocumentText("one two ");
    new Token(jcas, 0, 3).addToIndexes();
    new Token(jcas, 4, 7).addToIndexes();
    new Sentence(jcas, 0, 7).addToIndexes();
    
    // NE has trailing whitespace - on export this should be silently dropped
    new NamedEntity(jcas, 4, 8).addToIndexes();
    
    writeAndAssertEquals(jcas);
}
 
Example #21
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 #22
Source File: AbstractRdfDocumentGraphConsumer.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Override
public void doInitialize(UimaContext aContext) throws ResourceInitializationException {
  outputDocument = true;

  try {
    TypeSystem typeSystem = JCasFactory.createJCas().getTypeSystem();
    OwlSchemaFactory schemaFactory =
        new OwlSchemaFactory(namespace, typeSystem, Arrays.asList(ignoreProperties));
    documentOntology = schemaFactory.createDocumentOntology();
  } catch (CASRuntimeException | UIMAException e) {
    throw new ResourceInitializationException(e);
  }
  super.doInitialize(aContext);
}
 
Example #23
Source File: AbstractRdfEntityGraphConsumer.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Override
public void doInitialize(UimaContext aContext) throws ResourceInitializationException {
  multiValueProperties = true;
  try {
    TypeSystem typeSystem = JCasFactory.createJCas().getTypeSystem();
    OwlSchemaFactory schemaFactory =
        new OwlSchemaFactory(namespace, typeSystem, Arrays.asList(ignoreProperties));
    documentOntology = schemaFactory.createEntityOntology();
  } catch (CASRuntimeException | UIMAException e) {
    throw new ResourceInitializationException(e);
  }
  super.doInitialize(aContext);
}
 
Example #24
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 #25
Source File: TableRelation.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Override
public void doInitialize(final UimaContext aContext) throws ResourceInitializationException {
  super.doInitialize(aContext);

  try {

    getMonitor().debug("The source regular expression is \"{}\"", sourcePattern);
    getMonitor().debug("The target regular expression is \"{}\"", targetPattern);
    if (!caseSensitive) {
      sourcePattern = "(?i)" + sourcePattern;
      targetPattern = "(?i)" + targetPattern;
    }

    source = Pattern.compile(sourcePattern);
    target = Pattern.compile(targetPattern);
    sourceConstructor =
        TypeUtils.getEntityClass(
                sourceType,
                JCasFactory.createJCas(TypeSystemSingleton.getTypeSystemDescriptionInstance()))
            .getConstructor(JCas.class);
    targetConstructor =
        TypeUtils.getEntityClass(
                targetType,
                JCasFactory.createJCas(TypeSystemSingleton.getTypeSystemDescriptionInstance()))
            .getConstructor(JCas.class);

  } catch (UIMAException | BaleenException | NoSuchMethodException | SecurityException e) {
    throw new ResourceInitializationException(e);
  }
}
 
Example #26
Source File: FullDocument.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Override
public void doInitialize(UimaContext aContext) throws ResourceInitializationException {
  try {
    et =
        TypeUtils.getEntityClass(
            type, JCasFactory.createJCas(TypeSystemSingleton.getTypeSystemDescriptionInstance()));
  } catch (UIMAException | BaleenException e) {
    throw new ResourceInitializationException(e);
  }
}
 
Example #27
Source File: TwoPairedKappaTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Before
public void init()
    throws Exception
{
    user1 = new User();
    user1.setUsername("user1");

    user2 = new User();
    user2.setUsername("user2");

    user3 = new User();
    user3.setUsername("user3");

    document = new SourceDocument();

    kappatestCas = JCasFactory.createJCas().getCas();
    CollectionReader reader1 = createReader(WebannoTsv2Reader.class,
            WebannoTsv2Reader.PARAM_SOURCE_LOCATION, "src/test/resources/",
            WebannoTsv2Reader.PARAM_PATTERNS, "kappatest.tsv");
    reader1.getNext(kappatestCas);

    kappaspandiff = JCasFactory.createJCas().getCas();
    CollectionReader reader2 = createReader(WebannoTsv2Reader.class,
            WebannoTsv2Reader.PARAM_SOURCE_LOCATION, "src/test/resources/",
            WebannoTsv2Reader.PARAM_PATTERNS, "kappaspandiff.tsv");
    reader2.getNext(kappaspandiff);

    kappaarcdiff = JCasFactory.createJCas().getCas();
    CollectionReader reader3 = createReader(WebannoTsv2Reader.class,
            WebannoTsv2Reader.PARAM_SOURCE_LOCATION, "src/test/resources/",
            WebannoTsv2Reader.PARAM_PATTERNS, "kappaarcdiff.tsv");
    reader3.getNext(kappaarcdiff);

    kappaspanarcdiff = JCasFactory.createJCas().getCas();
    CollectionReader reader4 = createReader(WebannoTsv2Reader.class,
            WebannoTsv2Reader.PARAM_SOURCE_LOCATION, "src/test/resources/",
            WebannoTsv2Reader.PARAM_PATTERNS, "kappaspanarcdiff.tsv");
    reader4.getNext(kappaspanarcdiff);
}
 
Example #28
Source File: TestUtil.java    From termsuite-core with Apache License 2.0 5 votes vote down vote up
public static JCas createJCas() {
	try {
		return JCasFactory.createJCas();
	} catch (UIMAException e) {
		e.printStackTrace();
		throw new RuntimeException(e);
	}
}
 
Example #29
Source File: DocumentFactoryTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void canCreateDocument() throws UIMAException {
  JCas jCas = JCasFactory.createJCas();
  DocumentFactory documentFactory = new DocumentFactory(jCas, sentenceFactory);

  Document document = documentFactory.create();
  assertNotNull(document);
}
 
Example #30
Source File: SentenceFactoryTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void canCreateSentenceWithEntities() throws UIMAException {
  JCas jCas = JCasFactory.createJCas();

  addWordTokens(jCas);

  Organisation organisation = Annotations.createOrganisation(jCas, 5, 7, "test");
  organisation.setIsNormalised(true);
  Annotations.createPerson(jCas, 10, 18, "sentence");

  SentenceFactory factory = new SentenceFactory(jCas);

  Sentence sentence = factory.create().get(0);

  assertEquals(
      ImmutableSet.of(
          MISSING_VALUE,
          Organisation.class.getSimpleName(),
          MISSING_VALUE,
          Person.class.getSimpleName(),
          MISSING_VALUE),
      ImmutableSet.copyOf(sentence.entities().get()));

  assertEquals(
      ImmutableSet.of(MISSING_VALUE, "test", MISSING_VALUE, MISSING_VALUE, MISSING_VALUE),
      ImmutableSet.copyOf(sentence.norms().get()));
}