Skip to content

Commit

Permalink
Fix/improve SUTime (WORKDAY)
Browse files Browse the repository at this point in the history
Add definition for WORKDAY which was previously undefined, causing an error.
Add some more expressions for workday and weekday
Add reccognition of the (n)oughts decade.
  • Loading branch information
manning committed Nov 20, 2021
1 parent ff5806e commit 0dfb118
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/edu/stanford/nlp/time/SUTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,8 @@ public Duration getDuration() {
.hourOfDay(), 17)))));
public static final Time DINNERTIME = createTemporal(StandardTemporalType.TIME_OF_DAY, "EV", new InexactTime(new Range(new InexactTime(new Partial(DateTimeFieldType.hourOfDay(), 18)), new InexactTime(new Partial(DateTimeFieldType
.hourOfDay(), 20)))));
public static final Time WORKDAY = createTemporal(StandardTemporalType.TIME_OF_DAY, "WH", new InexactTime(new Range(new InexactTime(new Partial(DateTimeFieldType.hourOfDay(), 9)),
new InexactTime(new Partial(DateTimeFieldType.hourOfDay(), 17)))));

public static final Time MORNING_TWILIGHT = createTemporal(StandardTemporalType.TIME_OF_DAY, "MO", new InexactTime(new Range(DAWN, SUNRISE)));
public static final Time EVENING_TWILIGHT = createTemporal(StandardTemporalType.TIME_OF_DAY, "EV", new InexactTime(new Range(SUNSET, DUSK)));
Expand All @@ -809,7 +811,7 @@ public enum TimeUnit {
YEAR(SUTime.YEAR), DECADE(SUTime.DECADE), CENTURY(SUTime.CENTURY), MILLENNIUM(SUTime.MILLENNIUM),
UNKNOWN(SUTime.DURATION_UNKNOWN);

protected Duration duration;
private final Duration duration;

TimeUnit(Duration d) {
this.duration = d;
Expand Down
1 change: 1 addition & 0 deletions src/edu/stanford/nlp/time/rules/defs.sutime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
LUNCHTIME = InexactTime( TimeRange( IsoTime(12, NONE, NONE), IsoTime(14, NONE, NONE) ))
TEATIME = InexactTime( TimeRange( IsoTime(15, NONE, NONE), IsoTime(17, NONE, NONE) ))
DINNERTIME = InexactTime( TimeRange( IsoTime(18, NONE, NONE), IsoTime(20, NONE, NONE) ))
WORKDAY = InexactTime( TimeRange( IsoTime(9, NONE, NONE), IsoTime(17, NONE, NONE) ))

DAYTIME = {
type: TIME_OF_DAY,
Expand Down
16 changes: 12 additions & 4 deletions src/edu/stanford/nlp/time/rules/english.sutime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
$hasTemporal = "( { temporal::EXISTS } & {{ temporal.value != NON_TEMPORAL }} & !{{ tags[\"TIMEZONE\"] }} )"

# Decades
# We might want to add "teens" but would need to change grammar to insist on "the" before it, but even then maybe too ambiguous?
# "teens": "1X",
DECADES_MAP = {
"oughts": "0X",
"noughts": "0X",
"twenties": "2X",
"thirties": "3X",
"forties": "4X",
Expand Down Expand Up @@ -124,7 +128,7 @@
}
$BasicOrdTerm = CreateRegex(Keys(BASIC_ORDINAL_MAP))

# Finanical Quarters
# Financial Quarters
FISCAL_YEAR_QUARTER_MAP = {
"Q1": FYQ1,
"Q2": FYQ2,
Expand Down Expand Up @@ -265,7 +269,7 @@
{ (/suppertimes?/) => SUPPERTIME }
{ (/daylights?|days?|daytimes?/) => DAYTIME }
{ (/nighttimes?|nights?|overnights?/) => NIGHT }
{ (/workday|work day|business hours/) => WORKDAY }
{ (/workday|work(ing)? day|business hours/) => WORKDAY }

# Seasons
{ (/summers?/) => SUMMER }
Expand Down Expand Up @@ -296,7 +300,7 @@
{ (/suns?/) => SUNDAY }

{ (/weekends?/) => WEEKEND }
{ (/weekdays?/) => WEEKDAY }
{ (/weekdays?|workweek/) => WEEKDAY }

# Month
{ (/januarys?/) => JANUARY }
Expand Down Expand Up @@ -402,7 +406,7 @@
{ ( [ { tag:NNP } ]+ [ { tag:POS } ] /birthday/ ) => SimpleTime($0) }

# Generic decade
{ ( /the/? ( /\w+teen/ /$Decades/ ) )
{ ( /the/? ( /\w+teen|twenty/ /$Decades/ ) )
=> IsoDate( Concat( Format("%02d", $0[0].numcompvalue), DECADES_MAP[Lowercase($0[1].word)]), NIL, NIL)
}
{ ( /the/? ( /$Decades/ ) )
Expand Down Expand Up @@ -481,6 +485,10 @@
{ text: /\b(\d{4})\s*(?:-)\s*(\d{4})\b/ =>
TimeRange( IsoDate($1, NIL, NIL), IsoDate($2, NIL, NIL) ) }
{ ( /the/ /weekend/ ) => WEEKEND }
{ ( /work(ing)?/ /day/ ) => WORKDAY }
{ ( /business/ /hours/ ) => WORKDAY }
{ ( /work(ing)?/ /week/ ) => WEEKDAY }
{ ( /week|business/ /days?/ ) => WEEKDAY }

# Now a few time expressions
{ ( (/\d\d\d\d/) /hours?/? (/universal|zulu/ | /[a-z]+/ /standard|daylight/) /time/ ) => IsoTime($1[0].word, NIL, NIL) }
Expand Down

0 comments on commit 0dfb118

Please sign in to comment.