Java Code Examples for org.apache.uima.resource.metadata.TypeSystemDescription#toXML()
The following examples show how to use
org.apache.uima.resource.metadata.TypeSystemDescription#toXML() .
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: LayerDetailForm.java From webanno with Apache License 2.0 | 6 votes |
private IResourceStream exportUimaTypeSystem() { try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { TypeSystemDescription tsd = annotationService .getAllProjectTypes(getModelObject().getProject()); tsd.toXML(bos); return new InputStreamResourceStream(new ByteArrayInputStream(bos.toByteArray())); } catch (Exception e) { error("Unable to generate the UIMA type system file: " + ExceptionUtils.getRootCauseMessage(e)); ProjectLayersPanel.LOG.error("Unable to generate the UIMA type system file", e); RequestCycle.get().find(IPartialPageRequestHandler.class) .ifPresent(handler -> handler.addChildren(getPage(), IFeedback.class)); return null; } }
Example 2
Source File: TypeSystemUtilTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testTypeSystem2TypeSystemDescription() throws Exception { //create a CAS with example type system File typeSystemFile = JUnitExtension.getFile("ExampleCas/testTypeSystem.xml"); TypeSystemDescription tsDesc = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(typeSystemFile)); //add an example type to test FSArrays with and without elementTypes TypeDescription type = tsDesc.addType("example.TestType", "", "uima.tcas.Annotation"); type.addFeature("testFeat", "", "uima.cas.FSArray","uima.tcas.Annotation", null); TypeDescription type2 = tsDesc.addType("example.TestType2", "", "uima.tcas.Annotation"); type2.addFeature("testFeat", "", "uima.cas.FSArray"); CAS cas = CasCreationUtils.createCas(tsDesc, null, null); //convert that CAS's type system back to a TypeSystemDescription TypeSystemDescription tsDesc2 = TypeSystemUtil.typeSystem2TypeSystemDescription(cas.getTypeSystem()); //test that this is valid by creating a new CAS CasCreationUtils.createCas(tsDesc2, null, null); // Check that can be written (without cluttering up the console) StringWriter out = new StringWriter(); tsDesc2.toXML(out); }
Example 3
Source File: TypeSystemWriter.java From biomedicus with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} <p>Writes the type system to the path if it hasn't already been written. Uses the * semaphore with 1 permit {@code writeOnce}.</p> */ public void writeToPath(Path path) throws BiomedicusException { if (writeOnce.tryAcquire()) { try (BufferedWriter bufferedWriter = Files.newBufferedWriter(path)) { TypeSystemDescription description = getCasManager().getCasDefinition().getTypeSystemDescription(); description.toXML(bufferedWriter); } catch (IOException | ResourceInitializationException | SAXException e) { throw new BiomedicusException(e); } } }
Example 4
Source File: Ecore2UimaTypeSystem.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Main program. Takes two arguments: the filename of an input .ecore file and the filename of the * UIMA TypeSystem file to generate. * * @param args the arguments * @throws Exception the exception */ public static void main(String[] args) throws Exception { if (args.length != 2) { System.err.println("Usage: java " + Ecore2UimaTypeSystem.class.getName() + " <ecore filename> <filename of UIMA TypeSystem file to generate>"); return; } if (!new File(args[0]).exists()) { System.err.println("File " + args[0] + " does not exist"); return; } Map options = new HashMap(); // options.put(OPTION_GENERATE_UIMA_LIST_TYPES, Boolean.TRUE); TypeSystemDescription tsDesc = ecore2UimaTypeSystem(args[0], options); try (FileOutputStream os = new FileOutputStream(args[1])) { tsDesc.toXML(os); } // test creating a CAS try { CasCreationUtils.createCas(tsDesc, null, new FsIndexDescription[0]); } catch (Exception e) { System.err .println("Warning: CAS could not be created from the output type system. The following problem occurred:"); System.err.println(e.getMessage()); } }