From 6376ba7312e95166e150a8acfff969657132c262 Mon Sep 17 00:00:00 2001 From: cesarvh Date: Thu, 18 Oct 2018 16:47:27 -0700 Subject: [PATCH] HM-5: Added unknown date --- .../structureddate/antlr/StructuredDate.g4 | 16 +++++----------- .../antlr/ANTLRStructuredDateEvaluator.java | 10 +++++++++- .../src/test/resources/test-dates.yaml | 5 +++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/services/structureddate/structureddate/src/main/antlr4/org/collectionspace/services/structureddate/antlr/StructuredDate.g4 b/services/structureddate/structureddate/src/main/antlr4/org/collectionspace/services/structureddate/antlr/StructuredDate.g4 index d1cb9a49f..3afaf9f5f 100644 --- a/services/structureddate/structureddate/src/main/antlr4/org/collectionspace/services/structureddate/antlr/StructuredDate.g4 +++ b/services/structureddate/structureddate/src/main/antlr4/org/collectionspace/services/structureddate/antlr/StructuredDate.g4 @@ -8,17 +8,12 @@ grammar StructuredDate; /* * Parser rules */ -// unknownDisplayDate: - -oneDisplayDate: displayDate ( DOT | QUESTION )? EOF ; +oneDisplayDate: displayDate ( DOT | QUESTION )? EOF; displayDate: uncertainDate | certainDate -/* TODO: Need to decide what "before" and "after" actually mean -| beforeOrAfterDate -*/ | beforeOrAfterDate -// | unknownDate +| unknownDate ; uncertainDate: CIRCA certainDate ; @@ -35,7 +30,6 @@ hyphenatedRange: singleInterval ( HYPHEN | DASH ) singleInterval | quarterInYearRange | strDayInMonthRange | numDayInMonthRange -// | numMonthInYearsRange ; singleInterval: yearSpanningWinter @@ -128,7 +122,7 @@ numYear: NUMBER ; numMonth: NUMBER ; numDayOfMonth: NUMBER ; num: NUMBER ; -// unknownDate: UNKNOWN ; +unknownDate: UNKNOWN ; /* * Lexer rules @@ -168,6 +162,6 @@ DASH: [—–] ; /* EM DASH, EN DASH */ SLASH: '/' ; DOT: '.' ; QUESTION: '?' ; -STRING: [a-z]+ ; OTHER: . ; -// UNKNOWN: 'unknown'; \ No newline at end of file +UNKNOWN: 'unknown'; +STRING: [a-z]+ ; \ No newline at end of file diff --git a/services/structureddate/structureddate/src/main/java/org/collectionspace/services/structureddate/antlr/ANTLRStructuredDateEvaluator.java b/services/structureddate/structureddate/src/main/java/org/collectionspace/services/structureddate/antlr/ANTLRStructuredDateEvaluator.java index b0de8cc52..560fa020b 100644 --- a/services/structureddate/structureddate/src/main/java/org/collectionspace/services/structureddate/antlr/ANTLRStructuredDateEvaluator.java +++ b/services/structureddate/structureddate/src/main/java/org/collectionspace/services/structureddate/antlr/ANTLRStructuredDateEvaluator.java @@ -86,6 +86,7 @@ import org.collectionspace.services.structureddate.antlr.StructuredDateParser.St import org.collectionspace.services.structureddate.antlr.StructuredDateParser.StrSeasonContext; import org.collectionspace.services.structureddate.antlr.StructuredDateParser.StrSeasonInYearRangeContext; import org.collectionspace.services.structureddate.antlr.StructuredDateParser.UncertainDateContext; +import org.collectionspace.services.structureddate.antlr.StructuredDateParser.UnknownDateContext; import org.collectionspace.services.structureddate.antlr.StructuredDateParser.YearContext; import org.collectionspace.services.structureddate.antlr.StructuredDateParser.YearSpanningWinterContext; @@ -166,6 +167,14 @@ public class ANTLRStructuredDateEvaluator extends StructuredDateBaseListener imp result.setEarliestSingleDate(earliestDate); result.setLatestDate(latestDate); } + @Override + public void exitUnknownDate(UnknownDateContext ctx) { + if (ctx.exception != null) return; + + // Dummy dates + stack.push(new Date()); + stack.push(new Date()); + } @Override public void exitBeforeOrAfterDate(BeforeOrAfterDateContext ctx) { @@ -1182,7 +1191,6 @@ public class ANTLRStructuredDateEvaluator extends StructuredDateBaseListener imp stack.push(num); } - protected String getErrorMessage(RecognitionException re) { String message = ""; diff --git a/services/structureddate/structureddate/src/test/resources/test-dates.yaml b/services/structureddate/structureddate/src/test/resources/test-dates.yaml index 82c238c95..412f35faf 100644 --- a/services/structureddate/structureddate/src/test/resources/test-dates.yaml +++ b/services/structureddate/structureddate/src/test/resources/test-dates.yaml @@ -1195,8 +1195,9 @@ "04/1995-04/2018": # Month/Year - Month/Year date earliestSingleDate: [1995, 4, 1, CE] latestDate: [2018, 4, 30, CE] - # "unknown": - # earliestSingleDate: [] + + "unknown": # Unknown date: Should result in empty fields + earliestSingleDate: [] # ------------------------------------------------------------------------------------------------------- # Invalid dates -- 2.47.3