Add Japanese time dimension (#646)

Summary:
Add the most common rules for Japanese time dimension.

Pull Request resolved: https://github.com/facebook/duckling/pull/646

Reviewed By: stroxler

Differential Revision: D30675005

Pulled By: chessai

fbshipit-source-id: 917aa98b5cfe0c73d207b1f51b80d8e17a1c7e6a
This commit is contained in:
Ovidiu Nistor 2021-09-21 12:21:05 -07:00 committed by Facebook GitHub Bot
parent 84175d61d6
commit dd70d80dc1
14 changed files with 2318 additions and 12 deletions

View File

@ -17,4 +17,5 @@ allDimensions =
, Seal Numeral
, Seal Ordinal
, Seal Temperature
, Seal Time
]

View File

@ -9,6 +9,7 @@
module Duckling.Duration.JA.Corpus
( corpus
, negativeCorpus
) where
import Prelude
@ -23,6 +24,13 @@ import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale JA Nothing}, testOptions, allExamples)
negativeCorpus :: NegativeCorpus
negativeCorpus = (testContext {locale = makeLocale JA Nothing}, testOptions, examples)
where
examples =
[ "月面"
]
allExamples :: [Example]
allExamples = concat
[ examples (DurationData 1 Second)
@ -36,4 +44,7 @@ allExamples = concat
[ "百 日"
, "百 日間"
]
, examples (DurationData 2 Month)
[ "2ヶ月"
]
]

View File

@ -0,0 +1,43 @@
-- Copyright (c) 2016-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree.
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Duration.JA.Rules
( rules
) where
import Data.String
import Prelude
import Duckling.Dimensions.Types
import Duckling.Duration.Helpers
import Duckling.Numeral.Helpers (numberWith)
import Duckling.Numeral.Types (NumeralData(..))
import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.TimeGrain.Types as TG
ruleDurationMonthWithCounter :: Rule
ruleDurationMonthWithCounter = Rule
{ name = "<integer> counter months"
, pattern =
[ numberWith TNumeral.value (>= 1)
, regex "(ケ|ヶ|カ|ヵ|か|箇)(月|げつ|つき)"
]
, prod = \case
(Token Numeral TNumeral.NumeralData{TNumeral.value = v}:
_) -> Just $ Token Duration $ duration TG.Month $ floor v
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleDurationMonthWithCounter
]

View File

