@Test public void testProcess() throws Exception { XMLInputSource posXML = null; ResourceSpecifier posSpec = null; AnalysisEngine posAnnotator = null; posXML = new XMLInputSource("src/test/resources/POSTagAnnotatorTest.xml"); posSpec = UIMAFramework.getXMLParser().parseResourceSpecifier(posXML); posAnnotator = UIMAFramework.produceAnalysisEngine(posSpec); final JCas jcas = posAnnotator.newJCas(); initCas(jcas); posAnnotator.process(jcas, null); final JFSIndexRepository indexes = jcas.getJFSIndexRepository(); FSIterator<Annotation> tokIter = indexes.getAnnotationIndex(Token.type).iterator(); String predictedPOSTags = ""; while (tokIter.hasNext()) { final Token t = (Token) tokIter.next(); final STTSMedPOSTag tag = (STTSMedPOSTag) t.getPosTag().get(0); predictedPOSTags = predictedPOSTags + tag.getValue() + ";"; } assertEquals(postags, predictedPOSTags); tokIter = indexes.getAnnotationIndex(STTSMedPOSTag.type).iterator(); predictedPOSTags = ""; while (tokIter.hasNext()) { final STTSMedPOSTag t = (STTSMedPOSTag) tokIter.next(); predictedPOSTags = predictedPOSTags + t.getValue() + ";"; } assertEquals(postags, predictedPOSTags); }
@Override public void process(final JCas aJCas) throws AnalysisEngineProcessException { LOGGER.info("process() - processing next document"); final JFSIndexRepository indexes = aJCas.getJFSIndexRepository(); final Iterator<org.apache.uima.jcas.tcas.Annotation> sentenceIter = indexes.getAnnotationIndex(Sentence.type) .iterator(); while (sentenceIter.hasNext()) { final Sentence sentence = (Sentence) sentenceIter.next(); @SuppressWarnings("unchecked") final ArrayList<Token> tokenList = (ArrayList<Token>) UIMAUtils.getAnnotations(aJCas, sentence, new Token(aJCas, 0, 0).getClass()); final de.julielab.jcore.ae.jpos.tagger.Sentence unitSentence = createUnitSentence(tokenList, aJCas); LOGGER.debug("process() - original sentence: " + sentence.getCoveredText()); final StringBuffer unitS = new StringBuffer(); for (final Unit unit : unitSentence.getUnits()) { unitS.append(unit.getRep() + " "); } LOGGER.debug("process() - sentence for prediction: " + unitSentence.toString()); try { tagger.predictForUIMA(unitSentence); } catch (final IllegalStateException e) { LOGGER.error("process() - predicting with JPOS failed: " + e.getMessage()); throw new AnalysisEngineProcessException(); } LOGGER.debug("process() - sentence with labels: " + unitSentence.toString()); writeToCAS(unitSentence, aJCas, tokenList); } }
POSAnnotator extends JCasAnnotator_ImplBase { @Override public void process(final JCas aJCas) throws AnalysisEngineProcessException { LOGGER.info("process() - processing next document"); final JFSIndexRepository indexes = aJCas.getJFSIndexRepository(); final Iterator<org.apache.uima.jcas.tcas.Annotation> sentenceIter = indexes.getAnnotationIndex(Sentence.type) .iterator(); while (sentenceIter.hasNext()) { final Sentence sentence = (Sentence) sentenceIter.next(); @SuppressWarnings("unchecked") final ArrayList<Token> tokenList = (ArrayList<Token>) UIMAUtils.getAnnotations(aJCas, sentence, new Token(aJCas, 0, 0).getClass()); final de.julielab.jcore.ae.jpos.tagger.Sentence unitSentence = createUnitSentence(tokenList, aJCas); LOGGER.debug("process() - original sentence: " + sentence.getCoveredText()); final StringBuffer unitS = new StringBuffer(); for (final Unit unit : unitSentence.getUnits()) { unitS.append(unit.getRep() + " "); } LOGGER.debug("process() - sentence for prediction: " + unitSentence.toString()); try { tagger.predictForUIMA(unitSentence); } catch (final IllegalStateException e) { LOGGER.error("process() - predicting with JPOS failed: " + e.getMessage()); throw new AnalysisEngineProcessException(); } LOGGER.debug("process() - sentence with labels: " + unitSentence.toString()); writeToCAS(unitSentence, aJCas, tokenList); } } }
POSAnnotator extends JCasAnnotator_ImplBase { @Override public void process(final JCas aJCas) throws AnalysisEngineProcessException { LOGGER.info("process() - processing next document"); final JFSIndexRepository indexes = aJCas.getJFSIndexRepository(); final Iterator<org.apache.uima.jcas.tcas.Annotation> sentenceIter = indexes.getAnnotationIndex(Sentence.type) .iterator(); while (sentenceIter.hasNext()) { final Sentence sentence = (Sentence) sentenceIter.next(); @SuppressWarnings("unchecked") final ArrayList<Token> tokenList = (ArrayList<Token>) UIMAUtils.getAnnotations(aJCas, sentence, new Token(aJCas, 0, 0).getClass()); final de.julielab.jcore.ae.jpos.tagger.Sentence unitSentence = createUnitSentence(tokenList, aJCas); LOGGER.debug("process() - original sentence: " + sentence.getCoveredText()); final StringBuffer unitS = new StringBuffer(); for (final Unit unit : unitSentence.getUnits()) { unitS.append(unit.getRep() + " "); } LOGGER.debug("process() - sentence for prediction: " + unitSentence.toString()); try { tagger.predictForUIMA(unitSentence); } catch (final IllegalStateException e) { LOGGER.error("process() - predicting with JPOS failed: " + e.getMessage()); throw new AnalysisEngineProcessException(); } LOGGER.debug("process() - sentence with labels: " + unitSentence.toString()); writeToCAS(unitSentence, aJCas, tokenList); } }  }
POSAnnotator extends JCasAnnotator_ImplBase { @Override public void process(final JCas aJCas) throws AnalysisEngineProcessException { LOGGER.info("process() - processing next document"); final JFSIndexRepository indexes = aJCas.getJFSIndexRepository(); final Iterator<org.apache.uima.jcas.tcas.Annotation> sentenceIter = indexes.getAnnotationIndex(Sentence.type) .iterator(); while (sentenceIter.hasNext()) { final Sentence sentence = (Sentence) sentenceIter.next(); @SuppressWarnings("unchecked") final ArrayList<Token> tokenList = (ArrayList<Token>) UIMAUtils.getAnnotations(aJCas, sentence, new Token(aJCas, 0, 0).getClass()); final de.julielab.jcore.ae.jpos.tagger.Sentence unitSentence = createUnitSentence(tokenList, aJCas); LOGGER.debug("process() - original sentence: " + sentence.getCoveredText()); final StringBuffer unitS = new StringBuffer(); for (final Unit unit : unitSentence.getUnits()) { unitS.append(unit.getRep() + " "); } LOGGER.debug("process() - sentence for prediction: " + unitSentence.toString()); try { tagger.predictForUIMA(unitSentence); } catch (final IllegalStateException e) { LOGGER.error("process() - predicting with JPOS failed: " + e.getMessage()); throw new AnalysisEngineProcessException(); } LOGGER.debug("process() - sentence with labels: " + unitSentence.toString()); writeToCAS(unitSentence, aJCas, tokenList); } }  @Override void initialize(final UimaContext aContext); @Override void process(final JCas aJCas); void writeToCAS(final de.julielab.jcore.ae.jpos.tagger.Sentence unitSentence, final JCas aJCas,
            final ArrayList<Token> tokenList); }
