XMIReader.PARAM_XMI_DIRECTORY,
options.getXMIDirectory()));
String grammarPath = "/org/apache/ctakes/temporal/timenorm.en.grammar";
URL grammarURL = PrintFailedTimeNormalizations.class.getResource(grammarPath);
TemporalExpressionParser parser = new TemporalExpressionParser(grammarURL);
for (JCas jCas : new JCasIterable(reader, aggregateBuilder.createAggregate())) {
JCas goldView = jCas.getView("GoldView");
Matcher matcher = DOC_TIME_PATTERN.matcher(goldView.getDocumentText());
if (!matcher.find()) {
System.err.println(goldView.getDocumentText());
} else {
Try<Temporal> anchorTry = parser.parse(matcher.group(1), TimeSpan.of(1, 1, 1));
if (anchorTry.isSuccess() && anchorTry.get() instanceof TimeSpan) {
TimeSpan anchor = (TimeSpan)anchorTry.get();
for (Segment segment : JCasUtil.select(jCas, Segment.class)) {
if (!THYMEData.SEGMENTS_TO_SKIP.contains(segment.getId())) {
for (TimeMention time : JCasUtil.selectCovered(goldView, TimeMention.class, segment)) {
String timeText = time.getCoveredText();
Try<Temporal> parsedTime = parser.parse(timeText, anchor);
if (parsedTime.isSuccess()) {
//System.err.printf("%s %s\n", timeText, parsedTime);
} else {
System.err.println(timeText);
System.err.println(parsedTime);