@ -19,4 +19,970 @@ import qualified Data.HashMap.Strict as HashMap
import Duckling.Ranking.Types
classifiers :: Classifiers
classifiers = HashMap.fromList []
classifiers
= HashMap.fromList
[("\21320\24460|\21320\21069 <time-of-day>",
Classifier{okData =
ClassData{prior = -0.35667494393873245,
unseen = -3.5553480614894135,
likelihoods =
HashMap.fromList
[("<time-of-day> o'clock", -2.1400661634962708),
("time-of-day (latent)", -2.1400661634962708),
("hh:mm", -2.4277482359480516), ("hour", -1.580450375560848),
("hh\26178mm\20998", -1.580450375560848),
("minute", -1.329135947279942)],
n = 14},
koData =
ClassData{prior = -1.2039728043259361,
unseen = -2.9444389791664407,
likelihoods =
HashMap.fromList
[("time-of-day (latent)", -0.9444616088408514),
("hour", -0.9444616088408514)],
n = 6}}),
("Thursday",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("integer (numeric)",
Classifier{okData =
ClassData{prior = -0.9572987556015321, unseen = -4.875197323201151,
likelihoods = HashMap.fromList [("", 0.0)], n = 129},
koData =
ClassData{prior = -0.4843923666978351, unseen = -5.342334251964811,
likelihoods = HashMap.fromList [("", 0.0)], n = 207}}),
("integer (20..90)",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [("integer (0..10)", 0.0)], n = 2},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("yyyy/mm",
Classifier{okData =
ClassData{prior = -1.9459101490553135, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -0.15415067982725836,
unseen = -3.258096538021482,
likelihoods = HashMap.fromList [("", 0.0)], n = 24}}),
("today",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.3978952727983707,
likelihoods = HashMap.fromList [("", 0.0)], n = 9},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("mm/dd",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.6094379124341003,
likelihoods = HashMap.fromList [("", 0.0)], n = 3},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("at <time-of-day>",
Classifier{okData =
ClassData{prior = -0.5108256237659907, unseen = -2.833213344056216,
likelihoods =
HashMap.fromList
[("hh\26178mm\20998", -0.8266785731844679),
("minute", -0.8266785731844679)],
n = 6},
koData =
ClassData{prior = -0.916290731874155, unseen = -2.5649493574615367,
likelihoods =
HashMap.fromList
[("time-of-day (latent)", -0.8754687373538999),
("hour", -0.8754687373538999)],
n = 4}}),
("Imperial year (latent)",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.9459101490553135,
likelihoods = HashMap.fromList [("integer (numeric)", 0.0)],
n = 5},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("December",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("September",
Classifier{okData =
ClassData{prior = -0.40546510810816444,
unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -1.0986122886681098,
unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [("", 0.0)], n = 2}}),
("last|past|next <duration>",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.3025850929940455,
likelihoods =
HashMap.fromList
[("day", -1.0986122886681098),
("<integer> <unit-of-duration>", -0.8109302162163288),
("hour", -1.5040773967762742)],
n = 3},
koData =
ClassData{prior = -infinity, unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [], n = 0}}),
("October",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("month (grain)",
Classifier{okData =
ClassData{prior = -2.6790626642289577,
unseen = -2.1972245773362196,
likelihoods = HashMap.fromList [("", 0.0)], n = 7},
koData =
ClassData{prior = -7.109592168373022e-2,
unseen = -4.574710978503383,
likelihoods = HashMap.fromList [("", 0.0)], n = 95}}),
("<time-of-day> o'clock",
Classifier{okData =
ClassData{prior = 0.0, unseen = -3.0910424533583156,
likelihoods =
HashMap.fromList
[("\21320\24460|\21320\21069 <time-of-day>",
-1.6582280766035324),
("time-of-day (latent)", -1.0986122886681098),
("hour", -0.7419373447293773)],
n = 9},
koData =
ClassData{prior = -infinity, unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [], n = 0}}),
("January",
Classifier{okData =
ClassData{prior = -0.40546510810816444,
unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -1.0986122886681098,
unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [("", 0.0)], n = 2}}),
("this quarter",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.6094379124341003,
likelihoods = HashMap.fromList [("", 0.0)], n = 3},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("Wednesday",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("November",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("July",
Classifier{okData =
ClassData{prior = 0.0, unseen = -3.1780538303479458,
likelihoods = HashMap.fromList [("", 0.0)], n = 22},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("hour (grain)",
Classifier{okData =
ClassData{prior = -0.8209805520698302,
unseen = -2.5649493574615367,
likelihoods = HashMap.fromList [("", 0.0)], n = 11},
koData =
ClassData{prior = -0.579818495252942, unseen = -2.772588722239781,
likelihoods = HashMap.fromList [("", 0.0)], n = 14}}),
("<year> - <year>",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.791759469228055,
likelihoods =
HashMap.fromList [("integer (numeric)integer (numeric)", 0.0)],
n = 4},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("from <time> to <time>",
Classifier{okData =
ClassData{prior = -0.7801585575495751, unseen = -4.04305126783455,
likelihoods =
HashMap.fromList
[("yearyear", -2.639057329615259),
("yyyy/mm/ddyyyy/mm/dd", -2.4159137783010487),
("dayday", -2.4159137783010487),
("year (latent)year (latent)", -2.639057329615259),
("monthmonth", -1.252762968495368),
("<year> <named-month><year> <named-month>",
-2.0794415416798357),
("JuneJuly", -2.4159137783010487),
("<year> <named-month>July", -2.2335922215070942)],
n = 22},
koData =
ClassData{prior = -0.6131044728864089, unseen = -4.174387269895637,
likelihoods =
HashMap.fromList
[("daymonth", -1.3862943611198906),
("MondayJuly", -1.8562979903656263),
("June<year> <named-month>", -2.2129729343043585),
("monthmonth", -1.6739764335716716),
("JuneJuly", -2.367123614131617),
("Monday<year> <named-month>", -2.2129729343043585)],
n = 26}}),
("May",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("First Imperial year (latent)",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [("", 0.0)], n = 1},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("year (grain)",
Classifier{okData =
ClassData{prior = -2.120263536200091, unseen = -2.3978952727983707,
likelihoods = HashMap.fromList [("", 0.0)], n = 9},
koData =
ClassData{prior = -0.12783337150988489,
unseen = -4.219507705176107,
likelihoods = HashMap.fromList [("", 0.0)], n = 66}}),
("Saturday",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("last year",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [("", 0.0)], n = 2},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("<time> - <time>",
Classifier{okData =
ClassData{prior = -1.0055218656020977, unseen = -4.574710978503383,
likelihoods =
HashMap.fromList
[("<year> <named-month>in <month>", -3.871201010907891),
("<year> <named-month>until <time>", -3.4657359027997265),
("Junein <named-month>", -3.871201010907891),
("yyyy/mm/ddmm/dd", -3.871201010907891),
("yearyear", -2.2617630984737906),
("yyyy/mm/ddyyyy/mm/dd", -3.4657359027997265),
("dayday", -2.9549102790337356),
("year (latent)year (latent)", -2.4849066497880004),
("monthmonth", -1.6739764335716716),
("<year> <named-month><year> <named-month>",
-2.6184380424125226),
("JuneJuly", -3.1780538303479458),
("Juneuntil <time>", -3.871201010907891),
("Junein <month>", -3.871201010907891),
("year (latent)in <year>", -3.871201010907891),
("year (latent)until <time>", -3.871201010907891),
("yyyy/mm/dduntil <time>", -3.871201010907891),
("<year> <named-month>July", -3.4657359027997265)],
n = 30},
koData =
ClassData{prior = -0.45547552868282576,
unseen = -4.948759890378168,
likelihoods =
HashMap.fromList
[("dayhour", -2.995732273553991),
("daymonth", -1.9459101490553135),
("monthyear", -2.995732273553991),
("yyyy/mm/ddyyyy/mm", -3.8430301339411947),
("MondayJuly", -3.1498829533812494),
("June<year> <named-month>", -2.995732273553991),
("monthhour", -2.8622008809294686),
("Mondayyear (latent)", -3.5553480614894135),
("monthmonth", -2.456735772821304),
("Junetime-of-day (latent)", -3.1498829533812494),
("dayyear", -3.5553480614894135),
("JuneJuly", -3.8430301339411947),
("Juneuntil <time>", -3.8430301339411947),
("Junein <month>", -4.248495242049359),
("<year> <named-month>year (latent)", -3.5553480614894135),
("Juneyear (latent)", -3.5553480614894135),
("Mondaytime-of-day (latent)", -3.1498829533812494),
("yyyy/mm/ddtime-of-day (latent)", -4.248495242049359),
("Mondayuntil <time>", -3.5553480614894135),
("Mondayin <month>", -3.8430301339411947),
("Mondayin <named-month>", -4.248495242049359),
("<year> <named-month>time-of-day (latent)",
-3.8430301339411947),
("Monday<year> <named-month>", -2.995732273553991)],
n = 52}}),
("year (latent)",
Classifier{okData =
ClassData{prior = -1.739174271186922e-2,
unseen = -4.07753744390572,
likelihoods = HashMap.fromList [("integer (numeric)", 0.0)],
n = 57},
koData =
ClassData{prior = -4.060443010546419, unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [("integer (numeric)", 0.0)],
n = 1}}),
("yyyy/mm/dd",
Classifier{okData =
ClassData{prior = 0.0, unseen = -3.258096538021482,
likelihoods = HashMap.fromList [("", 0.0)], n = 24},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("Monday",
Classifier{okData =
ClassData{prior = -2.583997552432231, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -7.847161544149521e-2,
unseen = -3.9318256327243257,
likelihoods = HashMap.fromList [("", 0.0)], n = 49}}),
("yesterday",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("<integer> counter months",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.70805020110221,
likelihoods = HashMap.fromList [("integer (numeric)", 0.0)],
n = 13},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("last <time-grain>",
Classifier{okData =
ClassData{prior = 0.0, unseen = -4.727387818712341,
likelihoods =
HashMap.fromList
[("week", -2.9267394020670396),
("month (grain)", -3.109060958860994),
("hour (grain)", -2.772588722239781),
("year (grain)", -2.9267394020670396),
("second", -2.320603598496724),
("week (grain)", -2.9267394020670396),
("day", -3.619886582626985), ("quarter", -2.772588722239781),
("minute (grain)", -2.320603598496724),
("year", -2.9267394020670396),
("second (grain)", -2.320603598496724),
("hour", -2.772588722239781), ("month", -3.109060958860994),
("quarter (grain)", -2.772588722239781),
("minute", -2.320603598496724),
("day (grain)", -3.619886582626985)],
n = 48},
koData =
ClassData{prior = -infinity, unseen = -2.833213344056216,
likelihoods = HashMap.fromList [], n = 0}}),
("last week",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [("", 0.0)], n = 1},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("April",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("week (grain)",
Classifier{okData =
ClassData{prior = -6.899287148695143e-2,
unseen = -2.772588722239781,
likelihoods = HashMap.fromList [("", 0.0)], n = 14},
koData =
ClassData{prior = -2.70805020110221, unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [("", 0.0)], n = 1}}),
("now",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.9459101490553135,
likelihoods = HashMap.fromList [("", 0.0)], n = 5},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("<year> <named-month> <day-of-month>",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.70805020110221,
likelihoods =
HashMap.fromList
[("Augustinteger (numeric)", -1.9459101490553135),
("Marchinteger (numeric)", -1.252762968495368),
("Juneinteger (numeric)", -1.9459101490553135),
("month", -0.8472978603872037)],
n = 5},
koData =
ClassData{prior = -infinity, unseen = -1.6094379124341003,
likelihoods = HashMap.fromList [], n = 0}}),
("Friday",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("tomorrow",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("this year",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [("", 0.0)], n = 1},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("fractional number",
Classifier{okData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0},
koData =
ClassData{prior = 0.0, unseen = -3.295836866004329,
likelihoods = HashMap.fromList [("", 0.0)], n = 25}}),
("Sunday",
Classifier{okData =
ClassData{prior = -1.4469189829363254, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -0.2682639865946794, unseen = -2.70805020110221,
likelihoods = HashMap.fromList [("", 0.0)], n = 13}}),
("June",
Classifier{okData =
ClassData{prior = 0.0, unseen = -3.871201010907891,
likelihoods = HashMap.fromList [("", 0.0)], n = 46},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("in/for the last <duration>",
Classifier{okData =
ClassData{prior = -0.3364722366212129, unseen = -2.833213344056216,
likelihoods =
HashMap.fromList
[("<integer> counter months", -1.6739764335716716),
("day", -2.0794415416798357), ("year", -1.6739764335716716),
("<integer> <unit-of-duration>", -1.3862943611198906),
("month", -1.6739764335716716)],
n = 5},
koData =
ClassData{prior = -1.252762968495368, unseen = -2.3978952727983707,
likelihoods =
HashMap.fromList
[("week", -1.6094379124341003), ("day", -1.6094379124341003),
("<integer> <unit-of-duration>", -1.2039728043259361)],
n = 2}}),
("February",
Classifier{okData =
ClassData{prior = -0.5596157879354228, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -0.8472978603872037,
unseen = -1.6094379124341003,
likelihoods = HashMap.fromList [("", 0.0)], n = 3}}),
("minute (grain)",
Classifier{okData =
ClassData{prior = -0.3364722366212129,
unseen = -3.0910424533583156,
likelihoods = HashMap.fromList [("", 0.0)], n = 20},
koData =
ClassData{prior = -1.252762968495368, unseen = -2.3025850929940455,
likelihoods = HashMap.fromList [("", 0.0)], n = 8}}),
("time-of-day (latent)",
Classifier{okData =
ClassData{prior = -1.466337068793427, unseen = -2.1972245773362196,
likelihoods =
HashMap.fromList [("integer (numeric)", -0.13353139262452263)],
n = 6},
koData =
ClassData{prior = -0.262364264467491, unseen = -3.1354942159291497,
likelihoods =
HashMap.fromList
[("integer (numeric)", -0.1466034741918754),
("integer (0..10)", -1.9924301646902063)],
n = 20}}),
("<integer> <unit-of-duration>",
Classifier{okData =
ClassData{prior = -2.6149597780361984, unseen = -4.060443010546419,
likelihoods =
HashMap.fromList
[("week", -2.9444389791664407),
("integer (numeric)day (grain)", -2.6567569067146595),
("integer (0..10)year (grain)", -3.349904087274605),
("integer (numeric)year (grain)", -3.349904087274605),
("day", -2.6567569067146595), ("year", -2.9444389791664407),
("integer (numeric)week (grain)", -3.349904087274605),
("hour", -3.349904087274605),
("integer (0..10)week (grain)", -3.349904087274605),
("integer (numeric)minute (grain)", -1.6451559950361796),
("minute", -1.6451559950361796),
("integer (numeric)hour (grain)", -3.349904087274605)],
n = 18},
koData =
ClassData{prior = -7.598590697792199e-2,
unseen = -6.169610732491456,
likelihoods =
HashMap.fromList
[("week", -5.474369310328396),
("integer (0..10)month (grain)", -3.223077511721901),
("integer (0..10)hour (grain)", -5.0689042022202315),
("integer (numeric)day (grain)", -3.459466289786131),
("integer (11..19)month (grain)", -5.0689042022202315),
("second", -3.970291913552122),
("integer (numeric)second (grain)", -3.970291913552122),
("integer (numeric)year (grain)", -1.9628238714973751),
("day", -3.459466289786131), ("year", -1.9628238714973751),
("integer (0..10)minute (grain)", -5.0689042022202315),
("integer (numeric)week (grain)", -5.474369310328396),
("integer (20..90)minute (grain)", -5.0689042022202315),
("hour", -2.9486406660201405), ("month", -1.5825490122177692),
("integer (numeric)minute (grain)", -3.459466289786131),
("integer (numeric)month (grain)", -1.8108076641987496),
("minute", -3.223077511721901),
("integer (numeric)hour (grain)", -3.0320222749591914)],
n = 228}}),
("integer (11..19)",
Classifier{okData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0},
koData =
ClassData{prior = 0.0, unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [("integer (0..10)", 0.0)],
n = 2}}),
("<time-of-day> am|pm",
Classifier{okData =
ClassData{prior = -0.6931471805599453,
unseen = -2.5649493574615367,
likelihoods =
HashMap.fromList
[("hh:mm", -0.8754687373538999),
("minute", -0.8754687373538999)],
n = 4},
koData =
ClassData{prior = -0.6931471805599453,
unseen = -2.5649493574615367,
likelihoods =
HashMap.fromList
[("time-of-day (latent)", -0.8754687373538999),
("hour", -0.8754687373538999)],
n = 4}}),
("on the <day-of-month>",
Classifier{okData =
ClassData{prior = -0.9808292530117262,
unseen = -1.6094379124341003,
likelihoods = HashMap.fromList [("integer (numeric)", 0.0)],
n = 3},
koData =
ClassData{prior = -0.4700036292457356,
unseen = -1.9459101490553135,
likelihoods = HashMap.fromList [("integer (numeric)", 0.0)],
n = 5}}),
("on <day>",
Classifier{okData =
ClassData{prior = -0.7646061445420903, unseen = -4.204692619390966,
likelihoods =
HashMap.fromList
[("mm/dd", -3.4965075614664802),
("Wednesday", -3.4965075614664802),
("Saturday", -3.4965075614664802),
("yyyy/mm/dd", -2.3978952727983707),
("Monday", -3.4965075614664802),
("<year> <named-month> <day-of-month>", -2.580216829592325),
("day", -0.8574502318512216), ("Sunday", -3.4965075614664802),
("Tuesday", -2.1102132003465894),
("<named-month> <day-of-month>", -3.4965075614664802),
("imperial <year> <named-month> <day-of-month>",
-2.3978952727983707)],
n = 27},
koData =
ClassData{prior = -0.6264558060612732, unseen = -4.31748811353631,
likelihoods =
HashMap.fromList
[("<time> - <time>", -3.20545280453606),
("Monday", -1.5960148921019597), ("day", -0.8383291904044432),
("Sunday", -1.8191584434161694),
("<named-month> <day-of-month>", -2.6946271807700692)],
n = 31}}),
("this|current <time-grain>",
Classifier{okData =
ClassData{prior = -3.922071315328127e-2,
unseen = -4.143134726391533,
likelihoods =
HashMap.fromList
[("week", -2.181224235989778),
("month (grain)", -2.740840023925201),
("hour (grain)", -2.517696472610991),
("year (grain)", -3.028522096376982),
("week (grain)", -2.181224235989778),
("day", -2.517696472610991), ("quarter", -2.181224235989778),
("year", -3.028522096376982), ("hour", -2.517696472610991),
("month", -2.740840023925201),
("quarter (grain)", -2.181224235989778),
("day (grain)", -2.517696472610991)],
n = 25},
koData =
ClassData{prior = -3.258096538021482, unseen = -2.70805020110221,
likelihoods =
HashMap.fromList
[("day", -1.9459101490553135),
("day (grain)", -1.9459101490553135)],
n = 1}}),
("hh:mm",
Classifier{okData =
ClassData{prior = -0.13353139262452263,
unseen = -2.1972245773362196,
likelihoods = HashMap.fromList [("", 0.0)], n = 7},
koData =
ClassData{prior = -2.0794415416798357,
unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [("", 0.0)], n = 1}}),
("in <year>",
Classifier{okData =
ClassData{prior = -9.53101798043249e-2,
unseen = -3.258096538021482,
likelihoods =
HashMap.fromList
[("Imperial year (latent)", -1.6094379124341003),
("First Imperial year (latent)", -2.5257286443082556),
("<time> - <time>", -2.5257286443082556),
("year (latent)", -1.6094379124341003),
("year", -0.8209805520698302)],
n = 10},
koData =
ClassData{prior = -2.3978952727983707,
unseen = -2.0794415416798357,
likelihoods =
HashMap.fromList
[("year (latent)", -1.252762968495368),
("year", -1.252762968495368)],
n = 1}}),
("second (grain)",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.4849066497880004,
likelihoods = HashMap.fromList [("", 0.0)], n = 10},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("until <time>",
Classifier{okData =
ClassData{prior = -0.7375989431307791, unseen = -4.07753744390572,
likelihoods =
HashMap.fromList
[("July", -2.6741486494265287),
("year (latent)", -2.451005098112319),
("yyyy/mm/dd", -2.451005098112319),
("<year> <named-month> <day-of-month>", -3.367295829986474),
("day", -1.9810014688665833), ("June", -2.268683541318364),
("year", -2.451005098112319), ("month", -1.575536360758419),
("<named-month> <day-of-month>", -3.367295829986474),
("<year> <named-month>", -2.6741486494265287),
("imperial <year> <named-month> <day-of-month>",
-3.367295829986474)],
n = 22},
koData =
ClassData{prior = -0.6505875661411494, unseen = -4.143134726391533,
likelihoods =
HashMap.fromList
[("<time> - <time>", -1.729239112246721),
("yyyy/mm/dd", -2.740840023925201),
("Monday", -1.929909807708872), ("day", -1.1826954058786512),
("Sunday", -3.028522096376982), ("year", -3.4339872044851463),
("month", -2.3353749158170367),
("<named-month> <day-of-month>", -3.4339872044851463)],
n = 24}}),
("in <month>",
Classifier{okData =
ClassData{prior = -0.24512245803298496,
unseen = -3.8066624897703196,
likelihoods =
HashMap.fromList
[("yyyy/mm", -2.174751721484161), ("July", -2.6855773452501515),
("<time> - <time>", -2.6855773452501515),
("June", -2.174751721484161), ("March", -2.3978952727983707),
("month", -0.8397506547518206),
("<year> <named-month>", -2.3978952727983707)],
n = 18},
koData =
ClassData{prior = -1.5260563034950494,
unseen = -2.9444389791664407,
likelihoods =
HashMap.fromList
[("September", -2.1972245773362196),
("July", -1.791759469228055),
("<time> - <time>", -2.1972245773362196),
("month", -1.0986122886681098),
("<year> <named-month>", -2.1972245773362196)],
n = 5}}),
("March",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.772588722239781,
likelihoods = HashMap.fromList [("", 0.0)], n = 14},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("hh\26178mm\20998",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.890371757896165,
likelihoods =
HashMap.fromList
[("integer (0..10)integer (20..90)", -1.7346010553881064),
("", -0.8873031950009028),
("integer (numeric)integer (numeric)", -0.8873031950009028)],
n = 14},
koData =
ClassData{prior = -infinity, unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [], n = 0}}),
("decimal number",
Classifier{okData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0},
koData =
ClassData{prior = 0.0, unseen = -2.3025850929940455,
likelihoods = HashMap.fromList [("", 0.0)], n = 8}}),
("next week",
Classifier{okData =
ClassData{prior = -0.6931471805599453,
unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [("", 0.0)], n = 1},
koData =
ClassData{prior = -0.6931471805599453,
unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [("", 0.0)], n = 1}}),
("in <duration>",
Classifier{okData =
ClassData{prior = -0.16034265007517937,
unseen = -3.9889840465642745,
likelihoods =
HashMap.fromList
[("week", -2.871679624884012),
("<integer> counter months", -1.4853852637641216),
("<integer> <unit-of-duration>", -1.405342556090585),
("month", -1.4853852637641216),
("minute", -1.5723966407537513)],
n = 23},
koData =
ClassData{prior = -1.9095425048844386, unseen = -2.772588722239781,
likelihoods =
HashMap.fromList
[("day", -2.0149030205422647), ("year", -2.0149030205422647),
("<integer> <unit-of-duration>", -1.0986122886681098),
("month", -2.0149030205422647),
("minute", -2.0149030205422647)],
n = 4}}),
("Tuesday",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.639057329615259,
likelihoods = HashMap.fromList [("", 0.0)], n = 12},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("in <named-month>",
Classifier{okData =
ClassData{prior = -0.17185025692665928,
unseen = -3.6375861597263857,
likelihoods =
HashMap.fromList
[("July", -2.512305623976115), ("June", -1.413693335308005),
("March", -1.6650077635889111), ("month", -0.7777045685880083)],
n = 16},
koData =
ClassData{prior = -1.845826690498331, unseen = -2.4849066497880004,
likelihoods =
HashMap.fromList
[("September", -1.7047480922384253),
("July", -1.2992829841302609), ("month", -1.0116009116784799)],
n = 3}}),
("<named-month> <day-of-month>",
Classifier{okData =
ClassData{prior = -1.0986122886681098,
unseen = -2.3978952727983707,
likelihoods =
HashMap.fromList
[("Marchinteger (numeric)", -1.2039728043259361),
("Juneinteger (numeric)", -1.6094379124341003),
("month", -0.916290731874155)],
n = 3},
koData =
ClassData{prior = -0.40546510810816444,
unseen = -2.833213344056216,
likelihoods =
HashMap.fromList
[("Augustinteger (numeric)", -1.3862943611198906),
("Marchinteger (numeric)", -1.6739764335716716),
("Juneinteger (numeric)", -2.0794415416798357),
("month", -0.8266785731844679)],
n = 6}}),
("integer (0..10)",
Classifier{okData =
ClassData{prior = -1.8971199848858813,
unseen = -2.0794415416798357,
likelihoods = HashMap.fromList [("", 0.0)], n = 6},
koData =
ClassData{prior = -0.16251892949777494, unseen = -3.58351893845611,
likelihoods = HashMap.fromList [("", 0.0)], n = 34}}),
("next <time-grain>",
Classifier{okData =
ClassData{prior = -0.6931471805599453,
unseen = -1.6094379124341003,
likelihoods =
HashMap.fromList
[("week", -0.6931471805599453),
("week (grain)", -0.6931471805599453)],
n = 1},
koData =
ClassData{prior = -0.6931471805599453,
unseen = -1.6094379124341003,
likelihoods =
HashMap.fromList
[("week", -0.6931471805599453),
("week (grain)", -0.6931471805599453)],
n = 1}}),
("quarter (grain)",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.639057329615259,
likelihoods = HashMap.fromList [("", 0.0)], n = 12},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("a week after next",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [("", 0.0)], n = 2},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("week-end",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [("", 0.0)], n = 2},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("this month",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [("", 0.0)], n = 1},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("day (grain)",
Classifier{okData =
ClassData{prior = -0.9382696385929302,
unseen = -2.3978952727983707,
likelihoods = HashMap.fromList [("", 0.0)], n = 9},
koData =
ClassData{prior = -0.496436886313891, unseen = -2.772588722239781,
likelihoods = HashMap.fromList [("", 0.0)], n = 14}}),
("<year> <named-month>",
Classifier{okData =
ClassData{prior = -0.3468709438421116, unseen = -4.543294782270004,
likelihoods =
HashMap.fromList
[("year (latent)July", -2.45315795147342),
("year (latent)June", -1.536867219599265),
("yearmonth", -0.7949298748698876),
("year (latent)in <month>", -3.146305132033365),
("year (latent)until <time>", -3.146305132033365),
("year (latent)March", -3.4339872044851463),
("year (latent)in <named-month>", -3.146305132033365),
("year (latent)from <time>", -2.9231615807191553)],
n = 41},
koData =
ClassData{prior = -1.2272296664902034, unseen = -3.828641396489095,
likelihoods =
HashMap.fromList
[("Imperial year (latent)August", -3.1135153092103742),
("last yearAugust", -3.1135153092103742),
("year (latent)June", -3.1135153092103742),
("yearmonth", -0.916290731874155),
("year (latent)in <month>", -3.1135153092103742),
("year (latent)March", -2.4203681286504293),
("year (latent)in <named-month>", -3.1135153092103742),
("year (latent)August", -3.1135153092103742),
("year (latent)from <time>", -1.6094379124341003)],
n = 17}}),
("imperial <year> <named-month> <day-of-month>",
Classifier{okData =
ClassData{prior = 0.0, unseen = -3.044522437723423,
likelihoods =
HashMap.fromList
[("year (latent)Augustinteger (numeric)", -2.3025850929940455),
("year (latent)Marchinteger (numeric)", -1.6094379124341003),
("yearmonth", -0.916290731874155),
("Imperial year (latent)Augustinteger (numeric)",
-2.3025850929940455),
("year (latent)Juneinteger (numeric)", -2.3025850929940455),
("last yearAugustinteger (numeric)", -2.3025850929940455)],
n = 7},
koData =
ClassData{prior = -infinity, unseen = -1.9459101490553135,
likelihoods = HashMap.fromList [], n = 0}}),
("on <named-day>",
Classifier{okData =
ClassData{prior = 0.0, unseen = -3.044522437723423,
likelihoods =
HashMap.fromList
[("Thursday", -1.8971199848858813),
("Friday", -1.8971199848858813), ("day", -0.7985076962177716),
("Tuesday", -1.3862943611198906)],
n = 8},
koData =
ClassData{prior = -infinity, unseen = -1.6094379124341003,
likelihoods = HashMap.fromList [], n = 0}}),
("from <time>",
Classifier{okData =
ClassData{prior = -1.1430640512389436, unseen = -4.007333185232471,
likelihoods =
HashMap.fromList
[("year (latent)", -2.379546134130174),
("yyyy/mm/dd", -2.1972245773362196),
("day", -2.1972245773362196), ("June", -1.6863989535702288),
("year", -2.379546134130174), ("month", -1.349926716949016),
("<year> <named-month>", -2.379546134130174)],
n = 22},
koData =
ClassData{prior = -0.38395890288720075,
unseen = -4.653960350157523,
likelihoods =
HashMap.fromList
[("year (latent)", -2.8526314299133175),
("yyyy/mm/dd", -3.0349529867072724),
("Monday", -1.6486586255873816), ("day", -1.466337068793427),
("June", -2.2464956263430023), ("year", -2.8526314299133175),
("hh:mm", -3.951243718581427), ("month", -1.6999519199749322),
("minute", -3.951243718581427),
("<year> <named-month>", -2.4471663218051534)],
n = 47}}),
("August",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.1972245773362196,
likelihoods = HashMap.fromList [("", 0.0)], n = 7},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}})]

View File

@ -17,9 +17,11 @@ module Duckling.Rules.JA
import Duckling.Dimensions.Types
import Duckling.Locale
import Duckling.Types
import qualified Duckling.Duration.JA.Rules as Duration
import qualified Duckling.Numeral.JA.Rules as Numeral
import qualified Duckling.Ordinal.JA.Rules as Ordinal
import qualified Duckling.Temperature.JA.Rules as Temperature
import qualified Duckling.Time.JA.Rules as Time
import qualified Duckling.TimeGrain.JA.Rules as TimeGrain
defaultRules :: Seal Dimension -> [Rule]
@ -33,7 +35,7 @@ langRules :: Seal Dimension -> [Rule]
langRules (Seal AmountOfMoney) = []
langRules (Seal CreditCardNumber) = []
langRules (Seal Distance) = []
langRules (Seal Duration) = []
langRules (Seal Duration) = Duration.rules
langRules (Seal Email) = []
langRules (Seal Numeral) = Numeral.rules
langRules (Seal Ordinal) = Ordinal.rules
@ -41,7 +43,7 @@ langRules (Seal PhoneNumber) = []
langRules (Seal Quantity) = []
langRules (Seal RegexMatch) = []
langRules (Seal Temperature) = Temperature.rules
langRules (Seal Time) = []
langRules (Seal Time) = Time.rules
langRules (Seal TimeGrain) = TimeGrain.rules
langRules (Seal Url) = []
langRules (Seal Volume) = []

View File

@ -29,7 +29,9 @@ module Duckling.Time.Helpers
-- Other
, getIntValue, timeComputed, toTimeObjectM
-- Rule constructors
, mkRuleInstants, mkRuleDaysOfWeek, mkRuleMonths, mkRuleMonthsWithLatent
, mkRuleInstants
, mkRuleDaysOfWeek, mkRuleDaysOfWeekLatent
, mkRuleMonths, mkRuleMonthsWithLatent
, mkRuleSeasons, mkRuleHolidays, mkRuleHolidays'
) where
@ -724,6 +726,12 @@ mkRuleDaysOfWeek daysOfWeek = zipWith go daysOfWeek [1..7]
go (name, pattern) i =
mkSingleRegexRule name pattern $ tt $ mkOkForThisNext $ dayOfWeek i
mkRuleDaysOfWeekLatent :: [(Text, String)] -> [Rule]
mkRuleDaysOfWeekLatent daysOfWeek = zipWith go daysOfWeek [1..7]
where
go (name, pattern) i =
mkSingleRegexRule name pattern $ tt $ mkLatent $ mkOkForThisNext $ dayOfWeek i
mkRuleMonths :: [(Text, String)] -> [Rule]
mkRuleMonths = mkRuleMonthsWithLatent . map (uncurry (,, False))

604
Duckling/Time/JA/Corpus.hs Normal file
View File

@ -0,0 +1,604 @@
-- Copyright (c) 2016-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree.
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.JA.Corpus
( corpus
, negativeCorpus
) where
import Data.String
import Prelude
import Duckling.Locale
import Duckling.Resolve
import Duckling.Time.Corpus
import Duckling.Time.Types hiding (Month, refTime)
import Duckling.TimeGrain.Types hiding (add)
import Duckling.Testing.Types hiding (examples)
corpus :: Corpus
corpus = (testContext {locale = makeLocale JA Nothing}, testOptions, allExamples)
negativeCorpus :: NegativeCorpus
negativeCorpus = (testContext {locale = makeLocale JA Nothing}, testOptions, examples)
where
examples =
[ "三三時分"
, ""
, ""
, "かよう"
]
allExamples :: [Example]
allExamples = concat
[ examples (datetime (2013, 2, 12, 15, 20, 0) Minute)
[ "15:20"
, "15時20分"
, "3:20 pm"
, "3:20PM"
, "午後3:20"
, "午後3時20分"
, "午後三時二十分"
, "15時20分に"
, "15時20分で"
, "15時20分の"
]
, examples (datetime (2013, 2, 13, 3, 20, 0) Minute)
[ "3:20 am"
, "3:20AM"
, "午前3:20"
, "午前3時20分"
, "午前三時二十分"
]
, examples (datetime (2013, 2, 12, 15, 0, 0) Hour)
[ "15時ちょうど"
, "15時きっかり"
, "15時ぴったり"
, "午後3時ちょうど"
, "午後3時きっかり"
, "午後3時ぴったり"
]
, examples (datetime (2013, 3, 25, 0, 0, 0) Day)
[ "3月25日"
, "3/25"
, "03/25に"
, "2013年3月25日に"
]
, examples (datetime (2021, 8, 6, 0, 0, 0) Day)
[ "2021年8月6日に"
, "令和3年8月6日に"
]
, examples (datetime (2021, 3, 25, 0, 0, 0) Day)
[ "2021年三月25日に"
, "2021年3月25日に"
, "2021/03/25に"
, "2021/03/25で"
, "2021/3/25に"
, "2021.03.25に"
, "2021325に"
]
-- on Tuesday
, examples (datetime (2013, 2, 19, 0, 0, 0) Day)
[ "火曜日に"
, "火曜に"
, "(火)に"
, "(火)に"
, "かようびに"
, "かように"
, "火曜日は"
, "火曜日で"
]
-- on the 25th
, examples (datetime (2013, 2, 25, 0, 0, 0) Day)
[ "25日に"
, "25日は"
, "25日で"
]
-- in June
, examples (datetime (2013, 6, 1, 0, 0, 0) Month)
[ "6月に"
, "6がつに"
, "6月中に"
, "6月の間に"
, "6月は"
, "6月で"
, "六月に"
, "ろくがつに"
]
-- in 2020
, examples (datetime (2020, 1, 1, 0, 0, 0) Year)
[ "2020年に"
, "2020年は"
, "2020年で"
, "令和2年に"
, "令和2年は"
, "令和2年で"
]
-- in 2018
, examples (datetime (2018, 1, 1, 0, 0, 0) Year)
[ "平成30年に"
]
-- in 1912 = gannen Taisho
, examples (datetime (1912, 1, 1, 0, 0, 0) Year)
[ "大正元年に"
]
-- in March 2020
, examples (datetime (2021, 3, 1, 0, 0, 0) Month)
[ "2021年3月に"
, "2021年三月に"
, "2021/03に"
, "2021/3に"
, "2021.03に"
, "2021.3に"
]
-- in 2 months
, examples (datetime (2013, 4, 12, 0, 0, 0) Day)
[ "2ヶ月で"
]
-- after 25/03/2021
, examples (datetimeOpenInterval After (2021, 3, 25, 0, 0, 0) Day)
[ "2021/03/25以降"
, "2021/3/25以降に"
, "2021.03.25"
, "2021/03/25より後"
, "2021.3.25から"
]
-- before 25/03/2021
, examples (datetimeOpenInterval Before (2021, 3, 25, 0, 0, 0) Day)
[ "2021/03/25まで"
, "2021/03/25より前"
, "2021/03/25以前"
]
-- until June 2020
, examples (datetimeOpenInterval Before (2020, 6, 1, 0, 0, 0) Day)
[ "2020年6月1日までに"
]
-- until June 2020
, examples (datetimeOpenInterval Before (2020, 6, 1, 0, 0, 0) Month)
[ "2020年6月よりも前"
, "2020年6月以前"
]
-- until June
, examples (datetimeOpenInterval Before (2013, 6, 1, 0, 0, 0) Month)
[ "6月よりも前"
, "6月より前"
, "6月以前"
]
-- until June 1
, examples (datetimeOpenInterval Before (2013, 6, 1, 0, 0, 0) Day)
[ "6月1日までに"
]
-- until 2020
, examples (datetimeOpenInterval Before (2020, 1, 1, 0, 0, 0) Year)
[ "2020年よりも前"
, "2020年より前"
, "2020年以前"
]
, examples (datetimeInterval ((2021, 3, 25, 0, 0, 0), (2021, 3, 31, 0, 0, 0)) Day)
[ "2021/03/25から2021/03/30まで"
, "2021/03/25以降2021/03/30以前"
, "2021/03/25以降2021/03/30まで"
, "2021/03/25より2021/03/30まで"
, "2021/03/25~2021/03/30"
, "2021/03/2503/30"
]
-- from 2020
, examples (datetimeOpenInterval After (2020, 1, 1, 0, 0, 0) Year)
[ "2020年以降"
, "2020年以来"
, "2020年より後"
, "2020年よりも後"
]
-- from June 2020
, examples (datetimeOpenInterval After (2020, 6, 1, 0, 0, 0) Month)
[ "2020年6月以降"
, "2020年6月初め以降"
, "2020年6月から"
, "2020年6月"
]
-- from June to July 2020
, examples (datetimeInterval ((2020, 6, 1, 0, 0, 0), (2020, 8, 1, 0, 0, 0)) Month)
[ "2020年6月から7月まで"
, "2020年6月~7月"
, "2020年6月以降7月いっぱい"
, "2020年6月頭から7月末まで"
, "2020年6月初めから7月いっぱい"
, "2020年6月以降7月にかけて"
]
-- from June 2020 to July 2021
, examples (datetimeInterval ((2020, 6, 1, 0, 0, 0), (2021, 8, 1, 0, 0, 0)) Month)
[ "2020年6月から2021年7月まで"
, "2020年6月2021年7月"
, "2020年6月から2021年7月にかけて"
, "2020年6月以降2021年7月いっぱい"
, "2020年6月頭から2021年7月末まで"
, "2020年6月初めから2021年7月いっぱい"
, "2020年6月以降2021年7月にかけて"
]
-- from June
, examples (datetimeOpenInterval After (2013, 6, 1, 0, 0, 0) Month)
[ "6月以降"
, "6月以来"
, "6月より後"
, "6月よりも後"
, "6月から"
]
-- from June to July
, examples (datetimeInterval ((2013, 6, 1, 0, 0, 0), (2013, 8, 1, 0, 0, 0)) Month)
[ "6月から7月まで"
, "6月~7月"
, "6月から7月にかけて"
, "6月初めから7月末まで"
, "6月頭から7月いっぱい"
]
-- from 2020 to 2021
, examples (datetimeInterval ((2020, 1, 1, 0, 0, 0), (2022, 1, 1, 0, 0, 0)) Year)
[ "2020年から2021年まで"
, "2020年から2021年にかけて"
, "2020年から2021年"
, "2020年2021年"
, "2020年・2021年"
, "2020年、2021年"
, "2020から2021年"
, "20202021年"
, "2020・2021年"
, "2020、2021年"
, "2020年から2021年の間"
]
-- ruleDaysOfWeek
, examples (datetime (2013, 2, 18, 0, 0, 0) Day)
[ "月に"
, "月曜"
, "月曜日"
, "げつようび"
]
, examples (datetime (2013, 2, 19, 0, 0, 0) Day)
[ "火は"
, "火曜"
, "火曜日"
, "かようび"
]
, examples (datetime (2013, 2, 13, 0, 0, 0) Day)
[ "水で"
, "水曜"
, "水曜日"
, "すいようび"
]
, examples (datetime (2013, 2, 14, 0, 0, 0) Day)
[ "(木)に"
, "木曜"
, "木曜日"
, "もくようび"
]
, examples (datetime (2013, 2, 15, 0, 0, 0) Day)
[ "(金)に"
, "金曜"
, "金曜日"
, "きんようび"
]
, examples (datetime (2013, 2, 16, 0, 0, 0) Day)
[ "土に"
, "土曜"
, "土曜日"
, "どようび"
]
, examples (datetime (2013, 2, 17, 0, 0, 0) Day)
[ "日に"
, "日曜"
, "日曜日"
, "にちようび"
]
-- ruleMonths
, examples (datetime (2014, 1, 1, 0, 0, 0) Month)
[ "1月"
, "一月"
, "1月"
, "いちがつ"
]
, examples (datetime (2013, 2, 1, 0, 0, 0) Month)
[ "2月"
, "二月"
, "2月"
, "にがつ"
]
, examples (datetime (2013, 3, 1, 0, 0, 0) Month)
[ "3月"
, "3月"
, "三月"
, "さんがつ"
, "3月に"
, "三月は"
, "三月の間に"
, "三月中に"
]
, examples (datetime (2013, 4, 1, 0, 0, 0) Month)
[ "4月"
, "四月"
, "4月"
, "しがつ"
]
, examples (datetime (2013, 5, 1, 0, 0, 0) Month)
[ "5月"
, "五月"
, "5月"
, "ごがつ"
]
, examples (datetime (2013, 6, 1, 0, 0, 0) Month)
[ "6月"
, "六月"
, "6月"
, "ろくがつ"
]
, examples (datetime (2013, 7, 1, 0, 0, 0) Month)
[ "7月"
, "七月"
, "7月"
, "しちがつ"
]
, examples (datetime (2013, 8, 1, 0, 0, 0) Month)
[ "8月"
, "八月"
, "8月"
, "はちがつ"
]
, examples (datetime (2013, 9, 1, 0, 0, 0) Month)
[ "9月"
, "九月"
, "9月"
, "くがつ"
]
, examples (datetime (2013, 10, 1, 0, 0, 0) Month)
[ "10月"
, "十月"
, "10月"
, "じゅうがつ"
]
, examples (datetime (2013, 11, 1, 0, 0, 0) Month)
[ "11月"
, "十一月"
, "11月"
, "じゅういちがつ"
]
, examples (datetime (2013, 12, 1, 0, 0, 0) Month)
[ "12月"
, "十二月"
, "12月"
, "じゅうにがつ"
]
-- weekend
, examples (datetimeInterval ((2013, 2, 15, 18, 0, 0), (2013, 2, 18, 0, 0, 0)) Hour)
[ "週末"
, "しゅうまつ"
]
-- now
, examples (datetime (2013, 2, 12, 4, 30, 0) Second)
[ ""
, "いま"
, "今すぐ"
, "ただいま"
, "ただちに"
]
-- today
, examples (datetime (2013, 2, 12, 0, 0, 0) Day)
[ "今日"
, "きょう"
, "本日"
, "ほんじつ"
]
-- tomorrow
, examples (datetime (2013, 2, 13, 0, 0, 0) Day)
[ "明日"
, "あした"
, "あす"
, "みょうにち"
]
-- yesterday
, examples (datetime (2013, 2, 11, 0, 0, 0) Day)
[ "昨日"
, "きのう"
, "さくじつ"
, "前日"
]
-- this hour
, examples (datetime (2013, 2, 12, 4, 0, 0) Hour)
[ "この1時間"
, "当1時間"
, "現1時間"
, "今1時間"
]
-- last one hour
, examples (datetimeInterval ((2013, 2, 12, 3, 0, 0), (2013, 2, 12, 4, 0, 0)) Hour)
[ "過去1時間"
]
-- current day
, examples (datetime (2013, 2, 12, 0, 0, 0) Day)
[ "今日"
, "本日"
, "きょう"
, "ほんじつ"
, "今日1日"
, "この1日"
]
-- current/this week
, examples (datetime (2013, 2, 11, 0, 0, 0) Week)
[ "今週"
, "当週"
, "この週"
, "現在の週"
, "こんしゅう"
, "この1週間"
]
-- current/this month
, examples (datetime (2013, 2, 1, 0, 0, 0) Month)
[ "今月"
, "当月"
, "こんげつ"
, "このひと月"
]
-- "this one month"
, examples (datetimeInterval ((2013, 1, 12, 0, 0, 0), (2013, 2, 12, 4, 30, 1)) Second)
[ "この1ヶ月"
]
-- "this two months"
, examples (datetimeInterval ((2012, 12, 12, 0, 0, 0), (2013, 2, 12, 4, 30, 1)) Second)
[ "この2ヶ月"
]
-- current/this quarter
, examples (datetime (2013, 1, 1, 0, 0, 0) Quarter)
[ "今四半期"
, "今QTR"
, "当四半期"
, "当QTR"
, "現四半期"
, "本四半期"
, "現行四半期"
, "現在の四半期"
, "今の四半期"
]
-- current/this year
, examples (datetime (2013, 1, 1, 0, 0, 0) Year)
[ "今年"
, "本年"
, "当年"
]
-- "this two years"
, examples (datetimeInterval ((2011, 2, 1, 0, 0, 0), (2013, 2, 12, 4, 30, 1)) Second)
[ "この2年"
, "この二年"
]
-- last second
, examples (datetime (2013, 2, 12, 4, 29, 59) Second)
[ "直近1秒間"
, "直近の1秒間"
, "直近の1秒"
, "直近1秒"
, "前の1秒"
, "前の1秒間"
, "前秒"
, "昨秒"
, "最後の1秒"
, "最後の1秒間"
]
-- last minute
, examples (datetime (2013, 2, 12, 4, 29, 0) Minute)
[ "直近1分間"
, "直近の1分間"
, "直近の1分"
, "直近1分"
, "前の1分"
, "前の1分間"
, "前分"
, "昨分"
, "最後の1分"
, "最後の1分間"
]
-- last hour
, examples (datetime (2013, 2, 12, 3, 0, 0) Hour)
[ "直近1時間"
, "直近の1時間"
, "直近1時間"
, "前1時間"
, "前の1時間"
, "最後の1時間"
]
-- last week
, examples (datetime (2013, 2, 4, 0, 0, 0) Week)
[ "先週"
, "せんしゅう"
, "先の週"
, "前週"
, "前の週"
, "昨週"
]
-- last month
, examples (datetime (2013, 1, 1, 0, 0, 0) Month)
[ "先月"
, "前月"
, "前の月"
, "昨月"
]
-- last quarter
, examples (datetime (2012, 10, 1, 0, 0, 0) Quarter)
[ "前四半期"
, "前の四半期"
, "先四半期"
, "先QTR"
, "先の四半期"
, "昨四半期"
]
-- last year
, examples (datetime (2012, 1, 1, 0, 0, 0) Year)
[ "去年"
, "昨年"
, "前年"
, "前の年"
, "先年"
, "先の年"
]
-- last 7 days
, examples (datetimeInterval ((2013, 2, 5, 0, 0, 0), (2013, 2, 12, 0, 0, 0)) Day)
[ "過去7日間"
, "直在7日間"
]
-- in the last 7 days
, examples (datetimeInterval ((2013, 2, 5, 4, 0, 0), (2013, 2, 12, 4, 30, 1)) Second)
[ "この7日間"
]
-- August 19th last year
, examples (datetime (2012, 8, 19, 0, 0, 0) Day)
[ "去年8月19日"
]
-- in two minutes
, examples (datetime (2013, 2, 12, 4, 32, 0) Second)
[ "2分後"
, "2分で"
, "2分間で"
, "2分経ったら"
, "2分経ってから"
, "2分経過後に"
, "2分経過してから"
, "2分経過したら"
, "2分過ぎに"
, "2分過ぎたら"
]
-- in two months
, examples (datetime (2013, 4, 12, 0, 0, 0) Day)
[ "2ヶ月後"
, "2ヶ月で"
, "2ヶ月間で"
, "2ヶ月経ったら"
, "2ヶ月経ってから"
, "2ヶ月経過後に"
, "2ヶ月経過してから"
, "2ヶ月経過したら"
, "2ヶ月過ぎに"
, "2ヶ月過ぎたら"
]
-- next week
, examples (datetime (2013, 2, 18, 0, 0, 0) Week)
[ "来週"
, "らいしゅう"
]
-- a week after next
, examples (datetime (2013, 2, 25, 0, 0, 0) Week)
[ "再来週"
, "さらいしゅう"
]
-- in one week
, examples (datetime (2013, 2, 19, 0, 0, 0) Day)
[ "一週間後"
, "1週間後"
]
]

639
Duckling/Time/JA/Rules.hs Normal file
View File

@ -0,0 +1,639 @@
-- Copyright (c) 2016-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree.
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NoRebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.JA.Rules
( rules
) where
import Control.Monad (guard)
import Prelude
import qualified Data.Text as Text
import Duckling.Dimensions.Types
import Duckling.Duration.Types (DurationData (..))
import Duckling.Numeral.Helpers (isNatural, parseInt)
import Duckling.Regex.Types
import Duckling.Time.Helpers
import Duckling.Types
import qualified Duckling.Duration.Types as TDuration
import qualified Duckling.Time.Types as TTime
import qualified Duckling.TimeGrain.Types as TG
ruleHHMM :: Rule
ruleHHMM = Rule
{ name = "hh:mm"
, pattern = [regex "((?:[01]?\\d)|(?:2[0-3]))[:. ]([0-5]\\d)"]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (hh:mm:_)):_) -> do
h <- parseInt hh
m <- parseInt mm
tt $ hourMinute (h /= 0 && h < 12) h m
_ -> Nothing
}
ruleHHMMKanji :: Rule
ruleHHMMKanji = Rule
{ name = "hh時mm分"
, pattern = [regex "((?:[01]?\\d)|(?:2[0-3]))時([0-5]\\d)分"]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (hh:mm:_)):_) -> do
h <- parseInt hh
m <- parseInt mm
tt $ hourMinute (h /= 0 && h < 12) h m
_ -> Nothing
}
ruleHHMMKanjiNumeral :: Rule
ruleHHMMKanjiNumeral = Rule
{ name = "hh時mm分"
, pattern =
[ Predicate isNatural
, regex ""
, Predicate isNatural
, regex ""
]
, prod = \tokens -> case tokens of
(hh:_:mm:_) -> do
h <- getIntValue hh
m <- getIntValue mm
guard (h > 0 && h < 25 && m < 60)
tt $ hourMinute (h /= 0 && h < 12) h m
_ -> Nothing
}
ruleTODLatent :: Rule
ruleTODLatent = Rule
{ name = "time-of-day (latent)"
, pattern =
[ Predicate $ isIntegerBetween 0 23
]
, prod = \tokens -> case tokens of
(token:_) -> do
n <- getIntValue token
tt $ mkLatent $ hour (n < 13) n
_ -> Nothing
}
ruleHHOClock :: Rule
ruleHHOClock = Rule
{ name = "<time-of-day> o'clock"
, pattern =
[ Predicate isATimeOfDay
, regex "時(ちょうど|きっかり|ぴったり)"
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> tt $ notLatent td
_ -> Nothing
}
ruleTODAMPM :: Rule
ruleTODAMPM = Rule
{ name = "<time-of-day> am|pm"
, pattern =
[ Predicate isATimeOfDay
, regex "([ap])(\\s|\\.)?m?\\.?"
]
, prod = \tokens -> case tokens of
(Token Time td:Token RegexMatch (GroupMatch (ap:_)):_) ->
tt $ timeOfDayAMPM (Text.toLower ap == "a") td
_ -> Nothing
}
ruleTODAMPMKanji :: Rule
ruleTODAMPMKanji = Rule
{ name = "午後|午前 <time-of-day>"
, pattern =
[ regex "午(前|後)"
, Predicate isATimeOfDay
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (ap:_)):Token Time td:_) ->
tt $ timeOfDayAMPM (ap == "") td
_ -> Nothing
}
ruleAtTOD :: Rule
ruleAtTOD = Rule
{ name = "at <time-of-day>"
, pattern =
[ Predicate isATimeOfDay
, regex "に|で|の"
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> tt $ notLatent td
_ -> Nothing
}
ruleMMDD :: Rule
ruleMMDD = Rule
{ name = "mm/dd"
, pattern =
[ regex "(1[0-2]|0?[1-9])\\s?[/]\\s?(3[01]|[12]\\d|0?[1-9])"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (mm:dd:_)):_) -> do
m <- parseInt mm
d <- parseInt dd
tt $ monthDay m d
_ -> Nothing
}
ruleYYYYMM :: Rule
ruleYYYYMM = Rule
{ name = "yyyy/mm"
, pattern =
[ regex "(\\d{4})\\s*[/.]\\s*(1[0-2]|0?[1-9])"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (yy:mm:_)):_) -> do
y <- parseInt yy
m <- parseInt mm
tt $ yearMonth y m
_ -> Nothing
}
ruleYYYYMMDD :: Rule
ruleYYYYMMDD = Rule
{ name = "yyyy/mm/dd"
, pattern =
[ regex "(\\d{2,4})\\s*[/.]\\s*(0?[1-9]|1[0-2])\\s*[/.]\\s*(3[01]|[12]\\d|0?[1-9])"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (yy:mm:dd:_)):_) -> do
y <- parseInt yy
m <- parseInt mm
d <- parseInt dd
tt $ yearMonthDay y m d
_ -> Nothing
}
ruleMonthDOM :: Rule
ruleMonthDOM = Rule
{ name = "<named-month> <day-of-month>"
, pattern =
[ Predicate isAMonth
, Predicate isDOMValue
, regex ""
]
, prod = \tokens -> case tokens of
(Token Time td:token:_) -> Token Time <$> intersectDOM td token
_ -> Nothing
}
ruleYearMonthDOM :: Rule
ruleYearMonthDOM = Rule
{ name = "<year> <named-month> <day-of-month>"
, pattern =
[ regex "(\\d{2,4})年"
, Predicate isAMonth
, Predicate isDOMValue
, regex ""
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):Token Time td:token:_) -> do
intVal <- parseInt match
dom <- intersectDOM td token
Token Time <$> intersect dom (year intVal)
_ -> Nothing
}
ruleImperialYearMonthDOM :: Rule
ruleImperialYearMonthDOM = Rule
{ name = "imperial <year> <named-month> <day-of-month>"
, pattern =
[ Predicate $ isGrainOfTime TG.Year
, Predicate isAMonth
, Predicate isDOMValue
, regex ""
]
, prod = \tokens -> case tokens of
(Token Time year:Token Time td:token:_) -> do
dom <- intersectDOM td token
Token Time <$> intersect dom year
_ -> Nothing
}
ruleYearMonth :: Rule
ruleYearMonth = Rule
{ name = "<year> <named-month>"
, pattern =
[ Predicate $ isGrainOfTime TG.Year
, Predicate isAMonth
]
, prod = \tokens -> case tokens of
(Token Time year:Token Time month:_) ->
Token Time . notLatent <$> intersect year month
_ -> Nothing
}
ruleOnADOW :: Rule
ruleOnADOW = Rule
{ name = "on <named-day>"
, pattern =
[ regex "(\\(|)?"
, Predicate isADayOfWeek
, regex "(\\)|)?(に|は|で)"
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> tt $ notLatent td
_ -> Nothing
}
ruleAbsorbOnDay :: Rule
ruleAbsorbOnDay = Rule
{ name = "on <day>"
, pattern =
[ Predicate $ isGrainOfTime TG.Day
, regex "に|は|で"
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> tt $ notLatent td
_ -> Nothing
}
ruleOnDay :: Rule
ruleOnDay = Rule
{ name = "on the <day-of-month>"
, pattern =
[ Predicate isDOMValue
, regex "日(に|は|で)"
]
, prod = \tokens -> case tokens of
(token:_) -> do
n <- getIntValue token
tt $ dayOfMonth n
_ -> Nothing
}
ruleInNamedMonth :: Rule
ruleInNamedMonth = Rule
{ name = "in <named-month>"
, pattern =
[ Predicate isAMonth
, regex "(の間|中)?(に|は|で)"
]
, prod = \tokens -> case tokens of
(td2:_) -> Just td2
_ -> Nothing
}
ruleYearLatent :: Rule
ruleYearLatent = Rule
{ name = "year (latent)"
, pattern =
[ Predicate $ or . sequence [isIntegerBetween (- 10000) 0, isIntegerBetween 25 10000]
, regex ""
]
, prod = \tokens -> case tokens of
(token:_) -> do
n <- getIntValue token
tt $ mkLatent $ year n
_ -> Nothing
}
ruleImperialYearLatent :: Rule
ruleImperialYearLatent = Rule
{ name = "Imperial year (latent)"
, pattern =
[ regex "(明治|大正|昭和|平成|令和)"
, Predicate $ isIntegerBetween 0 65
, regex ""
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):token:_) -> do
n <- getIntValue token
ry <- case Text.toLower match of
"明治" -> Just 1868
"大正" -> Just 1912
"昭和" -> Just 1926
"平成" -> Just 1989
"令和" -> Just 2019
_ -> Nothing
tt $ mkLatent $ year (ry+n-1)
_ -> Nothing
}
ruleFirstImperialYearLatent :: Rule
ruleFirstImperialYearLatent = Rule
{ name = "First Imperial year (latent)"
, pattern =
[ regex "(明治|大正|昭和|平成|令和)元年"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
ry <- case Text.toLower match of
"明治" -> Just 1868
"大正" -> Just 1912
"昭和" -> Just 1926
"平成" -> Just 1989
"令和" -> Just 2019
_ -> Nothing
tt $ mkLatent $ year ry
_ -> Nothing
}
ruleInYear :: Rule
ruleInYear = Rule
{ name = "in <year>"
, pattern =
[ Predicate $ isGrainOfTime TG.Year
, regex "に|は|で"
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> tt $ notLatent td
_ -> Nothing
}
ruleInMonth :: Rule
ruleInMonth = Rule
{ name = "in <month>"
, pattern =
[ Predicate $ isGrainOfTime TG.Month
, regex ""
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> tt $ notLatent td
_ -> Nothing
}
ruleInDuration :: Rule
ruleInDuration = Rule
{ name = "in <duration>"
, pattern =
[ dimension Duration
, regex "後|(間)?で|経ったら|経ってから|経過後に|経過してから|経過したら|過ぎに|過ぎたら"
]
, prod = \tokens -> case tokens of
(Token Duration dd:_) ->
tt $ inDuration dd
_ -> Nothing
}
ruleInTheLastDuration :: Rule
ruleInTheLastDuration = Rule
{ name = "in/for the last <duration>"
, pattern =
[ regex "この"
, Predicate $ isDurationGreaterThan TG.Hour
]
, prod = \tokens -> case tokens of
(_:Token Duration dd:_) ->
Token Time <$> interval TTime.Closed (durationBefore dd now) now
_ -> Nothing
}
ruleIntervalFromTime :: Rule
ruleIntervalFromTime = Rule
{ name = "from <time>"
, pattern =
[ dimension Time
, regex "(初め)?以(降|来)に?||よりも?後|から"
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> tt $ withDirection TTime.After $ notLatent td
_ -> Nothing
}
ruleIntervalUntilTime :: Rule
ruleIntervalUntilTime = Rule
{ name = "until <time>"
, pattern =
[ dimension Time
, regex "までに?|よりも?前|以前"
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> tt $ withDirection TTime.Before $ notLatent td
_ -> Nothing
}
ruleIntervalFromToTime :: Rule
ruleIntervalFromToTime = Rule
{ name = "from <time> to <time>"
, pattern =
[ dimension Time
, regex "(初め)?以(降|来)に?||よりも?後?|(初め|頭)?から|以降"
, dimension Time
, regex "末?まで|(より|以)前|の間|にかけて|いっぱい"
]
, prod = \tokens -> case tokens of
(Token Time td1:_:Token Time td2:_) ->
Token Time <$> interval TTime.Closed td1 td2
_ -> Nothing
}
ruleIntervalTimes :: Rule
ruleIntervalTimes = Rule
{ name = "<time> - <time>"
, pattern =
[ dimension Time
, regex "-|~||・|、|から"
, dimension Time
]
, prod = \tokens -> case tokens of
(Token Time td1:_:Token Time td2:_) ->
Token Time <$> interval TTime.Closed td1 td2
_ -> Nothing
}
ruleIntervalYear :: Rule
ruleIntervalYear = Rule
{ name = "<year> - <year>"
, pattern =
[ Predicate $ isIntegerBetween 1000 10000
, regex "-|~||・|、|から"
, Predicate $ isIntegerBetween 1000 10000
, regex ""
]
, prod = \tokens -> case tokens of
(t1:_:t2:_) -> do
y1 <- getIntValue t1
y2 <- getIntValue t2
guard (y1 < y2)
Token Time <$> interval TTime.Closed (year y1) (year y2)
_ -> Nothing
}
ruleWeekend :: Rule
ruleWeekend = Rule
{ name = "week-end"
, pattern =
[ regex "週末|しゅうまつ"
]
, prod = \_ -> tt $ mkOkForThisNext weekend
}
ruleNow :: Rule
ruleNow = Rule
{ name = "now"
, pattern =
[ regex "今すぐ|いま|即|ただ(いま|ちに)"
]
, prod = \_ -> tt now
}
ruleThisTimeGrain :: Rule
ruleThisTimeGrain = Rule
{ name = "this|current <time-grain>"
, pattern =
[ regex "現在の|(今|こ(ん|の)|当|現)(1|一)?"
, dimension TimeGrain
]
, prod = \tokens -> case tokens of
( _:
Token TimeGrain grain:
_) -> tt $ cycleNth grain 0
_ -> Nothing
}
ruleNextTimeGrain :: Rule
ruleNextTimeGrain = Rule
{ name = "next <time-grain>"
, pattern =
[ regex ""
, dimension TimeGrain
]
, prod = \tokens -> case tokens of
( _:
Token TimeGrain grain:
_) -> tt $ cycleNth grain 1
_ -> Nothing
}
ruleLastTimeGrain :: Rule
ruleLastTimeGrain = Rule
{ name = "last <time-grain>"
, pattern =
[ regex "(前|直近|最後|昨|先)の?(1|一)?"
, dimension TimeGrain
]
, prod = \tokens -> case tokens of
( _:
Token TimeGrain grain:
_) -> tt $ cycleNth grain $ - 1
_ -> Nothing
}
ruleDurationLastNext :: Rule
ruleDurationLastNext = Rule
{ name = "last|past|next <duration>"
, pattern =
[ regex "(過去|直在|次の)"
, dimension Duration
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):
Token Duration DurationData{TDuration.grain, TDuration.value}:
_) -> case Text.toLower match of
"次の" -> tt $ cycleN True grain value
"過去" -> tt $ cycleN True grain (- value)
"直在" -> tt $ cycleN True grain (- value)
_ -> Nothing
_ -> Nothing
}
ruleInstants :: [Rule]
ruleInstants = mkRuleInstants
[ ("today" , TG.Day , 0 , "今日(1日)?|きょう|本日|ほんじつ" )
, ("tomorrow" , TG.Day , 1 , "明日|あした|あす|みょうにち" )
, ("yesterday" , TG.Day , -1 , "(前|昨)日|きのう|さくじつ" )
, ("next week" , TG.Week , 1 , "らいしゅう" )
, ("last week" , TG.Week , -1 , "せんしゅう" )
, ("a week after next", TG.Week , 2 , "再来週|さらいしゅう" )
, ("this month" , TG.Month , 0 , "このひと月" )
, ("this quarter" , TG.Quarter, 0 , "本四半期|今の四半期|現行四半期" )
, ("this year" , TG.Year , 0 , "本年" )
, ("last year" , TG.Year , -1 , "去年" )
]
ruleDaysOfWeek :: [Rule]
ruleDaysOfWeek = mkRuleDaysOfWeek
[ ( "Monday" , "月曜日?|げつようび" )
, ( "Tuesday" , "火曜日?|かようび" )
, ( "Wednesday", "水曜日?|すいようび" )
, ( "Thursday" , "木曜日?|もくようび" )
, ( "Friday" , "金曜日?|きんようび" )
, ( "Saturday" , "土曜日?|どようび" )
, ( "Sunday" , "日曜日?|にちようび" )
]
ruleDaysOfWeekLatent :: [Rule]
ruleDaysOfWeekLatent = mkRuleDaysOfWeekLatent
[ ( "Monday" , "月|げつよう" )
, ( "Tuesday" , "火|かよう" )
, ( "Wednesday", "水|すいよう" )
, ( "Thursday" , "木|もくよう" )
, ( "Friday" , "金|きんよう" )
, ( "Saturday" , "土|どよう" )
, ( "Sunday" , "日|にちよう" )
]
ruleMonths :: [Rule]
ruleMonths = mkRuleMonths
[ ( "January" , "(1|一|)(月|がつ)|いちがつ" )
, ( "February" , "(2|二|)(月|がつ)|にがつ" )
, ( "March" , "(3|三|)(月|がつ)|さんがつ" )
, ( "April" , "(4|四|)(月|がつ)|しがつ" )
, ( "May" , "(5|五|)(月|がつ)|ごがつ" )
, ( "June" , "(6|六|)(月|がつ)|ろくがつ" )
, ( "July" , "(7|七|)(月|がつ)|しちがつ" )
, ( "August" , "(8|八|)(月|がつ)|はちがつ" )
, ( "September", "(9|九|)(月|がつ)|くがつ" )
, ( "October" , "(10|十|)(月|がつ)|じゅうがつ" )
, ( "November" , "(11|十一|)(月|がつ)|じゅういちがつ" )
, ( "December" , "(12|十二|)(月|がつ)|じゅうにがつ" )
]
rules :: [Rule]
rules =
[ ruleHHMM
, ruleHHMMKanji
, ruleHHMMKanjiNumeral
, ruleTODLatent
, ruleHHOClock
, ruleTODAMPM
, ruleTODAMPMKanji
, ruleAtTOD
, ruleMMDD
, ruleYYYYMM
, ruleYYYYMMDD
, ruleYearLatent
, ruleImperialYearLatent
, ruleFirstImperialYearLatent
, ruleMonthDOM
, ruleYearMonth
, ruleYearMonthDOM
, ruleImperialYearMonthDOM
, ruleOnADOW
, ruleAbsorbOnDay
, ruleOnDay
, ruleInNamedMonth
, ruleInYear
, ruleInMonth
, ruleInDuration
, ruleInTheLastDuration
, ruleIntervalFromTime
, ruleIntervalUntilTime
, ruleIntervalFromToTime
, ruleIntervalTimes
, ruleIntervalYear
, ruleWeekend
, ruleNow
, ruleThisTimeGrain
, ruleNextTimeGrain
, ruleLastTimeGrain
, ruleDurationLastNext
]
++ ruleDaysOfWeek
++ ruleDaysOfWeekLatent
++ ruleMonths
++ ruleInstants

View File

@ -20,13 +20,14 @@ import qualified Duckling.TimeGrain.Types as TG
import Duckling.Types
grains :: [(Text, String, TG.Grain)]
grains = [ ("second (grain)", "秒(毎|間)?", TG.Second)
, ("minute (grain)", "分(毎|間)?", TG.Minute)
, ("hour (grain)", "時(毎|間)?", TG.Hour)
, ("day (grain)", "日(毎|間)?", TG.Day)
, ("week (grain)", "週(毎|間)?", TG.Week)
, ("month (grain)", "月(毎|間)?", TG.Month)
, ("year (grain)", "年(毎|間)?", TG.Year)
grains = [ ("second (grain)", "秒(毎|間)?|びょう", TG.Second)
, ("minute (grain)", "分(毎|間)?|ふん", TG.Minute)
, ("hour (grain)", "時(毎|間)?|じ", TG.Hour)
, ("day (grain)", "曜?日(毎|間)?|ようび|にち|ひ", TG.Day)
, ("week (grain)", "週(毎|間)?|しゅう", TG.Week)
, ("month (grain)", "月(毎|間)?|げつ|つき", TG.Month)
, ("quarter (grain)", "(四|4)半期|しはんき|QTR", TG.Quarter)
, ("year (grain)", "年(毎|間)?|ねん|とし", TG.Year)
]
rules :: [Rule]

View File

@ -368,6 +368,7 @@ library
, Duckling.Duration.HU.Rules
, Duckling.Duration.IT.Rules
, Duckling.Duration.JA.Corpus
, Duckling.Duration.JA.Rules
, Duckling.Duration.KA.Corpus
, Duckling.Duration.KA.Rules
, Duckling.Duration.KO.Corpus
@ -741,6 +742,8 @@ library
, Duckling.Time.HU.Rules
, Duckling.Time.IT.Corpus
, Duckling.Time.IT.Rules
, Duckling.Time.JA.Corpus
, Duckling.Time.JA.Rules
, Duckling.Time.KA.Corpus
, Duckling.Time.KA.Rules
, Duckling.Time.KO.Corpus
@ -1148,6 +1151,7 @@ test-suite duckling-test
, Duckling.Time.HE.Tests
, Duckling.Time.HU.Tests
, Duckling.Time.IT.Tests
, Duckling.Time.JA.Tests
, Duckling.Time.KA.Tests
, Duckling.Time.KO.Tests
, Duckling.Time.NB.Tests

View File

@ -45,6 +45,7 @@ import qualified Duckling.Time.HR.Corpus as HRTime
import qualified Duckling.Time.HE.Corpus as HETime
import qualified Duckling.Time.HU.Corpus as HUTime
import qualified Duckling.Time.IT.Corpus as ITTime
import qualified Duckling.Time.JA.Corpus as JATime
import qualified Duckling.Time.KO.Corpus as KOTime
import qualified Duckling.Time.NB.Corpus as NBTime
import qualified Duckling.Time.NL.Corpus as NLTime
@ -198,7 +199,7 @@ getCorpusForLang = \case
ID -> (testContext, testOptions, [])
IS -> (testContext, testOptions, [])
IT -> ITTime.corpus
JA -> (testContext, testOptions, [])
JA -> JATime.corpus
KA -> (testContext, testOptions, [])
KM -> (testContext, testOptions, [])
KN -> (testContext, testOptions, [])

View File

@ -20,4 +20,5 @@ import Duckling.Testing.Asserts
tests :: TestTree
tests = testGroup "JA Tests"
[ makeCorpusTest [Seal Duration] corpus
, makeNegativeCorpusTest [Seal Duration] negativeCorpus
]

View File

@ -0,0 +1,23 @@
-- Copyright (c) 2016-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree.
module Duckling.Time.JA.Tests
( tests ) where
import Data.String
import Prelude
import Test.Tasty
import Duckling.Dimensions.Types
import Duckling.Testing.Asserts
import Duckling.Time.JA.Corpus
tests :: TestTree
tests = testGroup "JA Tests"
[ makeCorpusTest [Seal Time] corpus
, makeNegativeCorpusTest [Seal Duration] negativeCorpus
]

View File

@ -37,6 +37,7 @@ import qualified Duckling.Time.HR.Tests as HR
import qualified Duckling.Time.HE.Tests as HE
import qualified Duckling.Time.HU.Tests as HU
import qualified Duckling.Time.IT.Tests as IT
import qualified Duckling.Time.JA.Tests as JA
import qualified Duckling.Time.KA.Tests as KA
import qualified Duckling.Time.KO.Tests as KO
import qualified Duckling.Time.NB.Tests as NB
@ -66,6 +67,7 @@ tests = testGroup "Time Tests"
, HE.tests
, HU.tests
, IT.tests
, JA.tests
, KA.tests
, KO.tests
, NB.tests