RelativeDate extends BaleenTextAwareAnnotator { private void nextLastWeek(TextBlock block) { Pattern p = Pattern.compile( "\\b((in the|within the|" + DAYS + ") )?(next|last) week\\b", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(block.getCoveredText()); while (m.find()) { if (m.group(3) != null) { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeWeekDay(block, m.start(), m.end(), 1, DateTimeUtils.asDay(m.group(3))); } else { createRelativeWeekDay(block, m.start(), m.end(), -1, DateTimeUtils.asDay(m.group(3))); } } else if (m.group(2) != null) { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeWeekPeriod(block, m.start(), m.end(), 1); } else { createRelativeWeekPeriod(block, m.start(), m.end(), -1); } } else { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeWeek(block, m.start(), m.end(), 1); } else { createRelativeWeek(block, m.start(), m.end(), -1); } } } }  @Override AnalysisEngineAction getAction(); static final String PARAM_DATE_FORMAT; static final String PARAM_METADATA_FIELDS; }
@Test public void testNextLastWeek() throws Exception { jCas.setDocumentText( "Next week begins on the 10th October, last week began on 26th September."); setDocumentDate(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Temporal.class).size()); Temporal t1 = JCasUtil.selectByIndex(jCas, Temporal.class, 0); assertEquals("Next week", t1.getCoveredText()); assertEquals( LocalDate.of(2016, 10, 10).atStartOfDay().toEpochSecond(ZoneOffset.UTC), t1.getTimestampStart()); assertEquals( LocalDate.of(2016, 10, 17).atStartOfDay().toEpochSecond(ZoneOffset.UTC), t1.getTimestampStop()); Temporal t2 = JCasUtil.selectByIndex(jCas, Temporal.class, 1); assertEquals("last week", t2.getCoveredText()); assertEquals( LocalDate.of(2016, 9, 26).atStartOfDay().toEpochSecond(ZoneOffset.UTC), t2.getTimestampStart()); assertEquals( LocalDate.of(2016, 10, 3).atStartOfDay().toEpochSecond(ZoneOffset.UTC), t2.getTimestampStop()); }