/** * Constructor * * <p>Type system provided by {@link JCasFactory} * * @param includedTypeNames The (full) class names of the types to convert (eg * Person.class.getName()) * @throws UIMAException if type system can not be created */ public TaxonomyFactory(String[] includedTypeNames) throws UIMAException { this(JCasFactory.createJCas().getTypeSystem(), includedTypeNames); }
/** * Creates a new JCas with the given text. The type system is detected automatically using * {@link TypeSystemDescriptionFactory#createTypeSystemDescription()}. Type priorities are * detected automatically using {@link TypePrioritiesFactory#createTypePriorities()}. Indexes are * detected automatically using {@link FsIndexFactory#createFsIndexCollection()}. * * @param aText * the document text to be set in the new JCas. * @return a new JCas * @throws UIMAException * if the JCas could not be initialized */ public static JCas createText(String aText) throws UIMAException { return createText(aText, null); }
private JCas createJas() throws ResourceInitializationException { try { return JCasFactory.createJCas(TypeSystemSingleton.getTypeSystemDescriptionInstance()); } catch (UIMAException e) { throw new ResourceInitializationException(e); } }
@Test public void thatCreatingOrReadingInitialCasForNewDocumentCreatesNewCas() throws Exception { when(importExportService.importCasFromFile(any(File.class), any(Project.class), any())).thenReturn(JCasFactory.createText("Test")); SourceDocument doc = makeSourceDocument(1l, 1l, "test"); JCas cas = sut.createOrReadInitialCas(doc); assertThat(cas).isNotNull(); assertThat(cas.getDocumentText()).isEqualTo("Test"); assertThat(storageService.getCasFile(doc, WebAnnoConst.INITIAL_CAS_PSEUDO_USER)).exists(); }
/** * Constructor * * <p>Type system provided by {@link JCasFactory} * * @param includedTypeNames The (full) class names of the types to convert (eg * Person.class.getName()) * @throws UIMAException if type system can not be created */ public TaxonomyFactory(String[] includedTypeNames) throws UIMAException { this(JCasFactory.createJCas().getTypeSystem(), includedTypeNames); }
@Test public void thatReadingNonExistentAnnotationCasCreatesNewCas() throws Exception { SourceDocument sourceDocument = makeSourceDocument(1l, 1l, "test"); User user = makeUser(); when(userRepository.get(user.getUsername())).thenReturn(user); when(entityManager.createQuery(anyString(), any())).thenThrow(NoResultException.class); when(importExportService.importCasFromFile(any(File.class), any(Project.class), any())).thenReturn(JCasFactory.createText("Test")); JCas cas = sut.readAnnotationCas(sourceDocument, user.getUsername()); assertThat(cas).isNotNull(); assertThat(cas.getDocumentText()).isEqualTo("Test"); assertThat(storageService.getCasFile(sourceDocument, user.getUsername())).exists(); }
/** * Creates a new JCas from type system descriptor files. No auto-detection for type priorities, or * indexes is performed. * * @param typeSystemDescriptorPaths * paths to type system descriptor files * @return a new JCas * @throws UIMAException * if the JCas could not be initialized */ public static JCas createJCasFromPath(String... typeSystemDescriptorPaths) throws UIMAException { return createJCas(createTypeSystemDescriptionFromPath(typeSystemDescriptorPaths)); }
@Test public void testSplitSentences() throws Exception { JCas jcas = JCasFactory.createText("I am one. I am two.", "en"); ImportExportServiceImpl.splitSentences(jcas); assertEquals(asList("I am one.", "I am two."), toText(select(jcas, Sentence.class))); }
/** * This method creates a new JCas and loads the contents of an XMI or XCAS file into it. * * @param fileName * a file name for the serialized CAS data * @param typeSystemDescription * a type system description to initialize the JCas * @return a new JCas * @throws UIMAException * if the JCas could not be initialized * @throws IOException * if there is a problem reading the file */ public static JCas createJCas(String fileName, TypeSystemDescription typeSystemDescription) throws UIMAException, IOException { JCas jCas = createJCas(typeSystemDescription); CasIOUtil.readJCas(jCas, new File(fileName)); return jCas; } }
@Test public void testWriteReadExistsDeleteCas() throws Exception { SourceDocument doc = makeSourceDocument(1l, 1l); JCas cas = JCasFactory.createText("This is a test"); String user = "test"; sut.writeCas(doc, cas, user); assertThat(sut.getCasFile(doc, user)).exists(); assertThat(sut.existsCas(doc, user)).isTrue(); JCas 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(); }
@Before public void setUp() throws Exception { jCas = JCasFactory.createJCas(); outputDirectory = folder.newFolder("output"); outputDirectoryName = outputDirectory.getPath(); } }
@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); 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))); } }
private JCas readCas(Reader reader) throws UIMAException, IOException, SAXException { JCas jcas = JCasFactory .createJCas(annotationSchemaService.getFullProjectTypeSystem(project)); String xmi = IOUtils.toString(reader); // Get the annotations from the XMI are back in the CAS. XmiCasDeserializer.deserialize(new ByteArrayInputStream(xmi.getBytes()), jcas.getCas()); return jcas; }
@Test public void testReadOrCreateCas() throws Exception { SourceDocument doc = makeSourceDocument(2l, 2l); String user = "test"; JCas cas = sut.readOrCreateCas(doc, user, () -> { try { return JCasFactory.createText("This is a test"); } catch (UIMAException e) { throw new IOException(e); } }); assertThat(sut.getCasFile(doc, user)).exists(); assertThat(sut.existsCas(doc, user)).isTrue(); JCas 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(); }
public ToIOBConverter() throws Exception { jtbd = AnalysisEngineFactory.createEngine("de.julielab.jcore.ae.jtbd.desc.jcore-jtbd-ae-biomedical-english"); pennbioIEPosTagger = AnalysisEngineFactory .createEngine("de.julielab.jcore.ae.opennlp.postag.desc.jcore-opennlp-postag-ae-biomedical-english"); jCas = JCasFactory.createJCas("de.julielab.jcore.types.jcore-morpho-syntax-types"); }
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); try { File f = new File(targetFolder, DeepLearningConstants.FILENAME_TARGET_ID_TO_INDEX); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "utf-8")); writer.write( "# processing sequence of the respective document / target - prediction output should conform to this order enabling determination which document/item was classified as X" + "\n"); JCas typeFactory = JCasFactory.createJCas(); Type type = JCasUtil.getType(typeFactory, Class.forName(sequenceSpanTypeName)); AnnotationFS sequenceAnno = typeFactory.getCas().createAnnotation(type, 0, 0); sequenceSpanType = sequenceAnno.getType(); } catch (Exception e) { throw new ResourceInitializationException(e); } }
/** * Returns a JCas instance for the given typesystem. * * @param typesystem is the name of the typesystem (with our without ".xml" * extension). * @return a JCas instance for the given type system. */ public static JCas getJCas(String typesystem) { try { return JCasFactory.createJCas(getTypesystem(typesystem)); } catch (UIMAException ex) { throw new TypesystemException("getJCas failed", ex); } }
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); try { File f = new File(targetFolder, DeepLearningConstants.FILENAME_TARGET_ID_TO_INDEX); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), UTF_8)); writer.write( "# processing sequence of the respective document / target - prediction output should conform to this order enabling determination which document/item was classified as X" + "\n"); JCas typeFactory = JCasFactory.createJCas(); Type type = JCasUtil.getType(typeFactory, Class.forName(sequenceSpanTypeName)); AnnotationFS sequenceAnno = typeFactory.getCas().createAnnotation(type, 0, 0); sequenceSpanType = sequenceAnno.getType(); } catch (Exception e) { throw new ResourceInitializationException(e); } }
public JCas getJCas() throws RuntimeException { if (base64JCas == null) { return null; } try { byte[] bytes = new BASE64Decoder() .decodeBuffer(new ByteArrayInputStream(base64JCas.getBytes("utf-8"))); JCas jCas = JCasFactory.createJCas(); XmiCasDeserializer.deserialize(new ByteArrayInputStream(bytes), jCas.getCas()); return jCas; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); instanceVectorFile = new File(targetFolder, DeepLearningConstants.FILENAME_INSTANCE_VECTOR); outcomeVectorFile = new File(targetFolder, DeepLearningConstants.FILENAME_OUTCOME_VECTOR); try { if (toInteger) { loadMapping(instanceMap, DeepLearningConstants.FILENAME_INSTANCE_MAPPING); } // load the type of the annotation that holds the instances JCas typeFactory = JCasFactory.createJCas(); Type type = JCasUtil.getType(typeFactory, Class.forName(instanceTypeName)); AnnotationFS createAnnotation = typeFactory.getCas().createAnnotation(type, 0, 0); instanceType = createAnnotation.getType(); writerInstance = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(instanceVectorFile), "utf-8")); writerOutcome = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(outcomeVectorFile), "utf-8")); maximumLength = getMaximumLength(); } catch (Exception e) { throw new ResourceInitializationException(e); } }