@Test public void testNextLastYear() throws Exception { jCas.setDocumentText("Next year is 2017, last year was 2016."); setDocumentDate(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Temporal.class).size()); Temporal t1 = JCasUtil.selectByIndex(jCas, Temporal.class, 0); assertEquals("Next year", t1.getCoveredText()); assertEquals( LocalDate.of(2017, 1, 1).atStartOfDay().toEpochSecond(ZoneOffset.UTC), t1.getTimestampStart()); assertEquals( LocalDate.of(2018, 1, 1).atStartOfDay().toEpochSecond(ZoneOffset.UTC), t1.getTimestampStop()); Temporal t2 = JCasUtil.selectByIndex(jCas, Temporal.class, 1); assertEquals("last year", t2.getCoveredText()); assertEquals( LocalDate.of(2015, 1, 1).atStartOfDay().toEpochSecond(ZoneOffset.UTC), t2.getTimestampStart()); assertEquals( LocalDate.of(2016, 1, 1).atStartOfDay().toEpochSecond(ZoneOffset.UTC), t2.getTimestampStop()); }
private void nextLastYear(TextBlock block) { Pattern p = Pattern.compile( "\\b((in the|within the|" + MONTHS + ") )?(next|last) year\\b", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(block.getCoveredText()); while (m.find()) { if (m.group(3) != null) { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYearMonth(block, m.start(), m.end(), 1, DateTimeUtils.asMonth(m.group(3))); } else { createRelativeYearMonth(block, m.start(), m.end(), -1, DateTimeUtils.asMonth(m.group(3))); } } else if (m.group(2) != null) { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYearPeriod(block, m.start(), m.end(), 1); } else { createRelativeYearPeriod(block, m.start(), m.end(), -1); } } else { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYear(block, m.start(), m.end(), 1); } else { createRelativeYear(block, m.start(), m.end(), -1); } } } }
RelativeDate extends BaleenTextAwareAnnotator { private void nextLastYear(TextBlock block) { Pattern p = Pattern.compile( "\\b((in the|within the|" + MONTHS + ") )?(next|last) year\\b", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(block.getCoveredText()); while (m.find()) { if (m.group(3) != null) { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYearMonth(block, m.start(), m.end(), 1, DateTimeUtils.asMonth(m.group(3))); } else { createRelativeYearMonth(block, m.start(), m.end(), -1, DateTimeUtils.asMonth(m.group(3))); } } else if (m.group(2) != null) { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYearPeriod(block, m.start(), m.end(), 1); } else { createRelativeYearPeriod(block, m.start(), m.end(), -1); } } else { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYear(block, m.start(), m.end(), 1); } else { createRelativeYear(block, m.start(), m.end(), -1); } } } } }
RelativeDate extends BaleenTextAwareAnnotator { private void nextLastYear(TextBlock block) { Pattern p = Pattern.compile( "\\b((in the|within the|" + MONTHS + ") )?(next|last) year\\b", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(block.getCoveredText()); while (m.find()) { if (m.group(3) != null) { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYearMonth(block, m.start(), m.end(), 1, DateTimeUtils.asMonth(m.group(3))); } else { createRelativeYearMonth(block, m.start(), m.end(), -1, DateTimeUtils.asMonth(m.group(3))); } } else if (m.group(2) != null) { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYearPeriod(block, m.start(), m.end(), 1); } else { createRelativeYearPeriod(block, m.start(), m.end(), -1); } } else { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYear(block, m.start(), m.end(), 1); } else { createRelativeYear(block, m.start(), m.end(), -1); } } } }  }
RelativeDate extends BaleenTextAwareAnnotator { private void nextLastYear(TextBlock block) { Pattern p = Pattern.compile( "\\b((in the|within the|" + MONTHS + ") )?(next|last) year\\b", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(block.getCoveredText()); while (m.find()) { if (m.group(3) != null) { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYearMonth(block, m.start(), m.end(), 1, DateTimeUtils.asMonth(m.group(3))); } else { createRelativeYearMonth(block, m.start(), m.end(), -1, DateTimeUtils.asMonth(m.group(3))); } } else if (m.group(2) != null) { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYearPeriod(block, m.start(), m.end(), 1); } else { createRelativeYearPeriod(block, m.start(), m.end(), -1); } } else { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYear(block, m.start(), m.end(), 1); } else { createRelativeYear(block, m.start(), m.end(), -1); } } } }  @Override AnalysisEngineAction getAction(); }
RelativeDate extends BaleenTextAwareAnnotator { private void nextLastYear(TextBlock block) { Pattern p = Pattern.compile( "\\b((in the|within the|" + MONTHS + ") )?(next|last) year\\b", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(block.getCoveredText()); while (m.find()) { if (m.group(3) != null) { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYearMonth(block, m.start(), m.end(), 1, DateTimeUtils.asMonth(m.group(3))); } else { createRelativeYearMonth(block, m.start(), m.end(), -1, DateTimeUtils.asMonth(m.group(3))); } } else if (m.group(2) != null) { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYearPeriod(block, m.start(), m.end(), 1); } else { createRelativeYearPeriod(block, m.start(), m.end(), -1); } } else { if ("next".equalsIgnoreCase(m.group(4))) { createRelativeYear(block, m.start(), m.end(), 1); } else { createRelativeYear(block, m.start(), m.end(), -1); } } } }  @Override AnalysisEngineAction getAction(); static final String PARAM_DATE_FORMAT; static final String PARAM_METADATA_FIELDS; }