POSAnnotator extends JCasAnnotator_ImplBase { @Override public void process(final JCas aJCas) throws AnalysisEngineProcessException { LOGGER.info("process() - processing next document"); final JFSIndexRepository indexes = aJCas.getJFSIndexRepository(); final Iterator<org.apache.uima.jcas.tcas.Annotation> sentenceIter = indexes.getAnnotationIndex(Sentence.type) .iterator(); while (sentenceIter.hasNext()) { final Sentence sentence = (Sentence) sentenceIter.next(); @SuppressWarnings("unchecked") final ArrayList<Token> tokenList = (ArrayList<Token>) UIMAUtils.getAnnotations(aJCas, sentence, new Token(aJCas, 0, 0).getClass()); final de.julielab.jcore.ae.jpos.tagger.Sentence unitSentence = createUnitSentence(tokenList, aJCas); LOGGER.debug("process() - original sentence: " + sentence.getCoveredText()); final StringBuffer unitS = new StringBuffer(); for (final Unit unit : unitSentence.getUnits()) { unitS.append(unit.getRep() + " "); } LOGGER.debug("process() - sentence for prediction: " + unitSentence.toString()); try { tagger.predictForUIMA(unitSentence); } catch (final IllegalStateException e) { LOGGER.error("process() - predicting with JPOS failed: " + e.getMessage()); throw new AnalysisEngineProcessException(); } LOGGER.debug("process() - sentence with labels: " + unitSentence.toString()); writeToCAS(unitSentence, aJCas, tokenList); } }  @Override void initialize(final UimaContext aContext); @Override void process(final JCas aJCas); void writeToCAS(final de.julielab.jcore.ae.jpos.tagger.Sentence unitSentence, final JCas aJCas,
            final ArrayList<Token> tokenList);  }