SUTime: "Independence Day" is not recognised as a holiday
SUTime: "Independence Day" is not recognised as a holiday
Summary
SUTime resolves "the Fourth of July" and "July 4th" correctly, but does not recognise "Independence Day" at all. Only the bare word "Day" matches, as a one-day duration.
"We met on the Fourth of July." -> [the Fourth of July] DATE 2010-07-04
"We met on July 4th." -> [July 4th] DATE 2010-07-04
"We met on the 4th of July." -> [the 4th of July] DATE 2010-07-04
"We met on Independence Day." -> [Day] DURATION P1D
"We met on Independence day 2011."-> [day 2011] DATE, temporal functionCause
There is no rule for it. english.holidays.sutime.txt does not mention Independence Day,
and no rule file anywhere references INDEPENDENCE. The holiday machinery is not failing;
it was never asked. Holidays_sutime.xml does define the holiday
(<Fixed month="JULY" day="4" validFrom="1776" descriptionPropertiesKey="US_INDEPENDENCE"/>),
but nothing maps text onto it.
Suggested fix
One line, following the pattern the file already uses for fixed-date holidays:
# the US date; Independence Day falls elsewhere in other countries
{ (/independence/ /day/ ) => IsoDate(NIL, 7, 4) }Verified across phrasings and reference dates:
"Independence Day" ref 2010-02-17 -> 2010-07-04
"independence day" ref 2010-02-17 -> 2010-07-04 (case insensitive)
"Independence Day 2011" ref 2010-02-17 -> 2011-07-04 (composes with a year)
"Independence Day" ref 2011-06-03 -> 2011-07-04
"Independence Day" no reference -> XXXX-07-04No change to any of the 2075 entries in the SUTime golden file, and the existing rule behaviour tests stay green.
Alternative considered: route it through jollyday
Since the calendar already defines US_INDEPENDENCE, an obvious alternative is
{ (/independence/ /day/) => JH_US_INDEPENDENCE }, matching how Thanksgiving and Easter
are handled. Tried, and it is worse on three counts:
JH_US_INDEPENDENCE |
IsoDate(NIL, 7, 4) |
|
|---|---|---|
| "Independence Day 1995" | 1995-07-04 | 1995-07-04 |
| "Independence Day 1770" | splits into two expressions, unresolved | 1770-07-04 |
| "Independence Day", no reference | US_INDEPENDENCE |
XXXX-07-04 |
with sutime.binders=0 |
no match, "Unknown variable" logged | 1995-07-04 |
The 1770 case is the calendar's validFrom="1776". The undated case matters more:
XXXX-07-04 is a usable TIMEX value, while US_INDEPENDENCE is a symbol. Thanksgiving and
Easter emit symbols undated because they cannot be written as a fixed month and day;
Independence Day can, so there is no reason to give that up. And rules that resolve to a
JH_ variable silently match nothing when the holidays binder is disabled, whereas
IsoDate rules keep working.
There is precedent either way in the same file: Halloween, Christmas and Valentine's Day
are all defined in Holidays_sutime.xml as well, and the rules still use IsoDate for
them. The split is computed-versus-fixed rather than in-the-XML-versus-not.
One thing worth recording from the investigation: the XML entry carries no weekend-shift attribute, so jollyday returns July 4 flat. Had it modelled the observed holiday, "Independence Day 2010" would have resolved to July 5, which would be wrong for the phrase.
Open question: which countries this is right for
"Independence Day" means different dates in different places, and in the United Kingdom it
means nothing at all. Either form of the fix hard-codes the US date, and routing it through
jollyday does not help, since Holidays_sutime.xml is equally US-flavoured.
This is not a new problem introduced by this rule. Options.DEFAULT_BRITISH_GRAMMAR_FILES
includes english.holidays.sutime.txt wholesale, so the British pipeline already inherits a
number of US-specific holidays:
Thanksgivingresolves to the fourth Thursday in November. Canadian Thanksgiving is the second Monday in October, so British-English text about Canada gets the US date.{ (/labou?r/ /day/) => JH_LABOUR_DAY }matches the British spelling and resolves to the first Monday in September, the US date. There is no UK Labour Day; May Day is 1 May, and the calendar definesMAYDAYseparately.Memorial Day,Columbus Day,Martin Luther King Day,Inauguration DayandGroundhog Dayare all US holidays reachable from the British grammar.
So adding Independence Day joins an existing pattern rather than starting one. The wider
question — whether country-specific holidays belong in a shared English file, or in
per-locale files alongside british.sutime.txt — is worth deciding separately. The Spanish
grammar is unaffected either way, since DEFAULT_SPANISH_GRAMMAR_FILES does not include the
holidays file.
Note on deployment
This is a rule file change. The pipeline loads its grammar from the models jar
(edu/stanford/nlp/models/sutime/), not from src/edu/stanford/nlp/time/rules/, so it has
no effect until the models jar is rebuilt.
Source: stanfordnlp/CoreNLP