mirror of
https://github.com/facebook/duckling.git
synced 2024-09-11 21:27:13 +03:00
Added new rule support composite duration phrase in ES (#498)
Summary: Pull Request resolved: https://github.com/facebook/duckling/pull/498 Test Plan: In haxlsh: H.io $ debug (makeLocale ES Nothing) "dos hora y treinta y cinco minutos" [This Duration] Reviewed By: chinmay87 Differential Revision: D22054695 Pulled By: yuanbing fbshipit-source-id: b4486141bf7ccb0e538e40ce40fadd7daef374a8
This commit is contained in:
parent
7b2def024e
commit
e570acd2f9
@ -45,4 +45,14 @@ allExamples = concat
|
||||
, "cuarenta y cinco minutos"
|
||||
, "45 minutos"
|
||||
]
|
||||
, examples (DurationData 92 Minute)
|
||||
[
|
||||
"una hora y treinta y dos minutos"
|
||||
, "una hora treinta y dos minutos"
|
||||
]
|
||||
, examples (DurationData 155 Minute)
|
||||
[
|
||||
"dos hora y treinta y cinco minutos"
|
||||
, "dos hora treinta y cinco minutos"
|
||||
]
|
||||
]
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE NoRebindableSyntax #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
@ -13,11 +14,16 @@ module Duckling.Duration.ES.Rules
|
||||
( rules
|
||||
) where
|
||||
|
||||
import Duckling.Duration.Helpers
|
||||
import Data.Maybe
|
||||
import Duckling.Types
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
import Prelude
|
||||
import Data.Semigroup ((<>))
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Helpers
|
||||
import Duckling.Duration.Types (DurationData(..))
|
||||
import Duckling.Numeral.Types (NumeralData(..))
|
||||
import Duckling.Types
|
||||
import qualified Duckling.Duration.Types as TDuration
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
|
||||
ruleDurationQuarterOfAnHour :: Rule
|
||||
ruleDurationQuarterOfAnHour = Rule
|
||||
@ -46,9 +52,47 @@ ruleDurationThreeQuartersOfAnHour = Rule
|
||||
, prod = \_ -> Just $ Token Duration $ duration TG.Minute 45
|
||||
}
|
||||
|
||||
ruleCompositeDurationCommasAnd :: Rule
|
||||
ruleCompositeDurationCommasAnd = Rule
|
||||
{ name = "composite <duration> (with and)"
|
||||
, pattern =
|
||||
[ Predicate isNatural
|
||||
, dimension TimeGrain
|
||||
, regex "y"
|
||||
, dimension Duration
|
||||
]
|
||||
, prod = \case
|
||||
(Token Numeral NumeralData{TNumeral.value = v}:
|
||||
Token TimeGrain g:
|
||||
_:
|
||||
Token Duration dd@DurationData{TDuration.grain = dg}:
|
||||
_) | g > dg -> Just $ Token Duration $ duration g (floor v) <> dd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleCompositeDuration :: Rule
|
||||
ruleCompositeDuration = Rule
|
||||
{
|
||||
name = "composite <duration>"
|
||||
, pattern =
|
||||
[
|
||||
Predicate isNatural
|
||||
, dimension TimeGrain
|
||||
, dimension Duration
|
||||
]
|
||||
, prod = \case
|
||||
(Token Numeral NumeralData{TNumeral.value = v}:
|
||||
Token TimeGrain g:
|
||||
Token Duration dd@DurationData{TDuration.grain = dg}:
|
||||
_) | g > dg -> Just $ Token Duration $ duration g (floor v) <> dd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDurationHalfOfAnHour
|
||||
, ruleDurationQuarterOfAnHour
|
||||
, ruleDurationThreeQuartersOfAnHour
|
||||
, ruleCompositeDuration
|
||||
, ruleCompositeDurationCommasAnd
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user