mirror of
https://github.com/facebook/duckling.git
synced 2024-09-11 21:27:13 +03:00
Duration
Summary: Duration dimension for Hebrew. Reviewed By: niteria Differential Revision: D4930403 fbshipit-source-id: 690db8f
This commit is contained in:
parent
efa38401b5
commit
dbe9e73541
@ -14,6 +14,7 @@ import Duckling.Dimensions.Types
|
||||
|
||||
allDimensions :: [Some Dimension]
|
||||
allDimensions =
|
||||
[ This Numeral
|
||||
[ This Duration
|
||||
, This Numeral
|
||||
, This Ordinal
|
||||
]
|
||||
|
139
Duckling/Duration/HE/Rules.hs
Normal file
139
Duckling/Duration/HE/Rules.hs
Normal file
@ -0,0 +1,139 @@
|
||||
-- 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. An additional grant
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Duration.HE.Rules
|
||||
( rules ) where
|
||||
|
||||
import Control.Monad (join)
|
||||
import Data.Maybe
|
||||
import Data.String
|
||||
import Data.Text (Text)
|
||||
import Prelude
|
||||
import qualified Data.Text as Text
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Helpers
|
||||
import Duckling.Duration.Types (DurationData (..))
|
||||
import Duckling.Numeral.Helpers (parseInt)
|
||||
import Duckling.Numeral.Types (NumeralData(..))
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
import qualified Duckling.Duration.Types as TDuration
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
|
||||
ruleQuarterOfAnHour :: Rule
|
||||
ruleQuarterOfAnHour = Rule
|
||||
{ name = "quarter of an hour"
|
||||
, pattern =
|
||||
[ regex "(1/4/s \x05e9\x05e2\x05d4|\x05e8\x05d1\x05e2 \x05e9\x05e2\x05d4)"
|
||||
]
|
||||
, prod = \_ -> Just . Token Duration $ duration TG.Minute 15
|
||||
}
|
||||
|
||||
ruleHalfAnHour :: Rule
|
||||
ruleHalfAnHour = Rule
|
||||
{ name = "half an hour"
|
||||
, pattern =
|
||||
[ regex "(1/2/s \x05e9\x05e2\x05d4|\x05d7\x05e6\x05d9 \x05e9\x05e2\x05d4)"
|
||||
]
|
||||
, prod = \_ -> Just . Token Duration $ duration TG.Minute 30
|
||||
}
|
||||
|
||||
ruleThreequartersOfAnHour :: Rule
|
||||
ruleThreequartersOfAnHour = Rule
|
||||
{ name = "three-quarters of an hour"
|
||||
, pattern =
|
||||
[ regex "(3/4/s \x05e9\x05e2\x05d4|\x05e9\x05dc\x05d5\x05e9\x05ea \x05e8\x05d1\x05e2\x05d9 \x05e9\x05e2\x05d4)"
|
||||
]
|
||||
, prod = \_ -> Just . Token Duration $ duration TG.Minute 45
|
||||
}
|
||||
|
||||
ruleIntegerUnitofduration :: Rule
|
||||
ruleIntegerUnitofduration = Rule
|
||||
{ name = "<integer> <unit-of-duration>"
|
||||
, pattern =
|
||||
[ Predicate isNatural
|
||||
, dimension TimeGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token TimeGrain grain:
|
||||
_) -> Just . Token Duration . duration grain $ floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbernumberHours :: Rule
|
||||
ruleNumbernumberHours = Rule
|
||||
{ name = "number.number hours"
|
||||
, pattern =
|
||||
[ regex "(\\d+)\\.(\\d+)"
|
||||
, regex "\x05e9\x05e2\x05d4|\x05e9\x05e2\x05d5\x05ea"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (h:d:_)):_) -> do
|
||||
hh <- parseInt h
|
||||
dec <- parseInt d
|
||||
let divisor = floor $ (fromIntegral (10 :: Integer) :: Float) **
|
||||
fromIntegral (Text.length d - 1)
|
||||
numerator = fromIntegral $ 6 * dec
|
||||
Just . Token Duration . duration TG.Minute $
|
||||
60 * hh + quot numerator divisor
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleIntegerAndAnHalfHours :: Rule
|
||||
ruleIntegerAndAnHalfHours = Rule
|
||||
{ name = "<integer> and an half hours"
|
||||
, pattern =
|
||||
[ Predicate isNatural
|
||||
, regex "\x05d5\x05d7\x05e6\x05d9 (\x05e9\x05e2\x05d5\x05ea|\x05e9\x05e2\x05d4)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
Just . Token Duration . duration TG.Minute $ 30 + 60 * floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleAboutDuration :: Rule
|
||||
ruleAboutDuration = Rule
|
||||
{ name = "about <duration>"
|
||||
, pattern =
|
||||
[ regex "(\x05d1\x05e2\x05e8\x05da|\x05e1\x05d1\x05d9\x05d1\x05d5\x05ea|\x05d1\x05e7\x05d9\x05e8\x05d5\x05d1)"
|
||||
, dimension Duration
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:token:_) -> Just token
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleExactlyDuration :: Rule
|
||||
ruleExactlyDuration = Rule
|
||||
{ name = "exactly <duration>"
|
||||
, pattern =
|
||||
[ regex "\x05d1\x05d3\x05d9\x05d5\x05e7"
|
||||
, dimension Duration
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:token:_) -> Just token
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleAboutDuration
|
||||
, ruleExactlyDuration
|
||||
, ruleHalfAnHour
|
||||
, ruleIntegerAndAnHalfHours
|
||||
, ruleIntegerUnitofduration
|
||||
, ruleNumbernumberHours
|
||||
, ruleQuarterOfAnHour
|
||||
, ruleThreequartersOfAnHour
|
||||
]
|
@ -15,13 +15,14 @@ module Duckling.Rules.HE
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Types
|
||||
import qualified Duckling.Duration.HE.Rules as Duration
|
||||
import qualified Duckling.Numeral.HE.Rules as Numeral
|
||||
import qualified Duckling.Ordinal.HE.Rules as Ordinal
|
||||
import qualified Duckling.TimeGrain.HE.Rules as TimeGrain
|
||||
|
||||
rules :: Some Dimension -> [Rule]
|
||||
rules (This Distance) = []
|
||||
rules (This Duration) = []
|
||||
rules (This Duration) = Duration.rules
|
||||
rules (This Numeral) = Numeral.rules
|
||||
rules (This Email) = []
|
||||
rules (This AmountOfMoney) = []
|
||||
|
@ -182,6 +182,7 @@ library
|
||||
, Duckling.Duration.FR.Rules
|
||||
, Duckling.Duration.GA.Corpus
|
||||
, Duckling.Duration.GA.Rules
|
||||
, Duckling.Duration.HE.Rules
|
||||
, Duckling.Duration.IT.Rules
|
||||
, Duckling.Duration.JA.Corpus
|
||||
, Duckling.Duration.KO.Corpus
|
||||
|
Loading…
Reference in New Issue
Block a user