]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
UJ-47: Separated romanMonth from dateNum, renamed romanNum to romanMonth
authorcesarvh <cesarv.h@berkeley.edu>
Fri, 1 Feb 2019 21:15:26 +0000 (13:15 -0800)
committercesarvh <cesarv.h@berkeley.edu>
Tue, 19 Mar 2019 19:41:41 +0000 (12:41 -0700)
services/structureddate/structureddate/src/main/antlr4/org/collectionspace/services/structureddate/antlr/StructuredDate.g4
services/structureddate/structureddate/src/main/java/org/collectionspace/services/structureddate/antlr/ANTLRStructuredDateEvaluator.java
services/structureddate/structureddate/src/test/resources/test-dates.yaml

index e3b608f80b7ed983419d360f43f25b58dd73663c..6eb14b19a3ab3c300d05aad5ad8f406a8555c429 100644 (file)
@@ -62,6 +62,7 @@ date:                  numDate
 |                      dayFirstDate
 |                      dayOrYearFirstDate
 |                      invStrDateEraLastDate
+|                      romanDate
 ;
 
 month:                 monthYear
@@ -95,6 +96,7 @@ century:               ( strCentury | numCentury ) era? ;
 
 millennium:            nth MILLENNIUM era? ;
 
+romanDate:             num (HYPHEN | SLASH) romanMonth (HYPHEN | SLASH) numYear era? ;
 strDate:               strMonth ( numDayOfMonth | nth ) COMMA? numYear era?;
 invStrDate:            era num COMMA? strMonth num
 |                      era? num COMMA strMonth num ;
@@ -108,8 +110,8 @@ monthInYearRange:      strMonth ( HYPHEN | DASH ) strMonth COMMA? numYear era? ;
 nthQuarterInYearRange: nthQuarter ( HYPHEN | DASH ) nthQuarter COMMA? numYear era? ;
 strSeasonInYearRange:  strSeason ( HYPHEN | DASH ) strSeason COMMA? numYear era? ;
 numDayInMonthRange:    numMonth SLASH num ( HYPHEN | DASH ) num SLASH numYear era? ;
-numDate:               num SLASH ( num | romanNum ) SLASH num era?
-|                      num HYPHEN ( num | romanNum ) HYPHEN num era? ;
+numDate:               num SLASH num SLASH num era?
+|                      num HYPHEN num HYPHEN num era? ;
 monthYear:             strMonth COMMA? numYear era? ;
 invMonthYear:          era? numYear COMMA? strMonth ;
 seasonYear:            strSeason COMMA? numYear era? ;
@@ -132,7 +134,7 @@ numMonth:              NUMBER ;
 numDayOfMonth:         NUMBER ;
 num:                   NUMBER ;
 unknownDate:           UNKNOWN ;
-romanNum:              ROMANNUMBER ; 
+romanMonth:            ROMANMONTH ; 
 
 /*
  * Lexer rules
@@ -167,7 +169,7 @@ NTHSTR:         [0-9]*? ([0456789] 'th' | '1st' | '2nd' | '3rd' | '11th' | '12th
 HUNDREDS:       [0-9]*? '00' '\''? 's';
 TENS:           [0-9]*? '0' '\''? 's';
 NUMBER:         ([0-9,]+)*[0-9] ;
-ROMANNUMBER:    [ivx]+ ;
+ROMANMONTH:     'i' | 'ii' | 'iii' | 'iv' | 'v' | 'vi' | 'vii' | 'viii' | 'ix' | 'x' | 'xi' | 'xii' ;
 COMMA:          ',' ;
 HYPHEN:         '-' ;
 DASH:           [—–] ; /* EM DASH, EN DASH */
index 14e51f35018dc1ebb89e93d6d9820921eb1fbb52..bfa622ff303ebc6137aa9b10053748c8b9e886e1 100644 (file)
@@ -77,10 +77,11 @@ import org.collectionspace.services.structureddate.antlr.StructuredDateParser.Pa
 import org.collectionspace.services.structureddate.antlr.StructuredDateParser.PartialCenturyContext;
 import org.collectionspace.services.structureddate.antlr.StructuredDateParser.PartialDecadeContext;
 import org.collectionspace.services.structureddate.antlr.StructuredDateParser.PartialYearContext;
