@Test public void test() throws Exception { String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/"); URL url = HtmlAnnotator.class.getClassLoader().getResource("Modifier.xml"); if (url == null) { url = HtmlAnnotator.class.getClassLoader().getResource( "org/apache/uima/ruta/engine/Modifier.xml"); } XMLInputSource in = new XMLInputSource(url); ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in); AnalysisEngineDescription aed = (AnalysisEngineDescription) specifier; TypeSystemDescription basicTypeSystem = aed.getAnalysisEngineMetaData().getTypeSystem(); for (int i = 1; i <= 20; i++) { basicTypeSystem.addType(RutaTestUtils.TYPE + i, "Type for Testing", "uima.tcas.Annotation"); } Collection<TypeSystemDescription> tsds = new ArrayList<TypeSystemDescription>(); tsds.add(basicTypeSystem); TypeSystemDescription mergeTypeSystems = CasCreationUtils.mergeTypeSystems(tsds); aed.getAnalysisEngineMetaData().setTypeSystem(mergeTypeSystems); AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(aed); ae.setConfigParameterValue(RutaModifier.PARAM_OUTPUT_LOCATION, ""); String viewName = "modified_for_testing"; ae.setConfigParameterValue(RutaModifier.PARAM_OUTPUT_VIEW, viewName); ae.reconfigure(); String scriptName = this.getClass().getSimpleName(); CAS cas = null; try { cas = RutaTestUtils.process(namespace + "/" + scriptName + RutaEngine.SCRIPT_FILE_EXTENSION, namespace + "/test.html", 50); } catch (Exception e) { e.printStackTrace(); assert (false); } ae.process(cas); CAS modifiedView = cas.getView(viewName); String text = modifiedView.getDocumentText(); assertEquals("start of bodynormal BOLDend of body" , text); cas.release(); ae.destroy(); }
@Override public void process(JCas cas) throws AnalysisEngineProcessException { try { String viewName = cas.getViewName(); if (viewName == null) { cas = cas.getView(CAS.NAME_DEFAULT_SOFA); } JCas modifiedView = null; Iterator<?> viewIterator = cas.getViewIterator(); while (viewIterator.hasNext()) { JCas each = (JCas) viewIterator.next(); if (each.getViewName().equals(modifiedViewName)) { modifiedView = each; break; } } if (modifiedView == null) { try { modifiedView = cas.createView(modifiedViewName); } catch (Exception e) { modifiedView = cas.getView(modifiedViewName); } } else { modifiedView = cas.getView(modifiedViewName); } String locate = RutaModifier.locate(styleMapLocation, descriptorPaths, ".xml", true); try { String modifiedDocument = getModifiedDocument(cas, locate); modifiedView.setDocumentText(modifiedDocument); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } String documentText = modifiedView.getDocumentText(); if (documentText != null) { File outputFile = getOutputFile(cas.getCas()); if (outputFile != null) { try { FileUtils.saveString2File(documentText, outputFile); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } } catch (CASException e) { throw new AnalysisEngineProcessException(e); } }
RutaModifier extends JCasAnnotator_ImplBase { @Override public void process(JCas cas) throws AnalysisEngineProcessException { try { String viewName = cas.getViewName(); if (viewName == null) { cas = cas.getView(CAS.NAME_DEFAULT_SOFA); } JCas modifiedView = null; Iterator<?> viewIterator = cas.getViewIterator(); while (viewIterator.hasNext()) { JCas each = (JCas) viewIterator.next(); if (each.getViewName().equals(modifiedViewName)) { modifiedView = each; break; } } if (modifiedView == null) { try { modifiedView = cas.createView(modifiedViewName); } catch (Exception e) { modifiedView = cas.getView(modifiedViewName); } } else { modifiedView = cas.getView(modifiedViewName); } String locate = RutaModifier.locate(styleMapLocation, descriptorPaths, ".xml", true); try { String modifiedDocument = getModifiedDocument(cas, locate); modifiedView.setDocumentText(modifiedDocument); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } String documentText = modifiedView.getDocumentText(); if (documentText != null) { File outputFile = getOutputFile(cas.getCas()); if (outputFile != null) { try { FileUtils.saveString2File(documentText, outputFile); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } } catch (CASException e) { throw new AnalysisEngineProcessException(e); } } }
RutaModifier extends JCasAnnotator_ImplBase { @Override public void process(JCas cas) throws AnalysisEngineProcessException { try { String viewName = cas.getViewName(); if (viewName == null) { cas = cas.getView(CAS.NAME_DEFAULT_SOFA); } JCas modifiedView = null; Iterator<?> viewIterator = cas.getViewIterator(); while (viewIterator.hasNext()) { JCas each = (JCas) viewIterator.next(); if (each.getViewName().equals(modifiedViewName)) { modifiedView = each; break; } } if (modifiedView == null) { try { modifiedView = cas.createView(modifiedViewName); } catch (Exception e) { modifiedView = cas.getView(modifiedViewName); } } else { modifiedView = cas.getView(modifiedViewName); } String locate = RutaModifier.locate(styleMapLocation, descriptorPaths, ".xml", true); try { String modifiedDocument = getModifiedDocument(cas, locate); modifiedView.setDocumentText(modifiedDocument); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } String documentText = modifiedView.getDocumentText(); if (documentText != null) { File outputFile = getOutputFile(cas.getCas()); if (outputFile != null) { try { FileUtils.saveString2File(documentText, outputFile); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } } catch (CASException e) { throw new AnalysisEngineProcessException(e); } }  }
RutaModifier extends JCasAnnotator_ImplBase { @Override public void process(JCas cas) throws AnalysisEngineProcessException { try { String viewName = cas.getViewName(); if (viewName == null) { cas = cas.getView(CAS.NAME_DEFAULT_SOFA); } JCas modifiedView = null; Iterator<?> viewIterator = cas.getViewIterator(); while (viewIterator.hasNext()) { JCas each = (JCas) viewIterator.next(); if (each.getViewName().equals(modifiedViewName)) { modifiedView = each; break; } } if (modifiedView == null) { try { modifiedView = cas.createView(modifiedViewName); } catch (Exception e) { modifiedView = cas.getView(modifiedViewName); } } else { modifiedView = cas.getView(modifiedViewName); } String locate = RutaModifier.locate(styleMapLocation, descriptorPaths, ".xml", true); try { String modifiedDocument = getModifiedDocument(cas, locate); modifiedView.setDocumentText(modifiedDocument); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } String documentText = modifiedView.getDocumentText(); if (documentText != null) { File outputFile = getOutputFile(cas.getCas()); if (outputFile != null) { try { FileUtils.saveString2File(documentText, outputFile); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } } catch (CASException e) { throw new AnalysisEngineProcessException(e); } }  @Override void initialize(UimaContext aContext); @Override void process(JCas cas); static String locate(String name, String[] paths, String suffix, boolean mustExist); }
RutaModifier extends JCasAnnotator_ImplBase { @Override public void process(JCas cas) throws AnalysisEngineProcessException { try { String viewName = cas.getViewName(); if (viewName == null) { cas = cas.getView(CAS.NAME_DEFAULT_SOFA); } JCas modifiedView = null; Iterator<?> viewIterator = cas.getViewIterator(); while (viewIterator.hasNext()) { JCas each = (JCas) viewIterator.next(); if (each.getViewName().equals(modifiedViewName)) { modifiedView = each; break; } } if (modifiedView == null) { try { modifiedView = cas.createView(modifiedViewName); } catch (Exception e) { modifiedView = cas.getView(modifiedViewName); } } else { modifiedView = cas.getView(modifiedViewName); } String locate = RutaModifier.locate(styleMapLocation, descriptorPaths, ".xml", true); try { String modifiedDocument = getModifiedDocument(cas, locate); modifiedView.setDocumentText(modifiedDocument); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } String documentText = modifiedView.getDocumentText(); if (documentText != null) { File outputFile = getOutputFile(cas.getCas()); if (outputFile != null) { try { FileUtils.saveString2File(documentText, outputFile); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } } catch (CASException e) { throw new AnalysisEngineProcessException(e); } }  @Override void initialize(UimaContext aContext); @Override void process(JCas cas); static String locate(String name, String[] paths, String suffix, boolean mustExist); static final String DEFAULT_MODIFIED_VIEW; static final String PARAM_OUTPUT_LOCATION; static final String PARAM_STYLE_MAP; static final String PARAM_OUTPUT_VIEW; static final String PARAM_DESCRIPTOR_PATHS; }