Skip to content

Commit 08a5f8b

Browse files
Fix (hackingly) 'winter' date resolution in all langs. Misc. details En & It.
1 parent 6931ff0 commit 08a5f8b

File tree

16 files changed

+179
-81
lines changed

16 files changed

+179
-81
lines changed

grammar/de/src/rules.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,37 +1717,44 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
17171717
friday.span_to(&monday, false)
17181718
}
17191719
);
1720-
b.rule_1_terminal("season",
1720+
b.rule_1_terminal("season - summer",
17211721
b.reg(r#"sommer(?:zeit|s)?"#)?,
17221722
|_| Ok(helpers::month_day(6, 21)?
17231723
.span_to(&helpers::month_day(9, 23)?, false)?
1724-
.form(Form::PartOfYear))
1724+
.form(Form::Season))
17251725
);
17261726
b.rule_1_terminal("Summer solstice",
17271727
b.reg(r#"sommersonn(?:en)?wende"#)?,
17281728
|_| Ok(helpers::month_day(6, 21)?.form(Form::Celebration).too_ambiguous())
17291729
);
1730-
b.rule_1_terminal("season",
1730+
b.rule_1_terminal("season - fall",
17311731
b.reg(r#"herbst(?:zeit|s|es)?|sp[äa]tjahr(?:es)?"#)?,
17321732
|_| Ok(helpers::month_day(9, 23)?
17331733
.span_to(&helpers::month_day(12, 21)?, false)?
1734-
.form(Form::PartOfYear))
1734+
.form(Form::Season))
17351735
);
1736-
b.rule_1_terminal("season",
1736+
b.rule_1_terminal("season - winter",
17371737
b.reg(r#"winter(?:zeit|s)?"#)?,
17381738
|_| Ok(helpers::month_day(12, 21)?
17391739
.span_to(&helpers::month_day(3, 20)?, false)?
1740-
.form(Form::PartOfYear))
1740+
.form(Form::Season))
1741+
);
1742+
b.rule_2("season - winter <year>",
1743+
b.reg(r#"winter(?:zeit|s)?"#)?,
1744+
datetime_check!(form!(Form::Year(_))),
1745+
|_, year| Ok(helpers::year_month_day(year.value().form_year()?, 12, 21)?
1746+
.span_to(&helpers::year_month_day(year.value().form_year()? + (1 as i32), 3, 20)?, false)?
1747+
.form(Form::Season))
17411748
);
17421749
b.rule_1_terminal("Winter solstice",
17431750
b.reg(r#"wintersonnwende"#)?,
17441751
|_| Ok(helpers::month_day(12, 21)?.form(Form::Celebration).too_ambiguous())
17451752
);
1746-
b.rule_1_terminal("season",
1753+
b.rule_1_terminal("season - spring",
17471754
b.reg(r#"(?:fr[üu]hlings?|fr[üu]hjahr(?:es)?)(?:zeit)?"#)?,
17481755
|_| Ok(helpers::month_day(3, 20)?
17491756
.span_to(&helpers::month_day(6, 21)?, false)?
1750-
.form(Form::PartOfYear))
1757+
.form(Form::Season))
17511758
);
17521759
b.rule_2("im <part-of-year>",
17531760
b.reg(r#"(?:(?:in )?(?:de[nrms]|die|das)|im|ins)"#)?,

grammar/de/src/training.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ pub fn examples_datetime(v: &mut Vec<::rustling::train::Example<Dimension>>) {
185185
example!(v, check_moment!(c, [2013, 12]), "ein jahr nach weihnachten");
186186
example!(v, check_moment_span!(c, [2013, 6, 21], [2013, 9, 24]), "diesen sommer");
187187
example!(v, check_moment_span!(c, [2012, 12, 21], [2013, 3, 21]), "diesen winter");
188+
example!(v, check_moment!(c, [2014, 6, 1], Grain::Month), "juni 2014", "in juni 2014");
189+
example!(v, check_moment!(c, [2005, 5, 1], Grain::Month), "mai 2005", "in mai 2005");
190+
example!(v, check_moment_span!(c, [2014, 6, 21], [2014, 9, 24]), "sommer 2014", "in sommer 2014");
191+
example!(v, check_moment_span!(c, [2014, 12, 21], [2015, 3, 21]), "winter 2014", "in winter 2014");
188192
example!(v, check_moment!(c, [2013, 12, 25]), "Weihnachten", "Weihnachtstag");
189193
example!(v, check_moment!(c, [2013, 12, 31]), "Silvester");
190194
example!(v, check_moment!(c, [2014, 1, 1]), "Neujahrstag", "Neujahr");

grammar/en/src/rules_datetime.rs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
267267
a.value().the_nth_not_immediate(0)
268268
}
269269
);
270-
// TODO: add restrictions on datetime form
271270
b.rule_2("this <datetime>",
272271
b.reg(r#"the|this|current|coming"#)?,
273272
datetime_check!(|datetime: &DatetimeValue| !form!(Form::PartOfDay(_))(datetime) && !form!(Form::Meal)(datetime)),
@@ -277,7 +276,6 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
277276
.datetime_kind(a.value().datetime_kind.clone()))
278277
}
279278
);
280-
// TODO: add restrictions on datetime form
281279
b.rule_2("next <datetime>",
282280
b.reg(r#"(?:the |this )?next"#)?,
283281
datetime_check!(|datetime: &DatetimeValue| !form!(Form::PartOfDay(_))(datetime) && !form!(Form::Meal)(datetime)),
@@ -287,7 +285,6 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
287285
.datetime_kind(a.value().datetime_kind.clone()))
288286
}
289287
);
290-
// TODO: add restrictions on datetime form
291288
b.rule_2("last <datetime>",
292289
b.reg(r#"this past|(?:the |this )?last"#)?,
293290
datetime_check!(|datetime: &DatetimeValue| !form!(Form::PartOfDay(_))(datetime) && !form!(Form::Meal)(datetime)),
@@ -434,19 +431,15 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
434431
ordinal_check!(|ordinal: &OrdinalValue| 1 <= ordinal.value && ordinal.value <= 31),
435432
|month, ordinal| {
436433
let m = month.value().form_month()?;
437-
let form = Form::MonthDay(Some(MonthDayForm { month: m, day_of_month: ordinal.value().value as u32}));
438-
Ok(month.value().intersect(&helpers::day_of_month(ordinal.value().value as u32)?)?
439-
.form(form))
440-
434+
helpers::month_day(m, ordinal.value().value as u32)
441435
}
442436
);
443437
b.rule_2("<named-month> <day-of-month> (non ordinal)",
444438
datetime_check!(form!(Form::Month(_))),
445439
integer_check_by_range!(1, 31),
446440
|month, integer| {
447441
let m = month.value().form_month()?;
448-
let form = Form::MonthDay(Some(MonthDayForm { month: m, day_of_month: integer.value().value as u32}));
449-
Ok(month.value().intersect(&helpers::day_of_month(integer.value().value as u32)?)?.form(form))
442+
helpers::month_day(m, integer.value().value as u32)
450443
}
451444
);
452445
b.rule_3("<named-month> the <day-of-month> (non ordinal)",
@@ -455,8 +448,7 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
455448
integer_check_by_range!(1, 31),
456449
|month, _, integer| {
457450
let m = month.value().form_month()?;
458-
let form = Form::MonthDay(Some(MonthDayForm { month: m, day_of_month: integer.value().value as u32}));
459-
Ok(month.value().intersect(&helpers::day_of_month(integer.value().value as u32)?)?.form(form))
451+
helpers::month_day(m, integer.value().value as u32)
460452
}
461453
);
462454
b.rule_3("<day-of-month> (ordinal) of <named-month>",
@@ -465,8 +457,7 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
465457
datetime_check!(form!(Form::Month(_))),
466458
|ordinal, _, month| {
467459
let m = month.value().form_month()?;
468-
let form = Form::MonthDay(Some(MonthDayForm { month: m, day_of_month: ordinal.value().value as u32}));
469-
Ok(month.value().intersect(&helpers::day_of_month(ordinal.value().value as u32)?)?.form(form))
460+
helpers::month_day(m, ordinal.value().value as u32)
470461
}
471462
);
472463
b.rule_3("<day-of-month> (non ordinal) of <named-month>",
@@ -475,26 +466,23 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
475466
datetime_check!(form!(Form::Month(_))),
476467
|integer, _, month| {
477468
let m = month.value().form_month()?;
478-
let form = Form::MonthDay(Some(MonthDayForm { month: m, day_of_month: integer.value().value as u32}));
479-
Ok(month.value().intersect(&helpers::day_of_month(integer.value().value as u32)?)?.form(form))
469+
helpers::month_day(m, integer.value().value as u32)
480470
}
481471
);
482472
b.rule_2("<day-of-month> (non ordinal) <named-month>",
483473
integer_check_by_range!(1, 31),
484474
datetime_check!(form!(Form::Month(_))),
485475
|integer, month| {
486476
let m = month.value().form_month()?;
487-
let form = Form::MonthDay(Some(MonthDayForm { month: m, day_of_month: integer.value().value as u32}));
488-
Ok(month.value().intersect(&helpers::day_of_month(integer.value().value as u32)?)?.form(form))
477+
helpers::month_day(m, integer.value().value as u32)
489478
}
490479
);
491480
b.rule_2("<day-of-month>(ordinal) <named-month>",
492481
ordinal_check!(|ordinal: &OrdinalValue| 1 <= ordinal.value && ordinal.value <= 31),
493482
datetime_check!(form!(Form::Month(_))),
494483
|ordinal, month| {
495484
let m = month.value().form_month()?;
496-
let form = Form::MonthDay(Some(MonthDayForm { month: m, day_of_month: ordinal.value().value as u32}));
497-
Ok(month.value().intersect(&helpers::day_of_month(ordinal.value().value as u32)?)?.form(form))
485+
helpers::month_day(m, ordinal.value().value as u32)
498486
}
499487
);
500488
/* END OF DATETIME - DATE - DATES */
@@ -904,7 +892,7 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
904892
datetime_check!(|datetime: &DatetimeValue| form!(Form::PartOfDay(_))(datetime) || form!(Form::Meal)(datetime)),
905893
|_, datetime| Ok(datetime.value().clone().latent())
906894
);
907-
b.rule_2("in|for|during the <part-of-day>",
895+
b.rule_2("in|for|during the <part-of-day>",
908896
b.reg(r#"(?:in|for|during)(?: the)?"#)?,
909897
datetime_check!(|datetime: &DatetimeValue| form!(Form::PartOfDay(_))(datetime) || form!(Form::Meal)(datetime)),
910898
|_, datetime| Ok(datetime.value().clone().not_latent())
@@ -989,25 +977,33 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
989977
Ok(friday.span_to(&monday, false)?.datetime_kind(DatetimeKind::DatePeriod))
990978
}
991979
);
992-
b.rule_1_terminal("season",
980+
b.rule_1_terminal("season - summer",
993981
b.reg(r#"(?:the )?summer"#)?,
994982
|_| Ok(helpers::month_day(6, 21)?
995983
.span_to(&helpers::month_day(9, 23)?, false)?
996984
.form(Form::Season))
997985
);
998-
b.rule_1_terminal("season",
986+
b.rule_1_terminal("season - fall",
999987
b.reg(r#"(?:the )?(?:fall|autumn)"#)?,
1000988
|_| Ok(helpers::month_day(9, 23)?
1001989
.span_to(&helpers::month_day(12, 21)?, false)?
1002990
.form(Form::Season))
1003991
);
1004-
b.rule_1_terminal("season",
992+
b.rule_1_terminal("season - winter",
1005993
b.reg(r#"(?:the )?winter"#)?,
1006994
|_| Ok(helpers::month_day(12, 21)?
1007995
.span_to(&helpers::month_day(3, 20)?, false)?
1008996
.form(Form::Season))
1009997
);
1010-
b.rule_1_terminal("season",
998+
// FIXME: Also add support for combined years? e.g. "winter 2014-2015"
999+
b.rule_2("season - winter <year>",
1000+
b.reg(r#"(?:the )?winter(?: of)?"#)?,
1001+
datetime_check!(form!(Form::Year(_))),
1002+
|_, year| Ok(helpers::year_month_day(year.value().form_year()?, 12, 21)?
1003+
.span_to(&helpers::year_month_day(year.value().form_year()? + (1 as i32), 3, 20)?, false)?
1004+
.form(Form::Season))
1005+
);
1006+
b.rule_1_terminal("season - spring",
10111007
b.reg(r#"(?:the )?spring"#)?,
10121008
|_| Ok(helpers::month_day(3, 20)?
10131009
.span_to(&helpers::month_day(6, 21)?, false)?
@@ -1041,21 +1037,21 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
10411037
});
10421038
b.rule_2("<time-of-day> approximately",
10431039
datetime_check!(form!(Form::TimeOfDay(_))),
1044-
b.reg(r#"(?:-?ish|approximately)"#)?,
1040+
b.reg(r#"-?ish|approximately"#)?,
10451041
|datetime, _| Ok(datetime.value().clone().not_latent().precision(Precision::Approximate))
10461042
);
10471043
b.rule_2("about <time-of-day>",
1048-
b.reg(r#"(?:about|around|approximately)"#)?,
1044+
b.reg(r#"about|around|approximately"#)?,
10491045
datetime_check!(form!(Form::TimeOfDay(_))),
10501046
|_, datetime| Ok(datetime.value().clone().not_latent().precision(Precision::Approximate))
10511047
);
10521048
b.rule_2("<time-of-day> sharp",
10531049
datetime_check!(form!(Form::TimeOfDay(_))),
1054-
b.reg(r#"(?:sharp|exactly|precisely)"#)?,
1050+
b.reg(r#"sharp|exactly|precisely"#)?,
10551051
|datetime, _| Ok(datetime.value().clone().not_latent().precision(Precision::Exact))
10561052
);
10571053
b.rule_2("exactly <time-of-day>",
1058-
b.reg(r#"(?:exactly|precisely)"#)?,
1054+
b.reg(r#"exactly|precisely"#)?,
10591055
datetime_check!(form!(Form::TimeOfDay(_))),
10601056
|_, datetime| Ok(datetime.value().clone().not_latent().precision(Precision::Exact))
10611057
);

grammar/en/src/training.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ pub fn examples_datetime(v: &mut Vec<::rustling::train::Example<Dimension>>) {
155155
example!(v, check_moment!(c, [2013, 5, 12]), "three months hence");
156156
example!(v, check_moment!(c, [2015, 2]), "two years hence");
157157
example!(v, check_moment!(c, [2013, 12]), "one year after christmas");
158+
example!(v, check_moment!(c, [2014, 3, 1], Grain::Month), "march 2014", "in march 2014", "for march 2014");
159+
example!(v, check_moment!(c, [2005, 5, 1], Grain::Month), "may 2005", "in may 2005", "for may 2005");
160+
example!(v, check_moment_span!(c, [2014, 6, 21], [2014, 9, 24]), "summer 2014", "in summer 2014", "for summer 2014");
161+
example!(v, check_moment_span!(c, [2014, 12, 21], [2015, 3, 21]), "winter 2014", "in winter 2014", "for winter 2014");
158162
example!(v, check_moment_span!(c, [2013, 6, 21], [2013, 9, 24]), "this summer", "current summer");
159163
example!(v, check_moment_span!(c, [2012, 12, 21], [2013, 3, 21]), "this winter");
160164
example!(v, check_moment!(c, [2013, 12, 25]), "xmas", "christmas", "christmas day");

grammar/es/src/rules_datetime.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -798,22 +798,29 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
798798
friday.span_to(&monday, false)
799799
}
800800
);
801-
b.rule_1_terminal("season",
801+
b.rule_1_terminal("season - summer",
802802
b.reg(r#"verano"#)?,
803803
|_| helpers::month_day(6, 21)?
804804
.span_to(&helpers::month_day(9, 23)?, false)
805805
);
806-
b.rule_1_terminal("season",
806+
b.rule_1_terminal("season - fall",
807807
b.reg(r#"oto[ñn]o"#)?,
808808
|_| helpers::month_day(9, 23)?
809809
.span_to(&helpers::month_day(12, 21)?, false)
810810
);
811-
b.rule_1_terminal("season",
811+
b.rule_1_terminal("season - winter",
812812
b.reg(r#"invierno"#)?,
813813
|_| helpers::month_day(12, 21)?
814814
.span_to(&helpers::month_day(3, 20)?, false)
815815
);
816-
b.rule_1_terminal("season",
816+
b.rule_2("season - winter <year>",
817+
b.reg(r#"invierno(?: de)?"#)?,
818+
datetime_check!(form!(Form::Year(_))),
819+
|_, year| Ok(helpers::year_month_day(year.value().form_year()?, 12, 21)?
820+
.span_to(&helpers::year_month_day(year.value().form_year()? + (1 as i32), 3, 20)?, false)?
821+
.form(Form::Season))
822+
);
823+
b.rule_1_terminal("season - spring",
817824
b.reg(r#"primavera"#)?,
818825
|_| helpers::month_day(3, 20)?
819826
.span_to(&helpers::month_day(6, 21)?, false)

grammar/es/src/training.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,13 @@ pub fn examples_datetime(v: &mut Vec<::rustling::train::Example<Dimension>>) {
125125
example!(v, check_moment!(c, [2013, 1, 22]), "hace tres semanas");
126126
example!(v, check_moment!(c, [2012, 11, 12]), "hace tres meses");
127127
example!(v, check_moment!(c, [2011, 2]), "hace dos años");
128-
128+
example!(v, check_moment!(c, [2014, 3, 1], Grain::Month), "marzo 2014", "en marzo 2014", "por marzo 2014");
129+
example!(v, check_moment!(c, [2005, 5, 1], Grain::Month), "mayo 2005", "en mayo 2005", "por mayo 2005");
129130
// Seasons
130131
example!(v, check_moment_span!(c, [2013, 6, 21], [2013, 9, 24]), "este verano");
131132
example!(v, check_moment_span!(c, [2012, 12, 21], [2013, 3, 21]), "este invierno");
133+
example!(v, check_moment_span!(c, [2014, 6, 21], [2014, 9, 24]), "verano 2014", "en verano 2014", "para el verano 2014");
134+
example!(v, check_moment_span!(c, [2014, 12, 21], [2015, 3, 21]), "invierno 2014", "en invierno 2014", "para el invierno 2014");
132135

133136
// Holidays
134137
// TODO

grammar/fr/src/rules_datetime.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,13 @@ pub fn rules_datetime(b: &mut RuleSetBuilder<Dimension>) -> RustlingResult<()> {
948948
b.reg(r#"(?:cet )?hiver"#)?,
949949
|_| helpers::month_day(12, 21)?.span_to(&helpers::month_day(3, 20)?, false)
950950
);
951+
b.rule_2("season - winter <year>",
952+
b.reg(r#"hiver(?: de)?"#)?,
953+
datetime_check!(form!(Form::Year(_))),
954+
|_, year| Ok(helpers::year_month_day(year.value().form_year()?, 12, 21)?
955+
.span_to(&helpers::year_month_day(year.value().form_year()? + (1 as i32), 3, 20)?, false)?
956+
.form(Form::Season))
957+
);
951958
b.rule_1_terminal("season",
952959
b.reg(r#"(?:ce )?printemps"#)?,
953960
|_| helpers::month_day(3, 20)?.span_to(&helpers::month_day(6, 21)?, false)

grammar/fr/src/training.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ pub fn examples_datetime(v: &mut Vec<::rustling::train::Example<Dimension>>) {
258258
example!(v, check_moment!(c, [2013, 2, 12, 5, 0, 0]), "dans une demi heure", "dans 1/2h", "dans 1/2 h", "dans 1/2 heure");
259259
example!(v, check_moment!(c, [2013, 2, 12, 5, 15, 0]), "dans trois quarts d'heure", "dans 3/4h", "dans 3/4 h", "dans 3/4 heure");
260260
example!(v, check_moment!(c, [2016, 12, 15]), "15.12.2016", "15.12.16");
261+
example!(v, check_moment!(c, [2014, 3, 1], Grain::Month), "mars 2014", "en mars 2014", "pour mars 2014");
262+
example!(v, check_moment!(c, [2005, 5, 1], Grain::Month), "mai 2005", "en mai 2005", "pour mai 2005");
263+
example!(v, check_moment_span!(c, [2014, 6, 21], [2014, 9, 24]), "été 2014", "pour l'été 2014");
264+
example!(v, check_moment_span!(c, [2014, 12, 21], [2015, 3, 21]), "hiver 2014", "pour l'hiver 2014");
265+
261266
}
262267

263268
pub fn examples_durations(v: &mut Vec<::rustling::train::Example<Dimension>>) {

0 commit comments

Comments
 (0)