+import org.collectionspace.services.structureddate.antlr.StructuredDateParser.RomanDateContext;
 import org.collectionspace.services.structureddate.antlr.StructuredDateParser.QuarterCenturyContext;
 import org.collectionspace.services.structureddate.antlr.StructuredDateParser.QuarterInYearRangeContext;
 import org.collectionspace.services.structureddate.antlr.StructuredDateParser.QuarterYearContext;
-import org.collectionspace.services.structureddate.antlr.StructuredDateParser.RomanNumContext;
+import org.collectionspace.services.structureddate.antlr.StructuredDateParser.RomanMonthContext;
 import org.collectionspace.services.structureddate.antlr.StructuredDateParser.SeasonYearContext;
 import org.collectionspace.services.structureddate.antlr.StructuredDateParser.StrCenturyContext;
 import org.collectionspace.services.structureddate.antlr.StructuredDateParser.StrDateContext;
@@ -483,11 +484,6 @@ public class ANTLRStructuredDateEvaluator extends StructuredDateBaseListener imp
                        numMonth = num2;
                        dayOfMonth = num3;
                }
-               else if (DateUtils.isValidDate(num3, num2, num1, era)) {
-                       // The date was of format day-month-year
-                       numMonth = num2;
-                       dayOfMonth = num1;
-               }
 
                stack.push(year);
                stack.push(numMonth);
@@ -1213,17 +1209,28 @@ public class ANTLRStructuredDateEvaluator extends StructuredDateBaseListener imp
        }
 
        @Override
-       public void exitRomanNum(RomanNumContext ctx) {
-               
-               int num = DateUtils.romanToDecimal(ctx.ROMANNUMBER().getText());
-
-               if (num < 1 || num > 12) {
-                       throw new StructuredDateFormatException("unexpected month '" + Integer.toString(num) + "'");
-               }
+       public void exitRomanMonth(RomanMonthContext ctx) {
+               int num = DateUtils.romanToDecimal(ctx.ROMANMONTH().getText());
 
                stack.push(num);
        }
 
+       @Override
+       public void exitRomanDate(RomanDateContext ctx) {
+               if (ctx.exception != null) return;
+               System.out.println("I am going in here");
+               
+               Era era = (ctx.era() == null) ? null : (Era) stack.pop();
+               Integer year = (Integer) stack.pop();
+               Integer month = (Integer) stack.pop();
+               Integer day = (Integer) stack.pop();
+
+               stack.push(year);
+               stack.push(month);
+               stack.push(day);
+               stack.push(era);
+       }
+
        @Override
        public void exitUnknownDate(UnknownDateContext ctx) {
                if (ctx.exception != null) return;
index 95950313e825c40f5665c373da7663ed00f4b43e..bd9d8d26ec0fe21ec2f0981ae5bbac369c3430a1 100644 (file)
                                          earliestSingleDate: [54962,  5,  13, BCE]
                                          latestDate:         [2019,  4,  5, CE]
 
-  '17-X-13':                            # Day-Month-Year with roman numeral as month, makes sure ambiguities resolved as they were before
-                                         earliestSingleDate: [17,  10,  13, CE]
-
   '01-I-2017 BCE':                       # Day-Month-Year with roman numeral as month 
                                          earliestSingleDate: [2017,  1,  1, BCE]
 
   '29-IV-2018':                          # Day-Month-Year with roman numeral as month 
                                          earliestSingleDate: [2018,  4,  29, CE]
 
+  '01-IV-2017 BCE':                          # Day-Month-Year with roman numeral as month, with Era
+                                          earliestSingleDate: [2017, 4, 1, BCE]  
+
 # -------------------------------------------------------------------------------------------------------
 # Invalid dates
 # -------------------------------------------------------------------------------------------------------