Skip to content

Commit 0dfb118

Browse files
committed
Fix/improve SUTime (WORKDAY)
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.
1 parent ff5806e commit 0dfb118

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/edu/stanford/nlp/time/SUTime.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,8 @@ public Duration getDuration() {
791791
.hourOfDay(), 17)))));
792792
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
793793
.hourOfDay(), 20)))));
794+
public static final Time WORKDAY = createTemporal(StandardTemporalType.TIME_OF_DAY, "WH", new InexactTime(new Range(new InexactTime(new Partial(DateTimeFieldType.hourOfDay(), 9)),
795+
new InexactTime(new Partial(DateTimeFieldType.hourOfDay(), 17)))));
794796

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

812-
protected Duration duration;
814+
private final Duration duration;
813815

814816
TimeUnit(Duration d) {
815817
this.duration = d;

src/edu/stanford/nlp/time/rules/defs.sutime.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
LUNCHTIME = InexactTime( TimeRange( IsoTime(12, NONE, NONE), IsoTime(14, NONE, NONE) ))
196196
TEATIME = InexactTime( TimeRange( IsoTime(15, NONE, NONE), IsoTime(17, NONE, NONE) ))
197197
DINNERTIME = InexactTime( TimeRange( IsoTime(18, NONE, NONE), IsoTime(20, NONE, NONE) ))
198+
WORKDAY = InexactTime( TimeRange( IsoTime(9, NONE, NONE), IsoTime(17, NONE, NONE) ))
198199

199200
DAYTIME = {
200201
type: TIME_OF_DAY,

src/edu/stanford/nlp/time/rules/english.sutime.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
$hasTemporal = "( { temporal::EXISTS } & {{ temporal.value != NON_TEMPORAL }} & !{{ tags[\"TIMEZONE\"] }} )"
2323

2424
# Decades
25+
# We might want to add "teens" but would need to change grammar to insist on "the" before it, but even then maybe too ambiguous?
26+
# "teens": "1X",
2527
DECADES_MAP = {
28+
"oughts": "0X",
29+
"noughts": "0X",
2630
"twenties": "2X",
2731
"thirties": "3X",
2832
"forties": "4X",
@@ -124,7 +128,7 @@
124128
}
125129
$BasicOrdTerm = CreateRegex(Keys(BASIC_ORDINAL_MAP))
126130

127-
# Finanical Quarters
131+
# Financial Quarters
128132
FISCAL_YEAR_QUARTER_MAP = {
129133
"Q1": FYQ1,
130134
"Q2": FYQ2,
@@ -265,7 +269,7 @@
265269
{ (/suppertimes?/) => SUPPERTIME }
266270
{ (/daylights?|days?|daytimes?/) => DAYTIME }
267271
{ (/nighttimes?|nights?|overnights?/) => NIGHT }
268-
{ (/workday|work day|business hours/) => WORKDAY }
272+
{ (/workday|work(ing)? day|business hours/) => WORKDAY }
269273

270274
# Seasons
271275
{ (/summers?/) => SUMMER }
@@ -296,7 +300,7 @@
296300
{ (/suns?/) => SUNDAY }
297301

298302
{ (/weekends?/) => WEEKEND }
299-
{ (/weekdays?/) => WEEKDAY }
303+
{ (/weekdays?|workweek/) => WEEKDAY }
300304

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

404408
# Generic decade
405-
{ ( /the/? ( /\w+teen/ /$Decades/ ) )
409+
{ ( /the/? ( /\w+teen|twenty/ /$Decades/ ) )
406410
=> IsoDate( Concat( Format("%02d", $0[0].numcompvalue), DECADES_MAP[Lowercase($0[1].word)]), NIL, NIL)
407411
}
408412
{ ( /the/? ( /$Decades/ ) )
@@ -481,6 +485,10 @@
481485
{ text: /\b(\d{4})\s*(?:-)\s*(\d{4})\b/ =>
482486
TimeRange( IsoDate($1, NIL, NIL), IsoDate($2, NIL, NIL) ) }
483487
{ ( /the/ /weekend/ ) => WEEKEND }
488+
{ ( /work(ing)?/ /day/ ) => WORKDAY }
489+
{ ( /business/ /hours/ ) => WORKDAY }
490+
{ ( /work(ing)?/ /week/ ) => WEEKDAY }
491+
{ ( /week|business/ /days?/ ) => WEEKDAY }
484492

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

0 commit comments

Comments
 (0)