Consolidate days of the week and months for GA

Summary:
The Galeic ruleset has 12 separate rules for months, and 7 for days. This
change replaces those with a list of months/days and a single function
to create a list of rules from those. This is the same approach as is currently in the English ruleset.

Reviewed By: patapizza

Differential Revision: D5756222

fbshipit-source-id: ac4bc42
This commit is contained in:
Kevin Doherty 2017-09-01 12:15:53 -07:00 committed by Facebook Github Bot
parent b62be42077
commit c41b71c665
2 changed files with 66 additions and 207 deletions

View File

@ -21,7 +21,14 @@ import Data.String
classifiers :: Classifiers
classifiers
= HashMap.fromList
[("integer (numeric)",
[("Thursday",
Classifier{okData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0},
koData =
ClassData{prior = 0.0, unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [("", 0.0)], n = 2}}),
("integer (numeric)",
Classifier{okData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0},
@ -49,6 +56,13 @@ classifiers
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("Monday",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.0794415416798357,
likelihoods = HashMap.fromList [("", 0.0)], n = 6},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("dd/mm/yyyy",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.0986122886681098,
@ -69,9 +83,8 @@ classifiers
ClassData{prior = 0.0, unseen = -2.833213344056216,
likelihoods =
HashMap.fromList
[("day", -0.8266785731844679),
[("Monday", -1.3862943611198906), ("day", -0.8266785731844679),
("d\233 named-day", -2.0794415416798357),
("named-day", -1.3862943611198906),
("an named-day", -1.6739764335716716)],
n = 6},
koData =
@ -82,8 +95,7 @@ classifiers
ClassData{prior = 0.0, unseen = -1.9459101490553135,
likelihoods =
HashMap.fromList
[("day", -0.6931471805599453),
("named-day", -0.6931471805599453)],
[("Monday", -0.6931471805599453), ("day", -0.6931471805599453)],
n = 2},
koData =
ClassData{prior = -infinity, unseen = -1.0986122886681098,
@ -95,22 +107,12 @@ classifiers
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("named-day",
Classifier{okData =
ClassData{prior = -0.2876820724517809,
unseen = -2.0794415416798357,
likelihoods = HashMap.fromList [("", 0.0)], n = 6},
koData =
ClassData{prior = -1.3862943611198906,
unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [("", 0.0)], n = 2}}),
("an named-day",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.3978952727983707,
likelihoods =
HashMap.fromList
[("day", -0.6931471805599453),
("named-day", -0.6931471805599453)],
[("Monday", -0.6931471805599453), ("day", -0.6931471805599453)],
n = 4},
koData =
ClassData{prior = -infinity, unseen = -1.0986122886681098,
@ -138,9 +140,8 @@ classifiers
ClassData{prior = 0.0, unseen = -3.044522437723423,
likelihoods =
HashMap.fromList
[("day", -0.7985076962177716),
[("Monday", -1.3862943611198906), ("day", -0.7985076962177716),
("d\233 named-day", -2.3025850929940455),
("named-day", -1.3862943611198906),
("an named-day", -1.6094379124341003)],
n = 8},
koData =

View File

@ -13,6 +13,7 @@
module Duckling.Time.GA.Rules
( rules ) where
import Data.Text (Text)
import Prelude
import Duckling.Dimensions.Types
@ -32,15 +33,6 @@ ruleArInn = Rule
, prod = \_ -> tt . cycleNth TG.Day $ - 2
}
ruleNamedday :: Rule
ruleNamedday = Rule
{ name = "named-day"
, pattern =
[ regex "luai?n|lu\\.?"
]
, prod = \_ -> tt $ dayOfWeek 1
}
ruleNollaigNaMban :: Rule
ruleNollaigNaMban = Rule
{ name = "Nollaig na mBan"
@ -50,42 +42,6 @@ ruleNollaigNaMban = Rule
, prod = \_ -> tt $ monthDay 1 6
}
ruleNamedmonth12 :: Rule
ruleNamedmonth12 = Rule
{ name = "named-month"
, pattern =
[ regex "(mh?(\x00ed|i) )?(na )?nollai?g|nol\\.?"
]
, prod = \_ -> tt $ month 12
}
ruleNamedday2 :: Rule
ruleNamedday2 = Rule
{ name = "named-day"
, pattern =
[ regex "mh?(\x00e1|a)irt|m(\x00e1|a)?\\.?"
]
, prod = \_ -> tt $ dayOfWeek 2
}
ruleNamedday6 :: Rule
ruleNamedday6 = Rule
{ name = "named-day"
, pattern =
[ regex "sathai?rn|sa\\.?"
]
, prod = \_ -> tt $ dayOfWeek 6
}
ruleNamedmonth7 :: Rule
ruleNamedmonth7 = Rule
{ name = "named-month"
, pattern =
[ regex "(mh?(\x00ed|i) )?i(\x00fa|u)il|i(\x00fa|u)i\\.?"
]
, prod = \_ -> tt $ month 7
}
ruleInniu :: Rule
ruleInniu = Rule
{ name = "inniu"
@ -177,15 +133,6 @@ ruleTimeSeoChugainn = Rule
_ -> Nothing
}
ruleNamedday4 :: Rule
ruleNamedday4 = Rule
{ name = "named-day"
, pattern =
[ regex "d(\x00e9|e)ardaoin|d(\x00e9|e)?\\.?"
]
, prod = \_ -> tt $ dayOfWeek 4
}
ruleAmrach :: Rule
ruleAmrach = Rule
{ name = "amárach"
@ -208,24 +155,6 @@ ruleYearLatent2 = Rule
_ -> Nothing
}
ruleNamedmonth :: Rule
ruleNamedmonth = Rule
{ name = "named-month"
, pattern =
[ regex "(mh?(\x00ed|i) )?(an )?t?ean(\x00e1|a)ir|ean\\.?"
]
, prod = \_ -> tt $ month 1
}
ruleNamedmonth3 :: Rule
ruleNamedmonth3 = Rule
{ name = "named-month"
, pattern =
[ regex "(mh?(\x00ed|i) )?(an )?mh?(\x00e1|a)rta|m(\x00e1|a)r\\.?"
]
, prod = \_ -> tt $ month 3
}
ruleOrdinalRithe :: Rule
ruleOrdinalRithe = Rule
{ name = "<ordinal> ráithe"
@ -283,15 +212,6 @@ ruleDdmm = Rule
_ -> Nothing
}
ruleNamedmonth4 :: Rule
ruleNamedmonth4 = Rule
{ name = "named-month"
, pattern =
[ regex "(mh?(\x00ed|i) )?(an )?t?aibre(\x00e1|a)i?n|abr\\.?"
]
, prod = \_ -> tt $ month 4
}
ruleIGceannCycle :: Rule
ruleIGceannCycle = Rule
{ name = "i gceann <cycle>"
@ -321,15 +241,6 @@ ruleAnCycleDeTime = Rule
_ -> Nothing
}
ruleNamedday5 :: Rule
ruleNamedday5 = Rule
{ name = "named-day"
, pattern =
[ regex "h?aoine|ao\\.?"
]
, prod = \_ -> tt $ dayOfWeek 5
}
ruleDayofmonthordinalNamedmonth :: Rule
ruleDayofmonthordinalNamedmonth = Rule
{ name = "<day-of-month>(ordinal) <named-month>"
@ -385,15 +296,6 @@ ruleCycleInniu = Rule
_ -> Nothing
}
ruleNamedmonth2 :: Rule
ruleNamedmonth2 = Rule
{ name = "named-month"
, pattern =
[ regex "(mh?(\x00ed|i) )?(na )?feabhra|fea\\.?"
]
, prod = \_ -> tt $ month 2
}
ruleOrdinalCycleINdiaidhTime :: Rule
ruleOrdinalCycleINdiaidhTime = Rule
{ name = "<ordinal> <cycle> i ndiaidh <time>"
@ -436,24 +338,6 @@ ruleIntersect = Rule
_ -> Nothing
}
ruleNamedmonth6 :: Rule
ruleNamedmonth6 = Rule
{ name = "named-month"
, pattern =
[ regex "(mh?(\x00ed|i) )?(an )?mh?eith(ea|i)mh|mei\\.?"
]
, prod = \_ -> tt $ month 6
}
ruleNamedmonth8 :: Rule
ruleNamedmonth8 = Rule
{ name = "named-month"
, pattern =
[ regex "(mh?(\x00ed|i) )?(na )?l(\x00fa|u)nasa|l(\x00fa|u)n\\.?"
]
, prod = \_ -> tt $ month 8
}
ruleAnOrdinalCycleDeTime :: Rule
ruleAnOrdinalCycleDeTime = Rule
{ name = "an <ordinal> <cycle> de <time>"
@ -624,24 +508,6 @@ ruleAnCycleSeo = Rule
_ -> Nothing
}
ruleNamedmonth5 :: Rule
ruleNamedmonth5 = Rule
{ name = "named-month"
, pattern =
[ regex "(mh?(\x00ed|i) )?(na )?bh?ealtaine|bea\\.?"
]
, prod = \_ -> tt $ month 5
}
ruleNamedday7 :: Rule
ruleNamedday7 = Rule
{ name = "named-day"
, pattern =
[ regex "domhnai?[cg]h|do\\.?"
]
, prod = \_ -> tt $ dayOfWeek 7
}
ruleAnDayofmonthNonOrdinal :: Rule
ruleAnDayofmonthNonOrdinal = Rule
{ name = "an <day-of-month> (non ordinal)"
@ -681,15 +547,6 @@ ruleYear = Rule
_ -> Nothing
}
ruleNamedmonth10 :: Rule
ruleNamedmonth10 = Rule
{ name = "named-month"
, pattern =
[ regex "(mh?(\x00ed|i) )?dh?eireadh f(\x00f3|o)mhair|def?\\.?"
]
, prod = \_ -> tt $ month 10
}
ruleCycleRoimhTime :: Rule
ruleCycleRoimhTime = Rule
{ name = "<cycle> roimh <time>"
@ -731,15 +588,6 @@ ruleDdmmyyyy = Rule
_ -> Nothing
}
ruleNamedmonth11 :: Rule
ruleNamedmonth11 = Rule
{ name = "named-month"
, pattern =
[ regex "(mh?(\x00ed|i) )?(na )?samh(ain|na)|sam\\.?"
]
, prod = \_ -> tt $ month 11
}
ruleAnNamedday :: Rule
ruleAnNamedday = Rule
{ name = "an named-day"
@ -752,13 +600,49 @@ ruleAnNamedday = Rule
_ -> Nothing
}
ruleNamedday3 :: Rule
ruleNamedday3 = Rule
{ name = "named-day"
, pattern =
[ regex "ch?(\x00e9|e)adaoin|c(\x00e9|e)\\.?"
daysOfWeek :: [(Text, String)]
daysOfWeek =
[ ( "Monday" , "luai?n|lu\\.?" )
, ( "Tuesday" , "mh?(\x00e1|a)irt|m(\x00e1|a)?\\.?" )
, ( "Wednesday", "ch?(\x00e9|e)adaoin|c(\x00e9|e)\\.?" )
, ( "Thursday" , "d(\x00e9|e)ardaoin|d(\x00e9|e)?\\.?" )
, ( "Friday" , "h?aoine|ao\\.?" )
, ( "Saturday" , "sathai?rn|sa\\.?" )
, ( "Sunday" , "domhnai?[cg]h|do\\.?" )
]
, prod = \_ -> tt $ dayOfWeek 3
ruleDaysOfWeek :: [Rule]
ruleDaysOfWeek = zipWith go daysOfWeek [1..7]
where
go (name, regexPattern) i = Rule
{ name = name
, pattern = [regex regexPattern]
, prod = \_ -> tt $ dayOfWeek i
}
months :: [(Text, String)]
months =
[ ( "January" , "(mh?(\x00ed|i) )?(an )?t?ean(\x00e1|a)ir|ean\\.?" )
, ( "February" , "(mh?(\x00ed|i) )?(na )?feabhra|fea\\.?" )
, ( "March" , "(mh?(\x00ed|i) )?(an )?mh?(\x00e1|a)rta|m(\x00e1|a)r\\.?" )
, ( "April" , "(mh?(\x00ed|i) )?(an )?t?aibre(\x00e1|a)i?n|abr\\.?" )
, ( "May" , "(mh?(\x00ed|i) )?(na )?bh?ealtaine|bea\\.?" )
, ( "June" , "(mh?(\x00ed|i) )?(an )?mh?eith(ea|i)mh|mei\\.?" )
, ( "July" , "(mh?(\x00ed|i) )?i(\x00fa|u)il|i(\x00fa|u)i\\.?" )
, ( "August" , "(mh?(\x00ed|i) )?(na )?l(\x00fa|u)nasa|l(\x00fa|u)n\\.?" )
, ( "September", "(mh?(\x00ed|i) )?mh?e(\x00e1|a)n f(\x00f3|o)mhair|mef?\\.?")
, ( "October" , "(mh?(\x00ed|i) )?(na )?nollai?g|nol\\.?" )
, ( "November" , "(mh?(\x00ed|i) )?(na )?samh(ain|na)|sam\\.?" )
, ( "December" , "(mh?(\x00ed|i) )?(na )?nollai?g|nol\\.?" )
]
ruleMonths :: [Rule]
ruleMonths = zipWith go months [1..12]
where
go (name, regexPattern) i = Rule
{ name = name
, pattern = [regex regexPattern]
, prod = \_ -> tt $ month i
}
ruleCycleINdiaidhTime :: Rule
@ -775,15 +659,6 @@ ruleCycleINdiaidhTime = Rule
_ -> Nothing
}
ruleNamedmonth9 :: Rule
ruleNamedmonth9 = Rule
{ name = "named-month"
, pattern =
[ regex "(mh?(\x00ed|i) )?mh?e(\x00e1|a)n f(\x00f3|o)mhair|mef?\\.?"
]
, prod = \_ -> tt $ month 9
}
ruleDayofmonthordinalNamedmonthYear :: Rule
ruleDayofmonthordinalNamedmonthYear = Rule
{ name = "<day-of-month>(ordinal) <named-month> year"
@ -837,25 +712,6 @@ rules =
, ruleLFhilePdraig
, ruleLFhileVailintn
, ruleLNaNaithreacha
, ruleNamedday
, ruleNamedday2
, ruleNamedday3
, ruleNamedday4
, ruleNamedday5
, ruleNamedday6
, ruleNamedday7
, ruleNamedmonth
, ruleNamedmonth10
, ruleNamedmonth11
, ruleNamedmonth12
, ruleNamedmonth2
, ruleNamedmonth3
, ruleNamedmonth4
, ruleNamedmonth5
, ruleNamedmonth6
, ruleNamedmonth7
, ruleNamedmonth8
, ruleNamedmonth9
, ruleNollaigNaMban
, ruleOnANamedday
, ruleOrdinalCycleDeTime
@ -870,3 +726,5 @@ rules =
, ruleYearLatent2
, ruleYyyymmdd
]
++ ruleDaysOfWeek
++ ruleMonths