@Test public void test() throws Exception { String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/"); String name = namespace + "/" + "test.html"; URL textURL = HtmlAnnotatorTest.class.getClassLoader().getResource(name); File textFile = new File(textURL.toURI()); String html = FileUtils.file2String(textFile, "UTF-8"); URL url = HtmlAnnotator.class.getClassLoader().getResource("HtmlAnnotator.xml"); if (url == null) { url = HtmlAnnotator.class.getClassLoader().getResource( "org/apache/uima/ruta/engine/HtmlAnnotator.xml"); } XMLInputSource in = new XMLInputSource(url); ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in); AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier); CAS cas = ae.newCAS(); Type tagType = cas.getTypeSystem().getType(HtmlAnnotator.NAMESPACE + "TAG"); AnnotationIndex<AnnotationFS> ai = null; FSIterator<AnnotationFS> iterator = null; ae.setConfigParameterValue("onlyContent", false); ae.reconfigure(); cas.reset(); cas.setDocumentText(html); ae.process(cas); ai = cas.getAnnotationIndex(tagType); iterator = ai.iterator(); assertEquals(7, ai.size()); AnnotationFS a = iterator.next(); assertEquals("HTML", a.getType().getShortName()); assertEquals(0, a.getBegin()); assertEquals(127, a.getEnd()); a = iterator.next(); assertEquals("HEAD", a.getType().getShortName()); assertEquals(8, a.getBegin()); assertEquals(39, a.getEnd()); a = iterator.next(); assertEquals("REMARK", a.getType().getShortName()); assertEquals(16, a.getBegin()); assertEquals(30, a.getEnd()); a = iterator.next(); assertEquals("BODY", a.getType().getShortName()); assertEquals(41, a.getBegin()); assertEquals(118, a.getEnd()); a = iterator.next(); assertEquals("BR", a.getType().getShortName()); assertEquals(64, a.getBegin()); assertEquals(69, a.getEnd()); a = iterator.next(); assertEquals("B", a.getType().getShortName()); assertEquals(78, a.getBegin()); assertEquals(89, a.getEnd()); a = iterator.next(); assertEquals("BR", a.getType().getShortName()); assertEquals(91, a.getBegin()); assertEquals(96, a.getEnd()); ae.setConfigParameterValue("onlyContent", true); ae.reconfigure(); cas.reset(); cas.setDocumentText(html); ae.process(cas); ai = cas.getAnnotationIndex(tagType); iterator = ai.iterator(); assertEquals(4, ai.size()); a = iterator.next(); assertEquals("HTML", a.getType().getShortName()); assertEquals(6, a.getBegin()); assertEquals(120, a.getEnd()); a = iterator.next(); assertEquals("HEAD", a.getType().getShortName()); assertEquals(14, a.getBegin()); assertEquals(32, a.getEnd()); a = iterator.next(); assertEquals("BODY", a.getType().getShortName()); assertEquals(47, a.getBegin()); assertEquals(111, a.getEnd()); a = iterator.next(); assertEquals("B", a.getType().getShortName()); assertEquals(81, a.getBegin()); assertEquals(85, a.getEnd()); cas.release(); }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { String documentText = jcas.getDocumentText(); List<AnnotationFS> annotations = new ArrayList<AnnotationFS>(); List<AnnotationFS> annotationStack = new ArrayList<AnnotationFS>(); try { Parser parser = new Parser(documentText); NodeList list = parser.parse(null); HtmlVisitor visitor = new HtmlVisitor(jcas, onlyContent); list.visitAllNodesWith(visitor); annotations = visitor.getAnnotations(); annotationStack = visitor.getAnnotationStack(); } catch (ParserException e) { throw new AnalysisEngineProcessException(e); } for (AnnotationFS each : annotations) { if (each.getBegin() < each.getEnd()) { jcas.addFsToIndexes(each); } } for (AnnotationFS each : annotationStack) { if (each.getBegin() < each.getEnd()) { jcas.addFsToIndexes(each); } } }
HtmlAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { String documentText = jcas.getDocumentText(); List<AnnotationFS> annotations = new ArrayList<AnnotationFS>(); List<AnnotationFS> annotationStack = new ArrayList<AnnotationFS>(); try { Parser parser = new Parser(documentText); NodeList list = parser.parse(null); HtmlVisitor visitor = new HtmlVisitor(jcas, onlyContent); list.visitAllNodesWith(visitor); annotations = visitor.getAnnotations(); annotationStack = visitor.getAnnotationStack(); } catch (ParserException e) { throw new AnalysisEngineProcessException(e); } for (AnnotationFS each : annotations) { if (each.getBegin() < each.getEnd()) { jcas.addFsToIndexes(each); } } for (AnnotationFS each : annotationStack) { if (each.getBegin() < each.getEnd()) { jcas.addFsToIndexes(each); } } } }
HtmlAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { String documentText = jcas.getDocumentText(); List<AnnotationFS> annotations = new ArrayList<AnnotationFS>(); List<AnnotationFS> annotationStack = new ArrayList<AnnotationFS>(); try { Parser parser = new Parser(documentText); NodeList list = parser.parse(null); HtmlVisitor visitor = new HtmlVisitor(jcas, onlyContent); list.visitAllNodesWith(visitor); annotations = visitor.getAnnotations(); annotationStack = visitor.getAnnotationStack(); } catch (ParserException e) { throw new AnalysisEngineProcessException(e); } for (AnnotationFS each : annotations) { if (each.getBegin() < each.getEnd()) { jcas.addFsToIndexes(each); } } for (AnnotationFS each : annotationStack) { if (each.getBegin() < each.getEnd()) { jcas.addFsToIndexes(each); } } }  }
HtmlAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { String documentText = jcas.getDocumentText(); List<AnnotationFS> annotations = new ArrayList<AnnotationFS>(); List<AnnotationFS> annotationStack = new ArrayList<AnnotationFS>(); try { Parser parser = new Parser(documentText); NodeList list = parser.parse(null); HtmlVisitor visitor = new HtmlVisitor(jcas, onlyContent); list.visitAllNodesWith(visitor); annotations = visitor.getAnnotations(); annotationStack = visitor.getAnnotationStack(); } catch (ParserException e) { throw new AnalysisEngineProcessException(e); } for (AnnotationFS each : annotations) { if (each.getBegin() < each.getEnd()) { jcas.addFsToIndexes(each); } } for (AnnotationFS each : annotationStack) { if (each.getBegin() < each.getEnd()) { jcas.addFsToIndexes(each); } } }  @Override void initialize(UimaContext aContext); @Override void process(JCas jcas); }
HtmlAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { String documentText = jcas.getDocumentText(); List<AnnotationFS> annotations = new ArrayList<AnnotationFS>(); List<AnnotationFS> annotationStack = new ArrayList<AnnotationFS>(); try { Parser parser = new Parser(documentText); NodeList list = parser.parse(null); HtmlVisitor visitor = new HtmlVisitor(jcas, onlyContent); list.visitAllNodesWith(visitor); annotations = visitor.getAnnotations(); annotationStack = visitor.getAnnotationStack(); } catch (ParserException e) { throw new AnalysisEngineProcessException(e); } for (AnnotationFS each : annotations) { if (each.getBegin() < each.getEnd()) { jcas.addFsToIndexes(each); } } for (AnnotationFS each : annotationStack) { if (each.getBegin() < each.getEnd()) { jcas.addFsToIndexes(each); } } }  @Override void initialize(UimaContext aContext); @Override void process(JCas jcas); static final String NAMESPACE; static final String PARAM_ONLY_CONTENT; }