@Test public void test() throws Exception { JCas jcas = JCasFactory.createJCas(); AnalysisEngine cutter = AnalysisEngineFactory.createEngine(RutaCutter.class, RutaCutter.PARAM_KEEP, TruePositive.class.getName()); jcas.setDocumentText("Some text."); Ruta.apply(jcas.getCas(), "SW{-> TruePositive};"); cutter.process(jcas); Collection<TruePositive> select = JCasUtil.select(jcas, TruePositive.class); Assert.assertEquals(1, select.size()); TruePositive truePositive = select.iterator().next(); Assert.assertEquals(5, truePositive.getBegin()); JCas cuttedView = jcas.getView("cutted"); Assert.assertEquals("text", cuttedView.getDocumentText()); select = JCasUtil.select(cuttedView, TruePositive.class); Assert.assertEquals(1, select.size()); truePositive = select.iterator().next(); Assert.assertEquals(0, truePositive.getBegin()); jcas.release(); cutter.destroy(); }
@Override public void process(JCas jcaz) throws AnalysisEngineProcessException { JCas jcas; try { if (inputViewName != null) { jcas = jcaz.getView(inputViewName); } else { jcas = jcaz; } } catch (CASException e1) { throw new AnalysisEngineProcessException(e1.getCause()); } String documentText = jcas.getDocumentText(); map = new int[documentText.length() + 1]; JCas modview = null; try { Iterator<JCas> viewIterator = jcas.getViewIterator(); while (viewIterator.hasNext()) { JCas jCas2 = viewIterator.next(); if (jCas2.getViewName().equals(outputViewName)) { modview = jCas2; getContext().getLogger().log(Level.WARNING, "view with name \"" + outputViewName + "\" already exists."); } } if (modview == null) { modview = jcas.createView(outputViewName); } } catch (CASException e) { e.printStackTrace(); return; } SortedSet<HtmlConverterPSpan> visibleSpansSoFar = new TreeSet<HtmlConverterPSpan>(); TypeSystem typeSystem = jcas.getTypeSystem(); Type keepType = typeSystem.getType(keep); if (keepType == null) { Iterator<Type> typeIterator = typeSystem.getTypeIterator(); while (typeIterator.hasNext()) { Type type = typeIterator.next(); String shortName = type.getShortName(); if (shortName.equals(keep)) { keepType = type; break; } } if (keepType == null) { getContext().getLogger().log(Level.WARNING, "Type \"" + keep + "\" not defined."); return; } } AnnotationIndex<AnnotationFS> annotationIndex = jcas.getCas().getAnnotationIndex(keepType); for (AnnotationFS each : annotationIndex) { visibleSpansSoFar.add(new HtmlConverterPSpan(each.getBegin(), each.getEnd(), each .getCoveredText())); } StringBuffer sbu = new StringBuffer(documentText.length()); int originalOffsetI = 0; int outOffset = 0; for (HtmlConverterPSpan vis : visibleSpansSoFar) { final int begin = vis.getBegin(); final int end = vis.getEnd(); while (originalOffsetI < begin) { map[originalOffsetI++] = outOffset; } String s = ""; if (vis instanceof HtmlConverterPSpanReplacement) { s = vis.getTxt(); while (originalOffsetI < begin + s.length()) { map[originalOffsetI++] = outOffset++; } while (originalOffsetI < end) { map[originalOffsetI++] = outOffset; } } else { s = documentText.substring(begin, end); while (originalOffsetI < end) { map[originalOffsetI++] = outOffset++; } } sbu.append(s); } while (originalOffsetI < documentText.length()) { map[originalOffsetI++] = outOffset; } map[documentText.length()] = outOffset + 1; String modTxt = sbu.toString(); modview.setDocumentText(modTxt); try { mapAnnotations(jcas, map, outputViewName); } catch (CASException e) { e.printStackTrace(); } }
RutaCutter extends JCasAnnotator_ImplBase { @Override public void process(JCas jcaz) throws AnalysisEngineProcessException { JCas jcas; try { if (inputViewName != null) { jcas = jcaz.getView(inputViewName); } else { jcas = jcaz; } } catch (CASException e1) { throw new AnalysisEngineProcessException(e1.getCause()); } String documentText = jcas.getDocumentText(); map = new int[documentText.length() + 1]; JCas modview = null; try { Iterator<JCas> viewIterator = jcas.getViewIterator(); while (viewIterator.hasNext()) { JCas jCas2 = viewIterator.next(); if (jCas2.getViewName().equals(outputViewName)) { modview = jCas2; getContext().getLogger().log(Level.WARNING, "view with name \"" + outputViewName + "\" already exists."); } } if (modview == null) { modview = jcas.createView(outputViewName); } } catch (CASException e) { e.printStackTrace(); return; } SortedSet<HtmlConverterPSpan> visibleSpansSoFar = new TreeSet<HtmlConverterPSpan>(); TypeSystem typeSystem = jcas.getTypeSystem(); Type keepType = typeSystem.getType(keep); if (keepType == null) { Iterator<Type> typeIterator = typeSystem.getTypeIterator(); while (typeIterator.hasNext()) { Type type = typeIterator.next(); String shortName = type.getShortName(); if (shortName.equals(keep)) { keepType = type; break; } } if (keepType == null) { getContext().getLogger().log(Level.WARNING, "Type \"" + keep + "\" not defined."); return; } } AnnotationIndex<AnnotationFS> annotationIndex = jcas.getCas().getAnnotationIndex(keepType); for (AnnotationFS each : annotationIndex) { visibleSpansSoFar.add(new HtmlConverterPSpan(each.getBegin(), each.getEnd(), each .getCoveredText())); } StringBuffer sbu = new StringBuffer(documentText.length()); int originalOffsetI = 0; int outOffset = 0; for (HtmlConverterPSpan vis : visibleSpansSoFar) { final int begin = vis.getBegin(); final int end = vis.getEnd(); while (originalOffsetI < begin) { map[originalOffsetI++] = outOffset; } String s = ""; if (vis instanceof HtmlConverterPSpanReplacement) { s = vis.getTxt(); while (originalOffsetI < begin + s.length()) { map[originalOffsetI++] = outOffset++; } while (originalOffsetI < end) { map[originalOffsetI++] = outOffset; } } else { s = documentText.substring(begin, end); while (originalOffsetI < end) { map[originalOffsetI++] = outOffset++; } } sbu.append(s); } while (originalOffsetI < documentText.length()) { map[originalOffsetI++] = outOffset; } map[documentText.length()] = outOffset + 1; String modTxt = sbu.toString(); modview.setDocumentText(modTxt); try { mapAnnotations(jcas, map, outputViewName); } catch (CASException e) { e.printStackTrace(); } } }
RutaCutter extends JCasAnnotator_ImplBase { @Override public void process(JCas jcaz) throws AnalysisEngineProcessException { JCas jcas; try { if (inputViewName != null) { jcas = jcaz.getView(inputViewName); } else { jcas = jcaz; } } catch (CASException e1) { throw new AnalysisEngineProcessException(e1.getCause()); } String documentText = jcas.getDocumentText(); map = new int[documentText.length() + 1]; JCas modview = null; try { Iterator<JCas> viewIterator = jcas.getViewIterator(); while (viewIterator.hasNext()) { JCas jCas2 = viewIterator.next(); if (jCas2.getViewName().equals(outputViewName)) { modview = jCas2; getContext().getLogger().log(Level.WARNING, "view with name \"" + outputViewName + "\" already exists."); } } if (modview == null) { modview = jcas.createView(outputViewName); } } catch (CASException e) { e.printStackTrace(); return; } SortedSet<HtmlConverterPSpan> visibleSpansSoFar = new TreeSet<HtmlConverterPSpan>(); TypeSystem typeSystem = jcas.getTypeSystem(); Type keepType = typeSystem.getType(keep); if (keepType == null) { Iterator<Type> typeIterator = typeSystem.getTypeIterator(); while (typeIterator.hasNext()) { Type type = typeIterator.next(); String shortName = type.getShortName(); if (shortName.equals(keep)) { keepType = type; break; } } if (keepType == null) { getContext().getLogger().log(Level.WARNING, "Type \"" + keep + "\" not defined."); return; } } AnnotationIndex<AnnotationFS> annotationIndex = jcas.getCas().getAnnotationIndex(keepType); for (AnnotationFS each : annotationIndex) { visibleSpansSoFar.add(new HtmlConverterPSpan(each.getBegin(), each.getEnd(), each .getCoveredText())); } StringBuffer sbu = new StringBuffer(documentText.length()); int originalOffsetI = 0; int outOffset = 0; for (HtmlConverterPSpan vis : visibleSpansSoFar) { final int begin = vis.getBegin(); final int end = vis.getEnd(); while (originalOffsetI < begin) { map[originalOffsetI++] = outOffset; } String s = ""; if (vis instanceof HtmlConverterPSpanReplacement) { s = vis.getTxt(); while (originalOffsetI < begin + s.length()) { map[originalOffsetI++] = outOffset++; } while (originalOffsetI < end) { map[originalOffsetI++] = outOffset; } } else { s = documentText.substring(begin, end); while (originalOffsetI < end) { map[originalOffsetI++] = outOffset++; } } sbu.append(s); } while (originalOffsetI < documentText.length()) { map[originalOffsetI++] = outOffset; } map[documentText.length()] = outOffset + 1; String modTxt = sbu.toString(); modview.setDocumentText(modTxt); try { mapAnnotations(jcas, map, outputViewName); } catch (CASException e) { e.printStackTrace(); } }  }
RutaCutter extends JCasAnnotator_ImplBase { @Override public void process(JCas jcaz) throws AnalysisEngineProcessException { JCas jcas; try { if (inputViewName != null) { jcas = jcaz.getView(inputViewName); } else { jcas = jcaz; } } catch (CASException e1) { throw new AnalysisEngineProcessException(e1.getCause()); } String documentText = jcas.getDocumentText(); map = new int[documentText.length() + 1]; JCas modview = null; try { Iterator<JCas> viewIterator = jcas.getViewIterator(); while (viewIterator.hasNext()) { JCas jCas2 = viewIterator.next(); if (jCas2.getViewName().equals(outputViewName)) { modview = jCas2; getContext().getLogger().log(Level.WARNING, "view with name \"" + outputViewName + "\" already exists."); } } if (modview == null) { modview = jcas.createView(outputViewName); } } catch (CASException e) { e.printStackTrace(); return; } SortedSet<HtmlConverterPSpan> visibleSpansSoFar = new TreeSet<HtmlConverterPSpan>(); TypeSystem typeSystem = jcas.getTypeSystem(); Type keepType = typeSystem.getType(keep); if (keepType == null) { Iterator<Type> typeIterator = typeSystem.getTypeIterator(); while (typeIterator.hasNext()) { Type type = typeIterator.next(); String shortName = type.getShortName(); if (shortName.equals(keep)) { keepType = type; break; } } if (keepType == null) { getContext().getLogger().log(Level.WARNING, "Type \"" + keep + "\" not defined."); return; } } AnnotationIndex<AnnotationFS> annotationIndex = jcas.getCas().getAnnotationIndex(keepType); for (AnnotationFS each : annotationIndex) { visibleSpansSoFar.add(new HtmlConverterPSpan(each.getBegin(), each.getEnd(), each .getCoveredText())); } StringBuffer sbu = new StringBuffer(documentText.length()); int originalOffsetI = 0; int outOffset = 0; for (HtmlConverterPSpan vis : visibleSpansSoFar) { final int begin = vis.getBegin(); final int end = vis.getEnd(); while (originalOffsetI < begin) { map[originalOffsetI++] = outOffset; } String s = ""; if (vis instanceof HtmlConverterPSpanReplacement) { s = vis.getTxt(); while (originalOffsetI < begin + s.length()) { map[originalOffsetI++] = outOffset++; } while (originalOffsetI < end) { map[originalOffsetI++] = outOffset; } } else { s = documentText.substring(begin, end); while (originalOffsetI < end) { map[originalOffsetI++] = outOffset++; } } sbu.append(s); } while (originalOffsetI < documentText.length()) { map[originalOffsetI++] = outOffset; } map[documentText.length()] = outOffset + 1; String modTxt = sbu.toString(); modview.setDocumentText(modTxt); try { mapAnnotations(jcas, map, outputViewName); } catch (CASException e) { e.printStackTrace(); } }  @Override void initialize(UimaContext aContext); @Override void process(JCas jcaz); }
RutaCutter extends JCasAnnotator_ImplBase { @Override public void process(JCas jcaz) throws AnalysisEngineProcessException { JCas jcas; try { if (inputViewName != null) { jcas = jcaz.getView(inputViewName); } else { jcas = jcaz; } } catch (CASException e1) { throw new AnalysisEngineProcessException(e1.getCause()); } String documentText = jcas.getDocumentText(); map = new int[documentText.length() + 1]; JCas modview = null; try { Iterator<JCas> viewIterator = jcas.getViewIterator(); while (viewIterator.hasNext()) { JCas jCas2 = viewIterator.next(); if (jCas2.getViewName().equals(outputViewName)) { modview = jCas2; getContext().getLogger().log(Level.WARNING, "view with name \"" + outputViewName + "\" already exists."); } } if (modview == null) { modview = jcas.createView(outputViewName); } } catch (CASException e) { e.printStackTrace(); return; } SortedSet<HtmlConverterPSpan> visibleSpansSoFar = new TreeSet<HtmlConverterPSpan>(); TypeSystem typeSystem = jcas.getTypeSystem(); Type keepType = typeSystem.getType(keep); if (keepType == null) { Iterator<Type> typeIterator = typeSystem.getTypeIterator(); while (typeIterator.hasNext()) { Type type = typeIterator.next(); String shortName = type.getShortName(); if (shortName.equals(keep)) { keepType = type; break; } } if (keepType == null) { getContext().getLogger().log(Level.WARNING, "Type \"" + keep + "\" not defined."); return; } } AnnotationIndex<AnnotationFS> annotationIndex = jcas.getCas().getAnnotationIndex(keepType); for (AnnotationFS each : annotationIndex) { visibleSpansSoFar.add(new HtmlConverterPSpan(each.getBegin(), each.getEnd(), each .getCoveredText())); } StringBuffer sbu = new StringBuffer(documentText.length()); int originalOffsetI = 0; int outOffset = 0; for (HtmlConverterPSpan vis : visibleSpansSoFar) { final int begin = vis.getBegin(); final int end = vis.getEnd(); while (originalOffsetI < begin) { map[originalOffsetI++] = outOffset; } String s = ""; if (vis instanceof HtmlConverterPSpanReplacement) { s = vis.getTxt(); while (originalOffsetI < begin + s.length()) { map[originalOffsetI++] = outOffset++; } while (originalOffsetI < end) { map[originalOffsetI++] = outOffset; } } else { s = documentText.substring(begin, end); while (originalOffsetI < end) { map[originalOffsetI++] = outOffset++; } } sbu.append(s); } while (originalOffsetI < documentText.length()) { map[originalOffsetI++] = outOffset; } map[documentText.length()] = outOffset + 1; String modTxt = sbu.toString(); modview.setDocumentText(modTxt); try { mapAnnotations(jcas, map, outputViewName); } catch (CASException e) { e.printStackTrace(); } }  @Override void initialize(UimaContext aContext); @Override void process(JCas jcaz); static final String PARAM_OUTPUT_VIEW; static final String PARAM_INPUT_VIEW; static final String PARAM_KEEP; }