@Test public void testParseDate() throws UIMAException { JCas jCas = JCasFactory.createJCasFromPath(TYPESYSTEM_URL.getPath()); assertNotNull("Expecting a valid JCas object (second time loaded)", jCas); java.util.Date dtExpected = new java.util.Date(); String sExpected = dtExpected.toString(); LOGGER.info(String.format("date to be annotated: %s", sExpected)); jCas.setDocumentText(sExpected); DateAnnotation ctakesDate = new DateAnnotation(jCas); ctakesDate.setBegin(0); ctakesDate.setEnd(sExpected.length()); ctakesDate.addToIndexes(); DateAnnotator dateAnnotator = new DateAnnotator(); dateAnnotator.dateType = Date.class.getName(); dateAnnotator.process(jCas); LOGGER.info(String.format("Using org.apache.ctakes.ytex.uima.types.Date.type: %d", Date.type)); AnnotationIndex<Annotation> ytexDates = jCas.getAnnotationIndex(Date.type); for (FSIterator<Annotation> it = ytexDates.iterator(); it.hasNext(); ) { Annotation a = it.next(); LOGGER.info(String.format("[%s]", a)); } LOGGER.info(String.format("ytexDates.size: %d", ytexDates.size())); assertEquals("Expecting ytexDates to have 2 elements", 2, ytexDates.size()); String sParsed = ((Date)ytexDates.iterator().next()).getDate(); assertNotNull("Expected a parsed Date string", sParsed); LOGGER.info(String.format("date from annotation: %s", sParsed)); java.util.Date dtParsed = null; try { dtParsed = new SimpleDateFormat(DateAnnotator.DATE_FORMAT).parse(sParsed); } catch (ParseException e) { assertFalse("Expected a real java.util.Date object", true); } assertNotNull("Expected a not NULL java.util.Date object", dtParsed); assertTrue("Expected what we converted .toString to be parsed", (dtExpected.getTime() - dtParsed.getTime()) < 1000 ); }
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { Type t = jCas.getTypeSystem().getType(dateType); if (t != null) { AnnotationIndex<Annotation> annoIndex = jCas.getAnnotationIndex(); FSIterator<Annotation> iter = annoIndex.iterator(); while (iter.hasNext()) { Annotation anno = iter.next(); try { Span span = Chronic.parse(anno.getCoveredText()); if (span != null && span.getBeginCalendar() != null) { Date date = new Date(jCas); date.setBegin(anno.getBegin()); date.setEnd(anno.getEnd()); date.setDate(tlDateFormat.get().format( span.getBeginCalendar().getTime())); date.addToIndexes(); } } catch (Exception e) { if (log.isDebugEnabled()) log.debug( "chronic failed on: " + anno.getCoveredText(), e); } } } }
DateAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jCas) throws AnalysisEngineProcessException { Type t = jCas.getTypeSystem().getType(dateType); if (t != null) { AnnotationIndex<Annotation> annoIndex = jCas.getAnnotationIndex(); FSIterator<Annotation> iter = annoIndex.iterator(); while (iter.hasNext()) { Annotation anno = iter.next(); try { Span span = Chronic.parse(anno.getCoveredText()); if (span != null && span.getBeginCalendar() != null) { Date date = new Date(jCas); date.setBegin(anno.getBegin()); date.setEnd(anno.getEnd()); date.setDate(tlDateFormat.get().format( span.getBeginCalendar().getTime())); date.addToIndexes(); } } catch (Exception e) { if (log.isDebugEnabled()) log.debug( "chronic failed on: " + anno.getCoveredText(), e); } } } } }
DateAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jCas) throws AnalysisEngineProcessException { Type t = jCas.getTypeSystem().getType(dateType); if (t != null) { AnnotationIndex<Annotation> annoIndex = jCas.getAnnotationIndex(); FSIterator<Annotation> iter = annoIndex.iterator(); while (iter.hasNext()) { Annotation anno = iter.next(); try { Span span = Chronic.parse(anno.getCoveredText()); if (span != null && span.getBeginCalendar() != null) { Date date = new Date(jCas); date.setBegin(anno.getBegin()); date.setEnd(anno.getEnd()); date.setDate(tlDateFormat.get().format( span.getBeginCalendar().getTime())); date.addToIndexes(); } } catch (Exception e) { if (log.isDebugEnabled()) log.debug( "chronic failed on: " + anno.getCoveredText(), e); } } } }  }
DateAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jCas) throws AnalysisEngineProcessException { Type t = jCas.getTypeSystem().getType(dateType); if (t != null) { AnnotationIndex<Annotation> annoIndex = jCas.getAnnotationIndex(); FSIterator<Annotation> iter = annoIndex.iterator(); while (iter.hasNext()) { Annotation anno = iter.next(); try { Span span = Chronic.parse(anno.getCoveredText()); if (span != null && span.getBeginCalendar() != null) { Date date = new Date(jCas); date.setBegin(anno.getBegin()); date.setEnd(anno.getEnd()); date.setDate(tlDateFormat.get().format( span.getBeginCalendar().getTime())); date.addToIndexes(); } } catch (Exception e) { if (log.isDebugEnabled()) log.debug( "chronic failed on: " + anno.getCoveredText(), e); } } } }  @Override void initialize(UimaContext aContext); @Override void process(JCas jCas); }
DateAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jCas) throws AnalysisEngineProcessException { Type t = jCas.getTypeSystem().getType(dateType); if (t != null) { AnnotationIndex<Annotation> annoIndex = jCas.getAnnotationIndex(); FSIterator<Annotation> iter = annoIndex.iterator(); while (iter.hasNext()) { Annotation anno = iter.next(); try { Span span = Chronic.parse(anno.getCoveredText()); if (span != null && span.getBeginCalendar() != null) { Date date = new Date(jCas); date.setBegin(anno.getBegin()); date.setEnd(anno.getEnd()); date.setDate(tlDateFormat.get().format( span.getBeginCalendar().getTime())); date.addToIndexes(); } } catch (Exception e) { if (log.isDebugEnabled()) log.debug( "chronic failed on: " + anno.getCoveredText(), e); } } } }  @Override void initialize(UimaContext aContext); @Override void process(JCas jCas); static final String DATE_FORMAT; }