mirror of
https://github.com/facebook/duckling.git
synced 2024-12-25 05:01:31 +03:00
Rename Number to Numeral
Summary: For consistency with the dimension name. Reviewed By: JonCoens Differential Revision: D4722216 fbshipit-source-id: 82c56d3
This commit is contained in:
parent
33fa98734a
commit
54c9448fba
@ -23,7 +23,7 @@ import Test.Tasty.HUnit
|
||||
import Duckling.Api
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Lang
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Testing.Asserts
|
||||
import Duckling.Testing.Types
|
||||
import Duckling.Types
|
||||
@ -48,7 +48,7 @@ parseTest = testCase "Parse Test" $
|
||||
assertEqual "end" 6 end
|
||||
where
|
||||
sentence = "hey 42 there"
|
||||
val = toJText TNumber.NumberValue {TNumber.vValue = 42.0}
|
||||
val = toJText TNumeral.NumeralValue {TNumeral.vValue = 42.0}
|
||||
|
||||
rankTest :: TestTree
|
||||
rankTest = testGroup "Rank Tests"
|
||||
|
@ -18,7 +18,7 @@ import qualified Duckling.Distance.Tests as Distance
|
||||
import qualified Duckling.Duration.Tests as Duration
|
||||
import qualified Duckling.Email.Tests as Email
|
||||
import qualified Duckling.Finance.Tests as Finance
|
||||
import qualified Duckling.Number.Tests as Number
|
||||
import qualified Duckling.Numeral.Tests as Numeral
|
||||
import qualified Duckling.Ordinal.Tests as Ordinal
|
||||
import qualified Duckling.PhoneNumber.Tests as PhoneNumber
|
||||
import qualified Duckling.Quantity.Tests as Quantity
|
||||
@ -33,7 +33,7 @@ tests = testGroup "Dimensions Tests"
|
||||
, Duration.tests
|
||||
, Email.tests
|
||||
, Finance.tests
|
||||
, Number.tests
|
||||
, Numeral.tests
|
||||
, Ordinal.tests
|
||||
, PhoneNumber.tests
|
||||
, Quantity.tests
|
||||
|
@ -38,7 +38,7 @@ import Duckling.Distance.Types (DistanceData)
|
||||
import Duckling.Duration.Types (DurationData)
|
||||
import Duckling.Email.Types (EmailData)
|
||||
import Duckling.Finance.Types (FinanceData)
|
||||
import Duckling.Number.Types (NumberData)
|
||||
import Duckling.Numeral.Types (NumeralData)
|
||||
import Duckling.Ordinal.Types (OrdinalData)
|
||||
import Duckling.PhoneNumber.Types (PhoneNumberData)
|
||||
import Duckling.Quantity.Types (QuantityData)
|
||||
@ -61,7 +61,7 @@ data Dimension a where
|
||||
Duration :: Dimension DurationData
|
||||
Email :: Dimension EmailData
|
||||
Finance :: Dimension FinanceData
|
||||
Numeral :: Dimension NumberData
|
||||
Numeral :: Dimension NumeralData
|
||||
Ordinal :: Dimension OrdinalData
|
||||
PhoneNumber :: Dimension PhoneNumberData
|
||||
Quantity :: Dimension QuantityData
|
||||
|
@ -18,8 +18,8 @@ import Prelude
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Distance.Helpers
|
||||
import qualified Duckling.Distance.Types as TDistance
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Types
|
||||
|
||||
ruleLatentDistYard :: Rule
|
||||
@ -109,7 +109,7 @@ ruleHalf = Rule
|
||||
[ regex "\xbc18"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral NumberData {TNumber.value = v}:_) ->
|
||||
(Token Numeral NumeralData {TNumeral.value = v}:_) ->
|
||||
Just . Token Distance $ distance v
|
||||
_ -> Nothing
|
||||
}
|
||||
|
@ -19,23 +19,23 @@ import Prelude
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Distance.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Types
|
||||
|
||||
ruleNumberAsDistance :: Rule
|
||||
ruleNumberAsDistance = Rule
|
||||
ruleNumeralAsDistance :: Rule
|
||||
ruleNumeralAsDistance = Rule
|
||||
{ name = "number as distance"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral NumberData {TNumber.value = v}:_) ->
|
||||
(Token Numeral NumeralData {TNumeral.value = v}:_) ->
|
||||
Just . Token Distance $ distance v
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleNumberAsDistance
|
||||
[ ruleNumeralAsDistance
|
||||
]
|
||||
|
@ -19,9 +19,9 @@ import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Helpers
|
||||
import Duckling.Number.Helpers (parseInt)
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers (parseInt)
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
import Duckling.Types
|
||||
@ -47,7 +47,7 @@ ruleIntegerAndAnHalfHours = Rule
|
||||
, regex "og (en )?halv timer?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) ->
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
Just . Token Duration . duration TG.Minute $ 30 + 60 * floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -73,7 +73,7 @@ ruleIntegerMoreUnitofduration = Rule
|
||||
, regex "mere|mindre"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token TimeGrain grain:
|
||||
_) -> Just . Token Duration . duration grain $ floor v
|
||||
_ -> Nothing
|
||||
@ -101,8 +101,8 @@ ruleAboutDuration = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbernumberHours :: Rule
|
||||
ruleNumbernumberHours = Rule
|
||||
ruleNumeralnumberHours :: Rule
|
||||
ruleNumeralnumberHours = Rule
|
||||
{ name = "number.number hours"
|
||||
, pattern =
|
||||
[ regex "(\\d+)\\,(\\d+)"
|
||||
@ -138,5 +138,5 @@ rules =
|
||||
, ruleHalfAnHour
|
||||
, ruleIntegerAndAnHalfHours
|
||||
, ruleIntegerMoreUnitofduration
|
||||
, ruleNumbernumberHours
|
||||
, ruleNumeralnumberHours
|
||||
]
|
||||
|
@ -19,9 +19,9 @@ import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Helpers
|
||||
import Duckling.Number.Helpers (parseInt)
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers (parseInt)
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
import Duckling.Types
|
||||
@ -53,15 +53,15 @@ ruleIntegerMoreUnitofduration = Rule
|
||||
, dimension TimeGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
_:
|
||||
Token TimeGrain grain:
|
||||
_) -> Just . Token Duration . duration grain $ floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbernumberHours :: Rule
|
||||
ruleNumbernumberHours = Rule
|
||||
ruleNumeralnumberHours :: Rule
|
||||
ruleNumeralnumberHours = Rule
|
||||
{ name = "number.number hours"
|
||||
, pattern =
|
||||
[ regex "(\\d+)\\.(\\d+) stunden?"
|
||||
@ -86,7 +86,7 @@ ruleIntegerAndAnHalfHours = Rule
|
||||
, regex "ein ?halb stunden?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) ->
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
Just . Token Duration . duration TG.Minute $ 30 + 60 * floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -136,5 +136,5 @@ rules =
|
||||
, ruleHalfAnHour
|
||||
, ruleIntegerAndAnHalfHours
|
||||
, ruleIntegerMoreUnitofduration
|
||||
, ruleNumbernumberHours
|
||||
, ruleNumeralnumberHours
|
||||
]
|
||||
|
@ -19,9 +19,9 @@ import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Helpers
|
||||
import Duckling.Number.Helpers (parseInt)
|
||||
import Duckling.Number.Types (NumberData(..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers (parseInt)
|
||||
import Duckling.Numeral.Types (NumeralData(..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
import Duckling.Types
|
||||
@ -54,15 +54,15 @@ ruleDurationFortnight = Rule
|
||||
, prod = \_ -> Just . Token Duration $ duration TG.Day 14
|
||||
}
|
||||
|
||||
ruleNumberQuotes :: Rule
|
||||
ruleNumberQuotes = Rule
|
||||
ruleNumeralQuotes :: Rule
|
||||
ruleNumeralQuotes = Rule
|
||||
{ name = "<integer> + '\""
|
||||
, pattern =
|
||||
[ Predicate isNatural
|
||||
, regex "(['\"])"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (x:_)):
|
||||
_) -> case x of
|
||||
"'" -> Just . Token Duration . duration TG.Minute $ floor v
|
||||
@ -71,8 +71,8 @@ ruleNumberQuotes = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDurationNumberMore :: Rule
|
||||
ruleDurationNumberMore = Rule
|
||||
ruleDurationNumeralMore :: Rule
|
||||
ruleDurationNumeralMore = Rule
|
||||
{ name = "<integer> more <unit-of-duration>"
|
||||
, pattern =
|
||||
[ Predicate isNatural
|
||||
@ -81,12 +81,12 @@ ruleDurationNumberMore = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd:_:Token TimeGrain grain:_) ->
|
||||
Just . Token Duration . duration grain . floor $ TNumber.value nd
|
||||
Just . Token Duration . duration grain . floor $ TNumeral.value nd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDurationDotNumberHours :: Rule
|
||||
ruleDurationDotNumberHours = Rule
|
||||
ruleDurationDotNumeralHours :: Rule
|
||||
ruleDurationDotNumeralHours = Rule
|
||||
{ name = "number.number hours"
|
||||
, pattern = [regex "(\\d+)\\.(\\d+) *hours?"]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -109,7 +109,7 @@ ruleDurationAndHalfHour = Rule
|
||||
, regex "and (an? )?half hours?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) ->
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
Just . Token Duration . duration TG.Minute $ 30 + 60 * floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -144,10 +144,10 @@ rules =
|
||||
, ruleDurationHalfAnHour
|
||||
, ruleDurationThreeQuartersOfAnHour
|
||||
, ruleDurationFortnight
|
||||
, ruleDurationNumberMore
|
||||
, ruleDurationDotNumberHours
|
||||
, ruleDurationNumeralMore
|
||||
, ruleDurationDotNumeralHours
|
||||
, ruleDurationAndHalfHour
|
||||
, ruleDurationA
|
||||
, ruleDurationPrecision
|
||||
, ruleNumberQuotes
|
||||
, ruleNumeralQuotes
|
||||
]
|
||||
|
@ -17,21 +17,21 @@ import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Helpers
|
||||
import Duckling.Number.Types (NumberData(..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData(..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
import Duckling.Types
|
||||
|
||||
ruleNumberQuotes :: Rule
|
||||
ruleNumberQuotes = Rule
|
||||
ruleNumeralQuotes :: Rule
|
||||
ruleNumeralQuotes = Rule
|
||||
{ name = "<integer> + '\""
|
||||
, pattern =
|
||||
[ Predicate isNatural
|
||||
, regex "(['\"])"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (x:_)):
|
||||
_) -> case x of
|
||||
"'" -> Just . Token Duration . duration TG.Minute $ floor v
|
||||
@ -100,5 +100,5 @@ rules =
|
||||
, ruleUneDemiHeure
|
||||
, ruleTroisQuartsDHeure
|
||||
, ruleDurationEnviron
|
||||
, ruleNumberQuotes
|
||||
, ruleNumeralQuotes
|
||||
]
|
||||
|
@ -17,8 +17,8 @@ import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Helpers
|
||||
import Duckling.Number.Types (NumberData(..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData(..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
import Duckling.Types
|
||||
|
||||
@ -44,9 +44,9 @@ ruleAonDurationAmhain :: Rule
|
||||
ruleAonDurationAmhain = Rule
|
||||
{ name = "aon X amhain"
|
||||
, pattern =
|
||||
[ isNumberWith TNumber.value (== 1)
|
||||
[ isNumeralWith TNumeral.value (== 1)
|
||||
, dimension TimeGrain
|
||||
, isNumberWith TNumber.value (== 1)
|
||||
, isNumeralWith TNumeral.value (== 1)
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token TimeGrain grain:_) -> Just . Token Duration $ duration grain 1
|
||||
@ -57,14 +57,14 @@ ruleIntegerUnitofdurationInteger :: Rule
|
||||
ruleIntegerUnitofdurationInteger = Rule
|
||||
{ name = "<unit-integer> <unit-of-duration> <tens-integer>"
|
||||
, pattern =
|
||||
[ isNumberWith TNumber.value (< 10)
|
||||
[ isNumeralWith TNumeral.value (< 10)
|
||||
, dimension TimeGrain
|
||||
, isNumberWith TNumber.value (`elem` [10, 20 .. 50])
|
||||
, isNumeralWith TNumeral.value (`elem` [10, 20 .. 50])
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token TimeGrain grain:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> Just . Token Duration . duration grain . floor $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ module Duckling.Duration.Helpers
|
||||
( duration
|
||||
, isGrain
|
||||
, isNatural
|
||||
, isNumberWith
|
||||
, isNumeralWith
|
||||
) where
|
||||
|
||||
import Prelude
|
||||
@ -21,8 +21,8 @@ import Prelude
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Types (DurationData (DurationData))
|
||||
import qualified Duckling.Duration.Types as TDuration
|
||||
import Duckling.Number.Types (NumberData (NumberData))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (NumeralData))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
import Duckling.Types
|
||||
|
||||
@ -34,12 +34,12 @@ isGrain value (Token TimeGrain grain) = grain == value
|
||||
isGrain _ _ = False
|
||||
|
||||
isNatural :: Predicate
|
||||
isNatural (Token Numeral NumberData {TNumber.value = x}) =
|
||||
TNumber.isNatural x
|
||||
isNatural (Token Numeral NumeralData {TNumeral.value = x}) =
|
||||
TNumeral.isNatural x
|
||||
isNatural _ = False
|
||||
|
||||
isNumberWith :: (NumberData -> t) -> (t -> Bool) -> PatternItem
|
||||
isNumberWith f pred = Predicate $ \x -> case x of
|
||||
isNumeralWith :: (NumeralData -> t) -> (t -> Bool) -> PatternItem
|
||||
isNumeralWith f pred = Predicate $ \x -> case x of
|
||||
(Token Numeral x) -> pred $ f x
|
||||
_ -> False
|
||||
|
||||
|
@ -19,9 +19,9 @@ import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Helpers
|
||||
import Duckling.Number.Helpers (parseInt)
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers (parseInt)
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
import Duckling.Types
|
||||
@ -45,8 +45,8 @@ ruleADay = Rule
|
||||
, prod = \_ -> Just . Token Duration $ duration TG.Day 1
|
||||
}
|
||||
|
||||
ruleNumbernumberHours :: Rule
|
||||
ruleNumbernumberHours = Rule
|
||||
ruleNumeralnumberHours :: Rule
|
||||
ruleNumeralnumberHours = Rule
|
||||
{ name = "number.number hours"
|
||||
, pattern =
|
||||
[ regex "(\\d+)\\.(\\d+)"
|
||||
@ -72,7 +72,7 @@ ruleIntegerAndAnHalfHours = Rule
|
||||
, regex "\xc2dc\xac04\xbc18"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) ->
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
Just . Token Duration . duration TG.Minute $ 30 + 60 * floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -108,5 +108,5 @@ rules =
|
||||
, ruleExactlyDuration
|
||||
, ruleHalfAnHour
|
||||
, ruleIntegerAndAnHalfHours
|
||||
, ruleNumbernumberHours
|
||||
, ruleNumeralnumberHours
|
||||
]
|
||||
|
@ -19,9 +19,9 @@ import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Helpers
|
||||
import Duckling.Number.Helpers (parseInt)
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers (parseInt)
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
import Duckling.Types
|
||||
@ -44,14 +44,14 @@ ruleIntegerMoreUnitofduration = Rule
|
||||
, regex "mere?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token TimeGrain grain:
|
||||
_) -> Just . Token Duration . duration grain $ floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbernumberHours :: Rule
|
||||
ruleNumbernumberHours = Rule
|
||||
ruleNumeralnumberHours :: Rule
|
||||
ruleNumeralnumberHours = Rule
|
||||
{ name = "number.number hours"
|
||||
, pattern =
|
||||
[ regex "(\\d+)\\,(\\d+) *timer?"
|
||||
@ -76,7 +76,7 @@ ruleIntegerAndAnHalfHours = Rule
|
||||
, regex "og (en )?halv time?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) ->
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
Just . Token Duration . duration TG.Minute $ 30 + 60 * floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -125,5 +125,5 @@ rules =
|
||||
, ruleHalfAnHour
|
||||
, ruleIntegerAndAnHalfHours
|
||||
, ruleIntegerMoreUnitofduration
|
||||
, ruleNumbernumberHours
|
||||
, ruleNumeralnumberHours
|
||||
]
|
||||
|
@ -19,9 +19,9 @@ import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Helpers
|
||||
import Duckling.Number.Helpers (parseInt)
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers (parseInt)
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
import Duckling.Types
|
||||
@ -44,15 +44,15 @@ ruleIntegerMoreUnitofduration = Rule
|
||||
, dimension TimeGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
_:
|
||||
Token TimeGrain grain:
|
||||
_) -> Just . Token Duration . duration grain $ floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbernumberHours :: Rule
|
||||
ruleNumbernumberHours = Rule
|
||||
ruleNumeralnumberHours :: Rule
|
||||
ruleNumeralnumberHours = Rule
|
||||
{ name = "number.number hours"
|
||||
, pattern =
|
||||
[ regex "(\\d+)\\.(\\d+)"
|
||||
@ -78,7 +78,7 @@ ruleIntegerAndAnHalfHours = Rule
|
||||
, regex "i (p(o|\x00f3)(l|\x0142)) godziny"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) ->
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
Just . Token Duration . duration TG.Minute $ 30 + 60 * floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -126,6 +126,6 @@ rules =
|
||||
, ruleHalfAnHour
|
||||
, ruleIntegerAndAnHalfHours
|
||||
, ruleIntegerMoreUnitofduration
|
||||
, ruleNumbernumberHours
|
||||
, ruleNumeralnumberHours
|
||||
, ruleUnitofdurationAsADuration
|
||||
]
|
||||
|
@ -18,8 +18,8 @@ import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Helpers
|
||||
import Duckling.Number.Types (NumberData(..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData(..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Types
|
||||
|
||||
ruleIntegerUnitofduration :: Rule
|
||||
@ -30,7 +30,7 @@ ruleIntegerUnitofduration = Rule
|
||||
, dimension TimeGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token TimeGrain grain:
|
||||
_) -> Just . Token Duration . duration grain $ floor v
|
||||
_ -> Nothing
|
||||
|
@ -19,9 +19,9 @@ import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.Helpers
|
||||
import Duckling.Number.Helpers (parseInt)
|
||||
import Duckling.Number.Types (NumberData(..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers (parseInt)
|
||||
import Duckling.Numeral.Types (NumeralData(..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
import Duckling.Types
|
||||
@ -44,14 +44,14 @@ ruleIntegerMoreUnitofduration = Rule
|
||||
, regex "fler|mer"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token TimeGrain grain:
|
||||
_) -> Just . Token Duration . duration grain $ floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbernumberHours :: Rule
|
||||
ruleNumbernumberHours = Rule
|
||||
ruleNumeralnumberHours :: Rule
|
||||
ruleNumeralnumberHours = Rule
|
||||
{ name = "number.number hours"
|
||||
, pattern =
|
||||
[ regex "(\\d+)\\,(\\d+)"
|
||||
@ -77,7 +77,7 @@ ruleIntegerAndAnHalfHours = Rule
|
||||
, regex "och (en )?halv timme?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) ->
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
Just . Token Duration . duration TG.Minute $ 30 + 60 * floor v
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -127,5 +127,5 @@ rules =
|
||||
, ruleHalfAnHour
|
||||
, ruleIntegerAndAnHalfHours
|
||||
, ruleIntegerMoreUnitofduration
|
||||
, ruleNumbernumberHours
|
||||
, ruleNumeralnumberHours
|
||||
]
|
||||
|
@ -21,8 +21,8 @@ import Duckling.Dimensions.Types
|
||||
import Duckling.Finance.Helpers
|
||||
import Duckling.Finance.Types (Currency(..), FinanceData (..))
|
||||
import qualified Duckling.Finance.Types as TFinance
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -128,13 +128,13 @@ ruleIntersect = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleIntersectAndNumber :: Rule
|
||||
ruleIntersectAndNumber = Rule
|
||||
ruleIntersectAndNumeral :: Rule
|
||||
ruleIntersectAndNumeral = Rule
|
||||
{ name = "intersect (and number)"
|
||||
, pattern =
|
||||
[ financeWith TFinance.value isJust
|
||||
@ -144,7 +144,7 @@ ruleIntersectAndNumber = Rule
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -182,7 +182,7 @@ rules =
|
||||
, ruleDinars
|
||||
, ruleDirham
|
||||
, ruleIntersect
|
||||
, ruleIntersectAndNumber
|
||||
, ruleIntersectAndNumeral
|
||||
, ruleIntersectAndXCents
|
||||
, ruleIntersectXCents
|
||||
, ruleOtherPounds
|
||||
|
@ -20,8 +20,8 @@ import Duckling.Dimensions.Types
|
||||
import Duckling.Finance.Helpers
|
||||
import Duckling.Finance.Types (Currency(..), FinanceData (..))
|
||||
import qualified Duckling.Finance.Types as TFinance
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Types
|
||||
|
||||
ruleDollar :: Rule
|
||||
@ -51,8 +51,8 @@ rulePounds = Rule
|
||||
, prod = \_ -> Just . Token Finance $ currencyOnly Pound
|
||||
}
|
||||
|
||||
ruleIntersectAndNumber :: Rule
|
||||
ruleIntersectAndNumber = Rule
|
||||
ruleIntersectAndNumeral :: Rule
|
||||
ruleIntersectAndNumeral = Rule
|
||||
{ name = "intersect (and number)"
|
||||
, pattern =
|
||||
[ financeWith TFinance.value isJust
|
||||
@ -62,7 +62,7 @@ ruleIntersectAndNumber = Rule
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -106,7 +106,7 @@ ruleIntersect = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -116,7 +116,7 @@ rules =
|
||||
[ ruleCent
|
||||
, ruleDollar
|
||||
, ruleIntersect
|
||||
, ruleIntersectAndNumber
|
||||
, ruleIntersectAndNumeral
|
||||
, ruleIntersectAndXCents
|
||||
, ruleIntersectXCents
|
||||
, rulePounds
|
||||
|
@ -20,12 +20,12 @@ import Duckling.Dimensions.Types
|
||||
import Duckling.Finance.Helpers
|
||||
import Duckling.Finance.Types (Currency (..), FinanceData (..))
|
||||
import qualified Duckling.Finance.Types as TFinance
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Types
|
||||
|
||||
ruleIntersectAndNumber :: Rule
|
||||
ruleIntersectAndNumber = Rule
|
||||
ruleIntersectAndNumeral :: Rule
|
||||
ruleIntersectAndNumeral = Rule
|
||||
{ name = "intersect (and number)"
|
||||
, pattern =
|
||||
[ financeWith TFinance.value isJust
|
||||
@ -35,7 +35,7 @@ ruleIntersectAndNumber = Rule
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -109,7 +109,7 @@ ruleIntersect = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -127,7 +127,7 @@ rules :: [Rule]
|
||||
rules =
|
||||
[ ruleCent
|
||||
, ruleIntersect
|
||||
, ruleIntersectAndNumber
|
||||
, ruleIntersectAndNumeral
|
||||
, ruleIntersectAndXCents
|
||||
, ruleIntersectXCents
|
||||
, rulePounds
|
||||
|
@ -20,8 +20,8 @@ import Duckling.Dimensions.Types
|
||||
import Duckling.Finance.Helpers
|
||||
import Duckling.Finance.Types (Currency (..), FinanceData (..))
|
||||
import qualified Duckling.Finance.Types as TFinance
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Types
|
||||
|
||||
ruleDollar :: Rule
|
||||
@ -102,7 +102,7 @@ ruleIntersect = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -116,8 +116,8 @@ ruleInr = Rule
|
||||
, prod = \_ -> Just . Token Finance $ currencyOnly INR
|
||||
}
|
||||
|
||||
ruleIntersectAgusNumber :: Rule
|
||||
ruleIntersectAgusNumber = Rule
|
||||
ruleIntersectAgusNumeral :: Rule
|
||||
ruleIntersectAgusNumeral = Rule
|
||||
{ name = "intersect (agus number)"
|
||||
, pattern =
|
||||
[ financeWith TFinance.value isJust
|
||||
@ -125,7 +125,7 @@ ruleIntersectAgusNumber = Rule
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:_:Token Numeral (NumberData {TNumber.value = c}):_) ->
|
||||
(Token Finance fd:_:Token Numeral (NumeralData {TNumeral.value = c}):_) ->
|
||||
Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -149,7 +149,7 @@ rules =
|
||||
, ruleDollar
|
||||
, ruleInr
|
||||
, ruleIntersect
|
||||
, ruleIntersectAgusNumber
|
||||
, ruleIntersectAgusNumeral
|
||||
, ruleIntersectAndXCents
|
||||
, ruleIntersectXCents
|
||||
, rulePounds
|
||||
|
@ -20,8 +20,8 @@ import Duckling.Dimensions.Types
|
||||
import Duckling.Finance.Helpers
|
||||
import Duckling.Finance.Types (Currency(..))
|
||||
import qualified Duckling.Finance.Types as TFinance
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Types
|
||||
|
||||
ruleDollar :: Rule
|
||||
@ -60,7 +60,7 @@ ruleIntersect = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
@ -20,12 +20,12 @@ import Duckling.Dimensions.Types
|
||||
import Duckling.Finance.Helpers
|
||||
import Duckling.Finance.Types (Currency (..), FinanceData (..))
|
||||
import qualified Duckling.Finance.Types as TFinance
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Types
|
||||
|
||||
ruleIntersectAndNumber :: Rule
|
||||
ruleIntersectAndNumber = Rule
|
||||
ruleIntersectAndNumeral :: Rule
|
||||
ruleIntersectAndNumeral = Rule
|
||||
{ name = "intersect (and number)"
|
||||
, pattern =
|
||||
[ financeWith TFinance.value isJust
|
||||
@ -35,7 +35,7 @@ ruleIntersectAndNumber = Rule
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -134,7 +134,7 @@ ruleIntersect = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -154,7 +154,7 @@ rules =
|
||||
, ruleCent
|
||||
, ruleDirham
|
||||
, ruleIntersect
|
||||
, ruleIntersectAndNumber
|
||||
, ruleIntersectAndNumeral
|
||||
, ruleIntersectAndXCents
|
||||
, ruleIntersectXCents
|
||||
, ruleIntersectXCentsWithAnd
|
||||
|
@ -20,12 +20,12 @@ import Duckling.Dimensions.Types
|
||||
import Duckling.Finance.Helpers
|
||||
import Duckling.Finance.Types (Currency(..), FinanceData (..))
|
||||
import qualified Duckling.Finance.Types as TFinance
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Types
|
||||
|
||||
ruleIntersectAndNumber :: Rule
|
||||
ruleIntersectAndNumber = Rule
|
||||
ruleIntersectAndNumeral :: Rule
|
||||
ruleIntersectAndNumeral = Rule
|
||||
{ name = "intersect (and number)"
|
||||
, pattern =
|
||||
[ financeWith TFinance.value isJust
|
||||
@ -35,7 +35,7 @@ ruleIntersectAndNumber = Rule
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -106,7 +106,7 @@ ruleIntersect = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -126,7 +126,7 @@ rules =
|
||||
, ruleCent
|
||||
, ruleDollar
|
||||
, ruleIntersect
|
||||
, ruleIntersectAndNumber
|
||||
, ruleIntersectAndNumeral
|
||||
, ruleIntersectAndXCents
|
||||
, ruleIntersectXCents
|
||||
, rulePounds
|
||||
|
@ -21,13 +21,13 @@ import Duckling.Dimensions.Types
|
||||
import Duckling.Finance.Helpers
|
||||
import Duckling.Finance.Types (Currency(..), FinanceData (..))
|
||||
import qualified Duckling.Finance.Types as TFinance
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
ruleIntersectAndNumber :: Rule
|
||||
ruleIntersectAndNumber = Rule
|
||||
ruleIntersectAndNumeral :: Rule
|
||||
ruleIntersectAndNumeral = Rule
|
||||
{ name = "intersect (and number)"
|
||||
, pattern =
|
||||
[ financeWith TFinance.value isJust
|
||||
@ -37,7 +37,7 @@ ruleIntersectAndNumber = Rule
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -159,7 +159,7 @@ ruleIntersect = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -198,7 +198,7 @@ rules =
|
||||
, ruleDollar
|
||||
, ruleInr
|
||||
, ruleIntersect
|
||||
, ruleIntersectAndNumber
|
||||
, ruleIntersectAndNumeral
|
||||
, ruleIntersectAndXCents
|
||||
, ruleIntersectXCents
|
||||
, ruleKwd
|
||||
|
@ -25,8 +25,8 @@ import Duckling.Dimensions.Types
|
||||
import Duckling.Finance.Helpers
|
||||
import Duckling.Finance.Types (Currency(..), FinanceData (..))
|
||||
import qualified Duckling.Finance.Types as TFinance
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -100,7 +100,7 @@ ruleAmountUnit = Rule
|
||||
, financeWith TFinance.value isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token Finance (FinanceData {TFinance.currency = c}):
|
||||
_) -> Just . Token Finance . withValue v $ currencyOnly c
|
||||
_ -> Nothing
|
||||
@ -115,7 +115,7 @@ ruleUnitAmount = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance (FinanceData {TFinance.currency = c}):
|
||||
Token Numeral (NumberData {TNumber.value = v}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
_) -> Just . Token Finance . withValue v $ currencyOnly c
|
||||
_ -> Nothing
|
||||
}
|
||||
|
@ -20,12 +20,12 @@ import Duckling.Dimensions.Types
|
||||
import Duckling.Finance.Helpers
|
||||
import Duckling.Finance.Types (Currency(..), FinanceData (..))
|
||||
import qualified Duckling.Finance.Types as TFinance
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Types
|
||||
|
||||
ruleIntersectAndNumber :: Rule
|
||||
ruleIntersectAndNumber = Rule
|
||||
ruleIntersectAndNumeral :: Rule
|
||||
ruleIntersectAndNumeral = Rule
|
||||
{ name = "intersect (and number)"
|
||||
, pattern =
|
||||
[ financeWith TFinance.value isJust
|
||||
@ -35,7 +35,7 @@ ruleIntersectAndNumber = Rule
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -130,7 +130,7 @@ ruleIntersect = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -160,7 +160,7 @@ rules =
|
||||
, ruleDirham
|
||||
, ruleExactlyAmountofmoney
|
||||
, ruleIntersect
|
||||
, ruleIntersectAndNumber
|
||||
, ruleIntersectAndNumeral
|
||||
, ruleIntersectAndXCents
|
||||
, ruleIntersectXCents
|
||||
, ruleNok
|
||||
|
@ -20,8 +20,8 @@ import Duckling.Dimensions.Types
|
||||
import Duckling.Finance.Helpers
|
||||
import Duckling.Finance.Types (Currency(..), FinanceData (..))
|
||||
import qualified Duckling.Finance.Types as TFinance
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Types
|
||||
|
||||
ruleNg :: Rule
|
||||
@ -78,13 +78,13 @@ ruleIntersect = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleIntersectAndNumber :: Rule
|
||||
ruleIntersectAndNumber = Rule
|
||||
ruleIntersectAndNumeral :: Rule
|
||||
ruleIntersectAndNumeral = Rule
|
||||
{ name = "intersect and number"
|
||||
, pattern =
|
||||
[ financeWith TFinance.value isJust
|
||||
@ -94,7 +94,7 @@ ruleIntersectAndNumber = Rule
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Finance fd:
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = c}):
|
||||
Token Numeral (NumeralData {TNumeral.value = c}):
|
||||
_) -> Just . Token Finance $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -144,7 +144,7 @@ rules =
|
||||
, ruleDirham
|
||||
, ruleDollar
|
||||
, ruleIntersect
|
||||
, ruleIntersectAndNumber
|
||||
, ruleIntersectAndNumeral
|
||||
, ruleIntersectVXXuxen
|
||||
, ruleIntersectXXuxen
|
||||
, ruleNg
|
||||
|
@ -1,66 +0,0 @@
|
||||
-- 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.
|
||||
|
||||
|
||||
module Duckling.Number.Tests (tests) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
import Test.Tasty
|
||||
|
||||
import qualified Duckling.Number.AR.Tests as AR
|
||||
import qualified Duckling.Number.DA.Tests as DA
|
||||
import qualified Duckling.Number.DE.Tests as DE
|
||||
import qualified Duckling.Number.EN.Tests as EN
|
||||
import qualified Duckling.Number.ES.Tests as ES
|
||||
import qualified Duckling.Number.ET.Tests as ET
|
||||
import qualified Duckling.Number.FR.Tests as FR
|
||||
import qualified Duckling.Number.GA.Tests as GA
|
||||
import qualified Duckling.Number.ID.Tests as ID
|
||||
import qualified Duckling.Number.IT.Tests as IT
|
||||
import qualified Duckling.Number.JA.Tests as JA
|
||||
import qualified Duckling.Number.KO.Tests as KO
|
||||
import qualified Duckling.Number.MY.Tests as MY
|
||||
import qualified Duckling.Number.NB.Tests as NB
|
||||
import qualified Duckling.Number.NL.Tests as NL
|
||||
import qualified Duckling.Number.PL.Tests as PL
|
||||
import qualified Duckling.Number.PT.Tests as PT
|
||||
import qualified Duckling.Number.RO.Tests as RO
|
||||
import qualified Duckling.Number.RU.Tests as RU
|
||||
import qualified Duckling.Number.SV.Tests as SV
|
||||
import qualified Duckling.Number.TR.Tests as TR
|
||||
import qualified Duckling.Number.UK.Tests as UK
|
||||
import qualified Duckling.Number.VI.Tests as VI
|
||||
import qualified Duckling.Number.ZH.Tests as ZH
|
||||
|
||||
tests :: TestTree
|
||||
tests = testGroup "Number Tests"
|
||||
[ AR.tests
|
||||
, DA.tests
|
||||
, DE.tests
|
||||
, EN.tests
|
||||
, ES.tests
|
||||
, ET.tests
|
||||
, FR.tests
|
||||
, GA.tests
|
||||
, ID.tests
|
||||
, IT.tests
|
||||
, JA.tests
|
||||
, KO.tests
|
||||
, MY.tests
|
||||
, NB.tests
|
||||
, NL.tests
|
||||
, PL.tests
|
||||
, PT.tests
|
||||
, RO.tests
|
||||
, RU.tests
|
||||
, SV.tests
|
||||
, TR.tests
|
||||
, UK.tests
|
||||
, VI.tests
|
||||
, ZH.tests
|
||||
]
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.AR.Corpus
|
||||
module Duckling.Numeral.AR.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,94 +24,94 @@ corpus = (testContext {lang = AR}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "صفر"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "واحد"
|
||||
]
|
||||
, examples (NumberValue 4)
|
||||
, examples (NumeralValue 4)
|
||||
[ "4"
|
||||
, "أربعة"
|
||||
, "أربع"
|
||||
]
|
||||
, examples (NumberValue 6)
|
||||
, examples (NumeralValue 6)
|
||||
[ "6"
|
||||
, "ستة"
|
||||
, "ست"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "ثلاث و ثلاثون"
|
||||
]
|
||||
, examples (NumberValue 11)
|
||||
, examples (NumeralValue 11)
|
||||
[ "11"
|
||||
, "إحدى عشرة"
|
||||
, "إحدى عشر"
|
||||
]
|
||||
, examples (NumberValue 12)
|
||||
, examples (NumeralValue 12)
|
||||
[ "12"
|
||||
, "إثنتى عشر"
|
||||
, "إثنى عشر"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "أربع عشر"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "ستة عشر"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "سبع عشر"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "ثمان عشرة"
|
||||
]
|
||||
, examples (NumberValue 525)
|
||||
, examples (NumeralValue 525)
|
||||
[ "خمسمائة و خمسة و عشرون"
|
||||
, "525"
|
||||
]
|
||||
, examples (NumberValue 21)
|
||||
, examples (NumeralValue 21)
|
||||
[ "واحدة و عشرون"
|
||||
, "21"
|
||||
]
|
||||
, examples (NumberValue 24)
|
||||
, examples (NumeralValue 24)
|
||||
[ "أربعة و عشرون"
|
||||
, "24"
|
||||
]
|
||||
, examples (NumberValue 26)
|
||||
, examples (NumeralValue 26)
|
||||
[ "ستة و عشرون"
|
||||
, "26"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1.1"
|
||||
, "1.10"
|
||||
, "01.10"
|
||||
, "1 فاصلة 1"
|
||||
, "واحد فاصلة واحد"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0.77"
|
||||
, ".77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100000"
|
||||
, "100 الف"
|
||||
]
|
||||
, examples (NumberValue 10000)
|
||||
, examples (NumeralValue 10000)
|
||||
[ "10000"
|
||||
, "10 آلاف"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3 ملايين"
|
||||
, "3000000"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "-1200000"
|
||||
]
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.AR.Rules
|
||||
module Duckling.Numeral.AR.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.Maybe
|
||||
@ -18,9 +18,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -42,9 +42,9 @@ ruleInteger23 = Rule
|
||||
, numberBetween 1 100
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -100,9 +100,9 @@ ruleInteger22 = Rule
|
||||
, oneOf [20, 30 .. 90]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -112,10 +112,10 @@ ruleInteger21 = Rule
|
||||
{ name = "integer (13..19)"
|
||||
, pattern =
|
||||
[ numberBetween 3 10
|
||||
, numberWith TNumber.value (== 10)
|
||||
, numberWith TNumeral.value (== 10)
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v + 10
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v + 10
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
@ -152,8 +152,8 @@ ruleInteger15 = Rule
|
||||
, prod = \_ -> integer 11
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*\\.\\d+)"
|
||||
@ -215,15 +215,16 @@ ruleInteger12 = Rule
|
||||
, prod = \_ -> integer 8
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithMinus :: Rule
|
||||
ruleNumbersPrefixWithMinus = Rule
|
||||
ruleNumeralsPrefixWithMinus :: Rule
|
||||
ruleNumeralsPrefixWithMinus = Rule
|
||||
{ name = "numbers prefix with -, minus"
|
||||
, pattern =
|
||||
[ regex "-"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral (NumberData {TNumber.value = v}):_) -> double (v * (- 1))
|
||||
(_:Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
double (v * (- 1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -311,18 +312,18 @@ ruleInteger20 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "\x0641\x0627\x0635\x0644\x0629"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + decimalsToDouble v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -341,7 +342,7 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDecimalNumber
|
||||
[ ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleInteger
|
||||
, ruleInteger11
|
||||
@ -364,7 +365,7 @@ rules =
|
||||
, ruleIntegerNumeric
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleMultiply
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumbersPrefixWithMinus
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumeralsPrefixWithMinus
|
||||
, rulePowersOfTen
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.AR.Tests
|
||||
module Duckling.Numeral.AR.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.AR.Corpus
|
||||
import Duckling.Numeral.AR.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.DA.Corpus
|
||||
module Duckling.Numeral.DA.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,67 +24,67 @@ corpus = (testContext {lang = DA}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "nul"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "én"
|
||||
, "en"
|
||||
, "ét"
|
||||
, "et"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "to"
|
||||
, "et par"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "fjorten"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "seksten"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "sytten"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "Atten"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1,1"
|
||||
, "1,10"
|
||||
, "01,10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0,77"
|
||||
, ",77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100.000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3.000.000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1.200.000"
|
||||
, "1200000"
|
||||
, "1,2M"
|
||||
, "1200K"
|
||||
, ",0012G"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1.200.000"
|
||||
, "-1200000"
|
||||
, "minus 1.200.000"
|
||||
@ -93,7 +93,7 @@ allExamples = concat
|
||||
, "-1200K"
|
||||
, "-,0012G"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "5 tusind"
|
||||
, "fem tusinde"
|
||||
, "fem Tusind"
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.DA.Rules
|
||||
module Duckling.Numeral.DA.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.HashMap.Strict (HashMap)
|
||||
@ -21,21 +21,22 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|minus\\s?|negativ\\s?"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v * (-1)
|
||||
(_:Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
double $ v * (-1)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -82,8 +83,8 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*,\\d+)"
|
||||
@ -102,8 +103,8 @@ ruleInteger3 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -121,25 +122,25 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -176,8 +177,8 @@ ruleAPair = Rule
|
||||
, prod = \_ -> integer 2 >>= withGrain 1
|
||||
}
|
||||
|
||||
ruleNumbersOg :: Rule
|
||||
ruleNumbersOg = Rule
|
||||
ruleNumeralsOg :: Rule
|
||||
ruleNumeralsOg = Rule
|
||||
{ name = "numbers og"
|
||||
, pattern =
|
||||
[ numberBetween 1 10
|
||||
@ -185,9 +186,9 @@ ruleNumbersOg = Rule
|
||||
, oneOf [70, 20, 60, 50, 40, 90, 30, 80]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -206,7 +207,7 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
@ -274,18 +275,18 @@ ruleInteger2 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "komma"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + decimalsToDouble v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -305,7 +306,7 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleAPair
|
||||
, ruleDecimalNumber
|
||||
, ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleDozen
|
||||
, ruleFew
|
||||
@ -316,10 +317,10 @@ rules =
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleIntersect
|
||||
, ruleMultiply
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumbersOg
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumeralsOg
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
, rulePowersOfTen
|
||||
, ruleSingle
|
||||
, ruleTen
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.DA.Tests
|
||||
module Duckling.Numeral.DA.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.DA.Corpus
|
||||
import Duckling.Numeral.DA.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.DE.Corpus
|
||||
module Duckling.Numeral.DE.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,82 +24,82 @@ corpus = (testContext {lang = DE}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "null"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "eins"
|
||||
]
|
||||
, examples (NumberValue 3)
|
||||
, examples (NumeralValue 3)
|
||||
[ "3"
|
||||
, "Drei"
|
||||
]
|
||||
, examples (NumberValue 30)
|
||||
, examples (NumeralValue 30)
|
||||
[ "30"
|
||||
, "dreissig"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "drei Und dreissig"
|
||||
, "dreiunddreissig"
|
||||
, "0033"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "vierzehn"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "sechzehn"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "Siebzehn"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "achtzehn"
|
||||
]
|
||||
, examples (NumberValue 200)
|
||||
, examples (NumeralValue 200)
|
||||
[ "200"
|
||||
, "zwei hundert"
|
||||
]
|
||||
, examples (NumberValue 102)
|
||||
, examples (NumeralValue 102)
|
||||
[ "102"
|
||||
, "Hundert zwei"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1,1"
|
||||
, "1 komma 1"
|
||||
, "1,10"
|
||||
, "01,10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0,77"
|
||||
, ",77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100.000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3.000.000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1.200.000"
|
||||
, "1200000"
|
||||
, "1,2M"
|
||||
, "1200K"
|
||||
, ",0012G"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1.200.000"
|
||||
, "-1200000"
|
||||
, "minus 1.200.000"
|
||||
@ -108,26 +108,26 @@ allExamples = concat
|
||||
, "-1200K"
|
||||
, "-,0012G"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "5 tausend"
|
||||
, "fünf tausend"
|
||||
]
|
||||
, examples (NumberValue 200000)
|
||||
, examples (NumeralValue 200000)
|
||||
[ "zwei hundert tausend"
|
||||
]
|
||||
, examples (NumberValue 721012)
|
||||
, examples (NumeralValue 721012)
|
||||
[ "sieben hundert einundzwanzig tausend zwölf"
|
||||
]
|
||||
, examples (NumberValue 31256721)
|
||||
, examples (NumeralValue 31256721)
|
||||
[ "ein und dreissig millionen zwei hundert sechs und fünfzig tausend sieben hundert ein und zwanzig"
|
||||
]
|
||||
, examples (NumberValue 1416.15)
|
||||
, examples (NumeralValue 1416.15)
|
||||
[ "1416,15"
|
||||
]
|
||||
, examples (NumberValue 1416.15)
|
||||
, examples (NumeralValue 1416.15)
|
||||
[ "1.416,15"
|
||||
]
|
||||
, examples (NumberValue 1000000.0)
|
||||
, examples (NumeralValue 1000000.0)
|
||||
[ "1.000.000,00"
|
||||
]
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.DE.Rules
|
||||
module Duckling.Numeral.DE.Rules
|
||||
( rules ) where
|
||||
|
||||
import Control.Monad (join)
|
||||
@ -22,21 +22,22 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|minus|negativ"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v * (- 1)
|
||||
(_:Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
double $ v * (- 1)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -86,8 +87,8 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*,\\d+)"
|
||||
@ -131,8 +132,8 @@ ruleInteger3 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersUnd :: Rule
|
||||
ruleNumbersUnd = Rule
|
||||
ruleNumeralsUnd :: Rule
|
||||
ruleNumeralsUnd = Rule
|
||||
{ name = "numbers und"
|
||||
, pattern =
|
||||
[ numberBetween 1 10
|
||||
@ -140,9 +141,9 @@ ruleNumbersUnd = Rule
|
||||
, oneOf [20, 30 .. 90]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -152,7 +153,7 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
@ -163,25 +164,25 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -336,18 +337,18 @@ ruleInteger2 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "komma"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + decimalsToDouble v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -367,7 +368,7 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleCouple
|
||||
, ruleDecimalNumber
|
||||
, ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleDozen
|
||||
, ruleFew
|
||||
@ -378,10 +379,10 @@ rules =
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleIntersect
|
||||
, ruleMultiply
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumbersUnd
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
, ruleNumeralsUnd
|
||||
, rulePowersOfTen
|
||||
, ruleTen
|
||||
, ruleToNineteen
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.DE.Tests
|
||||
module Duckling.Numeral.DE.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.DE.Corpus
|
||||
import Duckling.Numeral.DE.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,13 +8,13 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.EN.Corpus
|
||||
module Duckling.Numeral.EN.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Testing.Types
|
||||
|
||||
corpus :: Corpus
|
||||
@ -22,80 +22,80 @@ corpus = (testContext, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "naught"
|
||||
, "nought"
|
||||
, "zero"
|
||||
, "nil"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "one"
|
||||
, "single"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "two"
|
||||
, "a pair"
|
||||
, "a couple"
|
||||
, "a couple of"
|
||||
]
|
||||
, examples (NumberValue 3)
|
||||
, examples (NumeralValue 3)
|
||||
[ "3"
|
||||
, "three"
|
||||
, "a few"
|
||||
, "few"
|
||||
]
|
||||
, examples (NumberValue 10)
|
||||
, examples (NumeralValue 10)
|
||||
[ "10"
|
||||
, "ten"
|
||||
]
|
||||
, examples (NumberValue 12)
|
||||
, examples (NumeralValue 12)
|
||||
[ "12"
|
||||
, "twelve"
|
||||
, "a dozen"
|
||||
, "a dozen of"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "fourteen"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "sixteen"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "seventeen"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "eighteen"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "thirty three"
|
||||
, "0033"
|
||||
]
|
||||
, examples (NumberValue 24)
|
||||
, examples (NumeralValue 24)
|
||||
[ "24"
|
||||
, "2 dozens"
|
||||
, "two dozen"
|
||||
, "Two dozen"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1.1"
|
||||
, "1.10"
|
||||
, "01.10"
|
||||
, "1 point 1"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ ".77"
|
||||
, "0.77"
|
||||
, "point 77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100,000"
|
||||
, "100,000.0"
|
||||
, "100000"
|
||||
@ -103,25 +103,25 @@ allExamples = concat
|
||||
, "100k"
|
||||
, "one hundred thousand"
|
||||
]
|
||||
, examples (NumberValue 3e6)
|
||||
, examples (NumeralValue 3e6)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3,000,000"
|
||||
, "3 million"
|
||||
]
|
||||
, examples (NumberValue 1.2e6)
|
||||
, examples (NumeralValue 1.2e6)
|
||||
[ "1,200,000"
|
||||
, "1200000"
|
||||
, "1.2M"
|
||||
, "1200k"
|
||||
, ".0012G"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "5 thousand"
|
||||
, "five thousand"
|
||||
]
|
||||
, examples (NumberValue (-1.2e6))
|
||||
, examples (NumeralValue (-1.2e6))
|
||||
[ "- 1,200,000"
|
||||
, "-1200000"
|
||||
, "minus 1,200,000"
|
||||
@ -130,28 +130,28 @@ allExamples = concat
|
||||
, "-1200K"
|
||||
, "-.0012G"
|
||||
]
|
||||
, examples (NumberValue 122)
|
||||
, examples (NumeralValue 122)
|
||||
[ "one twenty two"
|
||||
, "ONE TwentY tWO"
|
||||
]
|
||||
, examples (NumberValue 2e5)
|
||||
, examples (NumeralValue 2e5)
|
||||
[ "two Hundred thousand"
|
||||
]
|
||||
, examples (NumberValue 21011)
|
||||
, examples (NumeralValue 21011)
|
||||
[ "twenty-one thousand Eleven"
|
||||
]
|
||||
, examples (NumberValue 721012)
|
||||
, examples (NumeralValue 721012)
|
||||
[ "seven hundred twenty-one thousand twelve"
|
||||
, "seven hundred twenty-one thousand and twelve"
|
||||
]
|
||||
, examples (NumberValue 31256721)
|
||||
, examples (NumeralValue 31256721)
|
||||
[ "thirty-one million two hundred fifty-six thousand seven hundred twenty-one"
|
||||
]
|
||||
, examples (NumberValue 2400)
|
||||
, examples (NumeralValue 2400)
|
||||
[ "two hundred dozens"
|
||||
, "200 dozens"
|
||||
]
|
||||
, examples (NumberValue 2200000)
|
||||
, examples (NumeralValue 2200000)
|
||||
[ "two point two million"
|
||||
]
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.EN.Rules
|
||||
module Duckling.Numeral.EN.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.HashMap.Strict (HashMap)
|
||||
@ -21,9 +21,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -145,8 +145,8 @@ ruleCompositeTens = Rule
|
||||
{ name = "integer 21..99"
|
||||
, pattern = [oneOf [20,30..90], numberBetween 1 10]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData { TNumber.value = tens }) :
|
||||
Token Numeral (NumberData { TNumber.value = units }) :
|
||||
(Token Numeral (NumeralData { TNumeral.value = tens }) :
|
||||
Token Numeral (NumeralData { TNumeral.value = units }) :
|
||||
_) -> double (tens + units)
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -156,8 +156,8 @@ ruleSkipHundreds = Rule
|
||||
{ name = "one twenty two"
|
||||
, pattern = [numberBetween 1 10, numberBetween 10 100]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData { TNumber.value = hundreds }) :
|
||||
Token Numeral (NumberData { TNumber.value = rest }) :
|
||||
(Token Numeral (NumeralData { TNumeral.value = hundreds }) :
|
||||
Token Numeral (NumeralData { TNumeral.value = rest }) :
|
||||
_) -> double (hundreds*100 + rest)
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -168,11 +168,11 @@ ruleDotSpelledOut = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "point|dot"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
double $ TNumber.value nd1 + decimalsToDouble (TNumber.value nd2)
|
||||
double $ TNumeral.value nd1 + decimalsToDouble (TNumeral.value nd2)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -181,10 +181,10 @@ ruleLeadingDotSpelledOut = Rule
|
||||
{ name = "point 77"
|
||||
, pattern =
|
||||
[ regex "point|dot"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double . decimalsToDouble $ TNumber.value nd
|
||||
(_:Token Numeral nd:_) -> double . decimalsToDouble $ TNumeral.value nd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ ruleSuffixes = Rule
|
||||
"m" -> Just 1e6
|
||||
"g" -> Just 1e9
|
||||
_ -> Nothing
|
||||
double $ TNumber.value nd * x
|
||||
double $ TNumeral.value nd * x
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -234,7 +234,7 @@ ruleNegative = Rule
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -242,13 +242,13 @@ ruleSum :: Rule
|
||||
ruleSum = Rule
|
||||
{ name = "intersect 2 numbers"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
, numberWith TNumber.multipliable not
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens ->
|
||||
case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -257,15 +257,15 @@ ruleSumAnd :: Rule
|
||||
ruleSumAnd = Rule
|
||||
{ name = "intersect 2 numbers (with and)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, regex "and"
|
||||
, numberWith TNumber.multipliable not
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens ->
|
||||
case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -275,7 +275,7 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
@ -8,7 +8,7 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.EN.Tests
|
||||
module Duckling.Numeral.EN.Tests
|
||||
( tests
|
||||
) where
|
||||
|
||||
@ -18,8 +18,8 @@ import Test.Tasty
|
||||
import Test.Tasty.HUnit
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.EN.Corpus
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.EN.Corpus
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Testing.Asserts
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -34,14 +34,14 @@ surroundTests = testCase "Surround Tests" $
|
||||
mapM_ (analyzedFirstTest testContext . withTargets [This Numeral]) xs
|
||||
where
|
||||
xs = concat
|
||||
[ examples (NumberValue 3)
|
||||
[ examples (NumeralValue 3)
|
||||
[ "3km"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100k€"
|
||||
, "100k\x20ac"
|
||||
]
|
||||
, examples (NumberValue 10.99)
|
||||
, examples (NumeralValue 10.99)
|
||||
[ "10.99$"
|
||||
]
|
||||
]
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.ES.Corpus
|
||||
module Duckling.Numeral.ES.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,77 +24,77 @@ corpus = (testContext {lang = ES}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 1)
|
||||
[ examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "uno"
|
||||
, "una"
|
||||
]
|
||||
, examples (NumberValue 11)
|
||||
, examples (NumeralValue 11)
|
||||
[ "once"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "dieciséis"
|
||||
, "dieciseis"
|
||||
, "Diesiseis"
|
||||
, "diez y seis"
|
||||
]
|
||||
, examples (NumberValue 21)
|
||||
, examples (NumeralValue 21)
|
||||
[ "veintiuno"
|
||||
, "veinte y uno"
|
||||
]
|
||||
, examples (NumberValue 23)
|
||||
, examples (NumeralValue 23)
|
||||
[ "veintitrés"
|
||||
, "veinte y tres"
|
||||
]
|
||||
, examples (NumberValue 70)
|
||||
, examples (NumeralValue 70)
|
||||
[ "setenta"
|
||||
]
|
||||
, examples (NumberValue 78)
|
||||
, examples (NumeralValue 78)
|
||||
[ "Setenta y ocho"
|
||||
]
|
||||
, examples (NumberValue 80)
|
||||
, examples (NumeralValue 80)
|
||||
[ "ochenta"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "treinta y tres"
|
||||
, "treinta y 3"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1,1"
|
||||
, "1,10"
|
||||
, "01,10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0,77"
|
||||
, ",77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100.000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
]
|
||||
, examples (NumberValue 300)
|
||||
, examples (NumeralValue 300)
|
||||
[ "trescientos"
|
||||
]
|
||||
, examples (NumberValue 243)
|
||||
, examples (NumeralValue 243)
|
||||
[ "243"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3.000.000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1.200.000"
|
||||
, "1200000"
|
||||
, "1,2M"
|
||||
, "1200K"
|
||||
, ",0012G"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1.200.000"
|
||||
, "-1200000"
|
||||
, "menos 1.200.000"
|
||||
@ -102,7 +102,7 @@ allExamples = concat
|
||||
, "-1200K"
|
||||
, "-,0012G"
|
||||
]
|
||||
, examples (NumberValue 1.5)
|
||||
, examples (NumeralValue 1.5)
|
||||
[ "1 punto cinco"
|
||||
, "una punto cinco"
|
||||
, "1,5"
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.ES.Rules
|
||||
module Duckling.Numeral.ES.Rules
|
||||
( rules ) where
|
||||
|
||||
import qualified Data.HashMap.Strict as HashMap
|
||||
@ -19,21 +19,22 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|menos"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v * (- 1)
|
||||
(_:Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
double $ v * (- 1)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -57,16 +58,16 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
[ regex "(\\d+(\\.\\d\\d\\d)+,\\d+)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> let dot = Text.singleton '.'
|
||||
comma = Text.singleton ','
|
||||
fmt = Text.replace comma dot $ Text.replace dot Text.empty match
|
||||
(Token RegexMatch (GroupMatch (match:_)):_) ->
|
||||
let dot = Text.singleton '.'
|
||||
comma = Text.singleton ','
|
||||
fmt = Text.replace comma dot $ Text.replace dot Text.empty match
|
||||
in parseDouble fmt >>= double
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*,\\d+)"
|
||||
@ -89,8 +90,8 @@ byTensMap = HashMap.fromList
|
||||
, ( "noventa" , 90 )
|
||||
]
|
||||
|
||||
ruleNumber2 :: Rule
|
||||
ruleNumber2 = Rule
|
||||
ruleNumeral2 :: Rule
|
||||
ruleNumeral2 = Rule
|
||||
{ name = "number (20..90)"
|
||||
, pattern =
|
||||
[ regex "(veinte|treinta|cuarenta|cincuenta|sesenta|setenta|ochenta|noventa)"
|
||||
@ -127,8 +128,8 @@ zeroToFifteenMap = HashMap.fromList
|
||||
, ( "quince" , 15 )
|
||||
]
|
||||
|
||||
ruleNumber :: Rule
|
||||
ruleNumber = Rule
|
||||
ruleNumeral :: Rule
|
||||
ruleNumeral = Rule
|
||||
{ name = "number (0..15)"
|
||||
, pattern =
|
||||
[ regex "((c|z)ero|un(o|a)?|dos|tr(\x00e9|e)s|cuatro|cinco|s(e|\x00e9)is|siete|ocho|nueve|die(z|s)|once|doce|trece|catorce|quince)"
|
||||
@ -162,8 +163,8 @@ sixteenToTwentyNineMap = HashMap.fromList
|
||||
, ( "veintinueve" , 29 )
|
||||
]
|
||||
|
||||
ruleNumber5 :: Rule
|
||||
ruleNumber5 = Rule
|
||||
ruleNumeral5 :: Rule
|
||||
ruleNumeral5 = Rule
|
||||
{ name = "number (16..19 21..29)"
|
||||
, pattern =
|
||||
[ regex "(die(c|s)is(\x00e9|e)is|diecisiete|dieciocho|diecinueve|veintiun(o|a)|veintidos|veintitr(\x00e9|e)s|veinticuatro|veinticinco|veintis(\x00e9|e)is|veintisiete|veintiocho|veintinueve)"
|
||||
@ -174,28 +175,29 @@ ruleNumber5 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber3 :: Rule
|
||||
ruleNumber3 = Rule
|
||||
ruleNumeral3 :: Rule
|
||||
ruleNumeral3 = Rule
|
||||
{ name = "number (16..19)"
|
||||
, pattern =
|
||||
[ numberWith TNumber.value (== 10)
|
||||
[ numberWith TNumeral.value (== 10)
|
||||
, regex "y"
|
||||
, numberBetween 6 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:_:Token Numeral (NumberData {TNumber.value = v}):_) -> double $ 10 + v
|
||||
(_:_:Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
double $ 10 + v
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -222,8 +224,8 @@ oneHundredToThousandMap = HashMap.fromList
|
||||
]
|
||||
|
||||
|
||||
ruleNumber6 :: Rule
|
||||
ruleNumber6 = Rule
|
||||
ruleNumeral6 :: Rule
|
||||
ruleNumeral6 = Rule
|
||||
{ name = "number 100..1000 "
|
||||
, pattern =
|
||||
[ regex "(cien(to)?s?|doscientos|trescientos|cuatrocientos|quinientos|seiscientos|setecientos|ochocientos|novecientos|mil)"
|
||||
@ -234,8 +236,8 @@ ruleNumber6 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber4 :: Rule
|
||||
ruleNumber4 = Rule
|
||||
ruleNumeral4 :: Rule
|
||||
ruleNumeral4 = Rule
|
||||
{ name = "number (21..29 31..39 41..49 51..59 61..69 71..79 81..89 91..99)"
|
||||
, pattern =
|
||||
[ oneOf [70, 20, 60, 50, 40, 90, 30, 80]
|
||||
@ -243,39 +245,41 @@ ruleNumber4 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):_:Token Numeral (NumberData {TNumber.value = v2}):_) ->
|
||||
double $ v1 + v2
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbers :: Rule
|
||||
ruleNumbers = Rule
|
||||
ruleNumerals :: Rule
|
||||
ruleNumerals = Rule
|
||||
{ name = "numbers 200..999"
|
||||
, pattern =
|
||||
[ numberBetween 2 10
|
||||
, numberWith TNumber.value (== 100)
|
||||
, numberWith TNumeral.value (== 100)
|
||||
, numberBetween 0 100
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ 100 * v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "punto"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + decimalsToDouble v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -294,18 +298,18 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDecimalNumber
|
||||
[ ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleIntegerNumeric
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleNumber
|
||||
, ruleNumber2
|
||||
, ruleNumber3
|
||||
, ruleNumber4
|
||||
, ruleNumber5
|
||||
, ruleNumber6
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumbers
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeral
|
||||
, ruleNumeral2
|
||||
, ruleNumeral3
|
||||
, ruleNumeral4
|
||||
, ruleNumeral5
|
||||
, ruleNumeral6
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumerals
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.ES.Tests
|
||||
module Duckling.Numeral.ES.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.ES.Corpus
|
||||
import Duckling.Numeral.ES.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.ET.Corpus
|
||||
module Duckling.Numeral.ET.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,58 +24,58 @@ corpus = (testContext {lang = ET}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "null"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "üks"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "Kolmkümmend kolm"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "neliteist"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "kuusteist"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "Seitseteist"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "kaheksateist"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1.1"
|
||||
, "1.10"
|
||||
, "01.10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0.77"
|
||||
, ".77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100,000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
, "100 000"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3,000,000"
|
||||
, "3 000 000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1,200,000"
|
||||
, "1200000"
|
||||
, "1.2M"
|
||||
@ -83,7 +83,7 @@ allExamples = concat
|
||||
, ".0012G"
|
||||
, "1 200 000"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1,200,000"
|
||||
, "-1200000"
|
||||
, "miinus 1,200,000"
|
||||
@ -91,19 +91,19 @@ allExamples = concat
|
||||
, "-1200K"
|
||||
, "-.0012G"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "viis tuhat"
|
||||
]
|
||||
, examples (NumberValue 200000)
|
||||
, examples (NumeralValue 200000)
|
||||
[ "kakssada tuhat"
|
||||
]
|
||||
, examples (NumberValue 21011)
|
||||
, examples (NumeralValue 21011)
|
||||
[ "kakskümmend üks Tuhat üksteist"
|
||||
]
|
||||
, examples (NumberValue 721012)
|
||||
, examples (NumeralValue 721012)
|
||||
[ "seitsesada kakskümmend üks tuhat kaksteist"
|
||||
]
|
||||
, examples (NumberValue 31256721)
|
||||
, examples (NumeralValue 31256721)
|
||||
[ "kolmkümmend üks miljonit kakssada viiskümmend kuus tuhat seitsesada kakskümmend üks"
|
||||
]
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.ET.Rules
|
||||
module Duckling.Numeral.ET.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.Maybe
|
||||
@ -18,9 +18,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -36,8 +36,8 @@ ruleIntegerWithThousandsSeparatorSpace = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|miinus|negatiivne"
|
||||
@ -45,7 +45,7 @@ ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:
|
||||
Token Numeral (NumberData {TNumber.value = v}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
_) -> double $ v * (-1)
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -94,8 +94,8 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*\\.\\d+)"
|
||||
@ -113,8 +113,8 @@ ruleInteger3 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):_) -> double $ v1 + v2
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -143,25 +143,25 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
, numberWith TNumber.multipliable not
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -176,7 +176,7 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
@ -255,18 +255,18 @@ ruleInteger2 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "dot|point"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + decimalsToDouble v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -287,7 +287,7 @@ rules :: [Rule]
|
||||
rules =
|
||||
[ ruleACoupleOf
|
||||
, ruleAFew
|
||||
, ruleDecimalNumber
|
||||
, ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleInteger
|
||||
, ruleInteger2
|
||||
@ -298,9 +298,9 @@ rules =
|
||||
, ruleIntegerWithThousandsSeparatorSpace
|
||||
, ruleIntersect
|
||||
, ruleMultiply
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
, rulePowersOfTen
|
||||
, ruleTen
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.ET.Tests
|
||||
module Duckling.Numeral.ET.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.ET.Corpus
|
||||
import Duckling.Numeral.ET.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.FR.Corpus
|
||||
module Duckling.Numeral.FR.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,91 +24,91 @@ corpus = (testContext {lang = FR}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "zero"
|
||||
, "zéro"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "un"
|
||||
, "une"
|
||||
]
|
||||
, examples (NumberValue 11)
|
||||
, examples (NumeralValue 11)
|
||||
[ "onze"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "dix sept"
|
||||
, "dix-sept"
|
||||
]
|
||||
, examples (NumberValue 21)
|
||||
, examples (NumeralValue 21)
|
||||
[ "vingt et un"
|
||||
, "vingt-et-un"
|
||||
]
|
||||
, examples (NumberValue 23)
|
||||
, examples (NumeralValue 23)
|
||||
[ "vingt trois"
|
||||
, "vingt-trois"
|
||||
]
|
||||
, examples (NumberValue 70)
|
||||
, examples (NumeralValue 70)
|
||||
[ "soixante dix"
|
||||
]
|
||||
, examples (NumberValue 71)
|
||||
, examples (NumeralValue 71)
|
||||
[ "soixante onze"
|
||||
]
|
||||
, examples (NumberValue 78)
|
||||
, examples (NumeralValue 78)
|
||||
[ "soixante dix huit"
|
||||
]
|
||||
, examples (NumberValue 73)
|
||||
, examples (NumeralValue 73)
|
||||
[ "soixante treize"
|
||||
]
|
||||
, examples (NumberValue 80)
|
||||
, examples (NumeralValue 80)
|
||||
[ "quatre vingt"
|
||||
]
|
||||
, examples (NumberValue 81)
|
||||
, examples (NumeralValue 81)
|
||||
[ "quatre vingt un"
|
||||
]
|
||||
, examples (NumberValue 82)
|
||||
, examples (NumeralValue 82)
|
||||
[ "quatre vingt deux"
|
||||
]
|
||||
, examples (NumberValue 90)
|
||||
, examples (NumeralValue 90)
|
||||
[ "quatre vingt dix"
|
||||
]
|
||||
, examples (NumberValue 91)
|
||||
, examples (NumeralValue 91)
|
||||
[ "quatre vingt onze"
|
||||
]
|
||||
, examples (NumberValue 92)
|
||||
, examples (NumeralValue 92)
|
||||
[ "quatre vingt douze"
|
||||
]
|
||||
, examples (NumberValue 99)
|
||||
, examples (NumeralValue 99)
|
||||
[ "quatre vingt dix neuf"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "trente trois"
|
||||
, "trente-trois"
|
||||
, "trente 3"
|
||||
]
|
||||
, examples (NumberValue 118)
|
||||
, examples (NumeralValue 118)
|
||||
[ "cent dix-huit"
|
||||
]
|
||||
, examples (NumberValue 4020)
|
||||
, examples (NumeralValue 4020)
|
||||
[ "quatre mille vingt"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100.000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
, "cent mille"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3.000.000"
|
||||
, "trois millions"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1.200.000"
|
||||
, "1200000"
|
||||
, "1,2M"
|
||||
@ -116,7 +116,7 @@ allExamples = concat
|
||||
, ",0012G"
|
||||
, "un million deux cent mille"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1.200.000"
|
||||
, "-1200000"
|
||||
, "moins 1200000"
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.FR.Rules
|
||||
module Duckling.Numeral.FR.Rules
|
||||
( rules ) where
|
||||
|
||||
import qualified Data.Text as Text
|
||||
@ -18,24 +18,24 @@ import Data.Maybe
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
ruleNumbers4 :: Rule
|
||||
ruleNumbers4 = Rule
|
||||
ruleNumerals4 :: Rule
|
||||
ruleNumerals4 = Rule
|
||||
{ name = "numbers 81"
|
||||
, pattern =
|
||||
[ numberWith TNumber.value (== 80)
|
||||
, numberWith TNumber.value (== 1)
|
||||
[ numberWith TNumeral.value (== 80)
|
||||
, numberWith TNumeral.value (== 1)
|
||||
]
|
||||
, prod = \_ -> integer 81
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|moins"
|
||||
@ -43,7 +43,7 @@ ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:
|
||||
Token Numeral (NumberData {TNumber.value = v}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
_) -> double $ v * (-1)
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -62,16 +62,16 @@ ruleIntegerNumeric = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbers2 :: Rule
|
||||
ruleNumbers2 = Rule
|
||||
ruleNumerals2 :: Rule
|
||||
ruleNumerals2 = Rule
|
||||
{ name = "numbers 22..29 32..39 .. 52..59"
|
||||
, pattern =
|
||||
[ oneOf [20, 50, 40, 30]
|
||||
, numberBetween 2 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -83,16 +83,16 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
[ regex "(\\d+(\\.\\d\\d\\d)+,\\d+)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> let dot = Text.singleton '.'
|
||||
comma = Text.singleton ','
|
||||
fmt = Text.replace comma dot $ Text.replace dot Text.empty match
|
||||
(Token RegexMatch (GroupMatch (match:_)):_) ->
|
||||
let dot = Text.singleton '.'
|
||||
comma = Text.singleton ','
|
||||
fmt = Text.replace comma dot $ Text.replace dot Text.empty match
|
||||
in parseDouble fmt >>= double
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*,\\d+)"
|
||||
@ -103,8 +103,8 @@ ruleDecimalNumber = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber2 :: Rule
|
||||
ruleNumber2 = Rule
|
||||
ruleNumeral2 :: Rule
|
||||
ruleNumeral2 = Rule
|
||||
{ name = "number (20..60)"
|
||||
, pattern =
|
||||
[ regex "(vingt|trente|quarante|cinquante|soixante)"
|
||||
@ -118,22 +118,22 @@ ruleNumber2 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbers5 :: Rule
|
||||
ruleNumbers5 = Rule
|
||||
ruleNumerals5 :: Rule
|
||||
ruleNumerals5 = Rule
|
||||
{ name = "numbers 62..69 .. 92..99"
|
||||
, pattern =
|
||||
[ oneOf [60, 80]
|
||||
, numberBetween 2 20
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber :: Rule
|
||||
ruleNumber = Rule
|
||||
ruleNumeral :: Rule
|
||||
ruleNumeral = Rule
|
||||
{ name = "number (0..16)"
|
||||
, pattern =
|
||||
[ regex "(z(e|\x00e9)ro|une?|deux|trois|quatre|cinq|six|sept|huit|neuf|dix|onze|douze|treize|quatorze|quinze|seize)"
|
||||
@ -161,45 +161,45 @@ ruleNumber = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber3 :: Rule
|
||||
ruleNumber3 = Rule
|
||||
ruleNumeral3 :: Rule
|
||||
ruleNumeral3 = Rule
|
||||
{ name = "number (17..19)"
|
||||
, pattern =
|
||||
[ numberWith TNumber.value (== 10)
|
||||
[ numberWith TNumeral.value (== 10)
|
||||
, numberBetween 7 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:
|
||||
Token Numeral (NumberData {TNumber.value = v}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
_) -> double $ 10 + v
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbers3 :: Rule
|
||||
ruleNumbers3 = Rule
|
||||
ruleNumerals3 :: Rule
|
||||
ruleNumerals3 = Rule
|
||||
{ name = "numbers 61 71"
|
||||
, pattern =
|
||||
[ numberWith TNumber.value (== 60)
|
||||
[ numberWith TNumeral.value (== 60)
|
||||
, regex "-?et-?"
|
||||
, oneOf [1, 11]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W$\x20ac\x00a2\x00a3]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -209,8 +209,8 @@ ruleNumbersSuffixesKMG = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber4 :: Rule
|
||||
ruleNumber4 = Rule
|
||||
ruleNumeral4 :: Rule
|
||||
ruleNumeral4 = Rule
|
||||
{ name = "number 80"
|
||||
, pattern =
|
||||
[ regex "quatre"
|
||||
@ -219,18 +219,18 @@ ruleNumber4 = Rule
|
||||
, prod = \_ -> integer 80
|
||||
}
|
||||
|
||||
ruleNumbers :: Rule
|
||||
ruleNumbers = Rule
|
||||
ruleNumerals :: Rule
|
||||
ruleNumerals = Rule
|
||||
{ name = "numbers 21 31 41 51"
|
||||
, pattern =
|
||||
[ oneOf [20, 50, 40, 30]
|
||||
, regex "et"
|
||||
, numberWith TNumber.value (== 1)
|
||||
, numberWith TNumeral.value (== 1)
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -270,12 +270,12 @@ ruleSum :: Rule
|
||||
ruleSum = Rule
|
||||
{ name = "intersect 2 numbers"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
, numberWith TNumber.multipliable not
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -285,7 +285,7 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
@ -294,21 +294,21 @@ ruleMultiply = Rule
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDecimalNumber
|
||||
[ ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleIntegerNumeric
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleNumber
|
||||
, ruleNumber2
|
||||
, ruleNumber3
|
||||
, ruleNumber4
|
||||
, ruleNumbers
|
||||
, ruleNumbers2
|
||||
, ruleNumbers3
|
||||
, ruleNumbers4
|
||||
, ruleNumbers5
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeral
|
||||
, ruleNumeral2
|
||||
, ruleNumeral3
|
||||
, ruleNumeral4
|
||||
, ruleNumerals
|
||||
, ruleNumerals2
|
||||
, ruleNumerals3
|
||||
, ruleNumerals4
|
||||
, ruleNumerals5
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
, rulePowersOfTen
|
||||
, ruleSum
|
||||
, ruleMultiply
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.FR.Tests
|
||||
module Duckling.Numeral.FR.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.FR.Corpus
|
||||
import Duckling.Numeral.FR.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.GA.Corpus
|
||||
module Duckling.Numeral.GA.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,17 +24,17 @@ corpus = (testContext {lang = GA}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "a náid"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "aon"
|
||||
, "a haon"
|
||||
, "Amháin"
|
||||
]
|
||||
, examples (NumberValue 20)
|
||||
, examples (NumeralValue 20)
|
||||
[ "20"
|
||||
, "Fiche"
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.GA.Rules
|
||||
module Duckling.Numeral.GA.Rules
|
||||
( rules ) where
|
||||
|
||||
import qualified Data.Text as Text
|
||||
@ -17,14 +17,14 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|m(\x00ed|i)neas(\\sa)?\\s?"
|
||||
@ -32,7 +32,7 @@ ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:
|
||||
Token Numeral (NumberData {TNumber.value = v}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
_) -> double $ v * (-1)
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -50,8 +50,8 @@ ruleIntegerNumeric = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbers2 :: Rule
|
||||
ruleNumbers2 = Rule
|
||||
ruleNumerals2 :: Rule
|
||||
ruleNumerals2 = Rule
|
||||
{ name = "numbers, 1-10"
|
||||
, pattern =
|
||||
[ regex "(aon|dh(\x00e1|a)|tr(\x00ed|i)|ceithre|c(\x00fa|u)ig|seacht|s(\x00e9|e)|ocht|naoi|deich)"
|
||||
@ -88,8 +88,8 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*\\.\\d+)"
|
||||
@ -108,15 +108,15 @@ ruleDag = Rule
|
||||
, prod = \_ -> integer 10
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -126,8 +126,8 @@ ruleNumbersSuffixesKMG = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleOldVigesimalNumbersS :: Rule
|
||||
ruleOldVigesimalNumbersS = Rule
|
||||
ruleOldVigesimalNumeralsS :: Rule
|
||||
ruleOldVigesimalNumeralsS = Rule
|
||||
{ name = "old vigesimal numbers, 20s"
|
||||
, pattern =
|
||||
[ regex "is (dh?(\x00e1|a) fhichead|tr(\x00ed|i) fichid|ceithre fichid)"
|
||||
@ -145,8 +145,8 @@ ruleOldVigesimalNumbersS = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleOldVigesimalNumbersS2 :: Rule
|
||||
ruleOldVigesimalNumbersS2 = Rule
|
||||
ruleOldVigesimalNumeralsS2 :: Rule
|
||||
ruleOldVigesimalNumeralsS2 = Rule
|
||||
{ name = "old vigesimal numbers, 20s + 10"
|
||||
, pattern =
|
||||
[ regex "d(\x00e9|e)ag is (fiche|dh?(\x00e1|a) fhichead|tr(\x00ed|i) fichid|ceithre fichid)"
|
||||
@ -174,8 +174,8 @@ ruleAmhin = Rule
|
||||
, prod = \_ -> integer 1
|
||||
}
|
||||
|
||||
ruleNumbers :: Rule
|
||||
ruleNumbers = Rule
|
||||
ruleNumerals :: Rule
|
||||
ruleNumerals = Rule
|
||||
{ name = "numbers, 20-90"
|
||||
, pattern =
|
||||
[ regex "(fiche|tr(\x00ed|i)ocha|daichead|caoga|seasca|seacht(\x00f3|o)|ocht(\x00f3|o)|n(\x00f3|o)cha)"
|
||||
@ -210,8 +210,8 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleCountNumbers :: Rule
|
||||
ruleCountNumbers = Rule
|
||||
ruleCountNumerals :: Rule
|
||||
ruleCountNumerals = Rule
|
||||
{ name = "count numbers"
|
||||
, pattern =
|
||||
[ regex "a (n(\x00e1|a)id|haon|d(\x00f3|o)|tr(\x00ed|i)|ceathair|c(\x00fa|u)ig|s(\x00e9|e)|seacht|hocht|naoi|deich)"
|
||||
@ -241,16 +241,16 @@ ruleCountNumbers = Rule
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleAmhin
|
||||
, ruleCountNumbers
|
||||
, ruleCountNumerals
|
||||
, ruleDag
|
||||
, ruleDecimalNumber
|
||||
, ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleIntegerNumeric
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleNumbers
|
||||
, ruleNumbers2
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleOldVigesimalNumbersS
|
||||
, ruleOldVigesimalNumbersS2
|
||||
, ruleNumerals
|
||||
, ruleNumerals2
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
, ruleOldVigesimalNumeralsS
|
||||
, ruleOldVigesimalNumeralsS2
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.GA.Tests
|
||||
module Duckling.Numeral.GA.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.GA.Corpus
|
||||
import Duckling.Numeral.GA.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.Helpers
|
||||
module Duckling.Numeral.Helpers
|
||||
( decimalsToDouble
|
||||
, double
|
||||
, integer
|
||||
@ -31,9 +31,9 @@ import qualified Data.Text as Text
|
||||
import Prelude
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Types hiding (value)
|
||||
|
||||
zeroT :: Text
|
||||
zeroT = Text.singleton '0'
|
||||
|
||||
@ -69,43 +69,43 @@ decimalsToDouble x =
|
||||
-- -----------------------------------------------------------------
|
||||
-- Patterns
|
||||
|
||||
numberWith :: (NumberData -> t) -> (t -> Bool) -> PatternItem
|
||||
numberWith :: (NumeralData -> t) -> (t -> Bool) -> PatternItem
|
||||
numberWith f pred = Predicate $ \x ->
|
||||
case x of
|
||||
(Token Numeral x@NumberData{}) -> pred (f x)
|
||||
(Token Numeral x@NumeralData{}) -> pred (f x)
|
||||
_ -> False
|
||||
|
||||
numberBetween :: Double -> Double -> PatternItem
|
||||
numberBetween low up = Predicate $ \x ->
|
||||
case x of
|
||||
(Token Numeral NumberData {TNumber.value = v, TNumber.multipliable = False}) ->
|
||||
(Token Numeral NumeralData {value = v, multipliable = False}) ->
|
||||
low <= v && v < up
|
||||
_ -> False
|
||||
|
||||
oneOf :: [Double] -> PatternItem
|
||||
oneOf vs = Predicate $ \x ->
|
||||
case x of
|
||||
(Token Numeral NumberData {TNumber.value = v}) -> elem v vs
|
||||
(Token Numeral NumeralData {value = v}) -> elem v vs
|
||||
_ -> False
|
||||
|
||||
-- -----------------------------------------------------------------
|
||||
-- Production
|
||||
|
||||
withMultipliable :: Token -> Maybe Token
|
||||
withMultipliable (Token Numeral x@NumberData{}) =
|
||||
Just . Token Numeral $ x {TNumber.multipliable = True}
|
||||
withMultipliable (Token Numeral x@NumeralData{}) =
|
||||
Just . Token Numeral $ x {multipliable = True}
|
||||
withMultipliable _ = Nothing
|
||||
|
||||
withGrain :: Int -> Token -> Maybe Token
|
||||
withGrain g (Token Numeral x@NumberData{}) =
|
||||
Just . Token Numeral $ x {TNumber.grain = Just g}
|
||||
withGrain g (Token Numeral x@NumeralData{}) =
|
||||
Just . Token Numeral $ x {grain = Just g}
|
||||
withGrain _ _ = Nothing
|
||||
|
||||
double :: Double -> Maybe Token
|
||||
double x = Just . Token Numeral $ NumberData
|
||||
{ TNumber.value = x
|
||||
, TNumber.grain = Nothing
|
||||
, TNumber.multipliable = False
|
||||
double x = Just . Token Numeral $ NumeralData
|
||||
{ value = x
|
||||
, grain = Nothing
|
||||
, multipliable = False
|
||||
}
|
||||
|
||||
integer :: Integer -> Maybe Token
|
||||
@ -113,8 +113,8 @@ integer = double . fromIntegral
|
||||
|
||||
multiply :: Token -> Token -> Maybe Token
|
||||
multiply
|
||||
(Token Numeral (NumberData {TNumber.value = v1}))
|
||||
(Token Numeral (NumberData {TNumber.value = v2, TNumber.grain = g})) = case g of
|
||||
(Token Numeral (NumeralData {value = v1}))
|
||||
(Token Numeral (NumeralData {value = v2, grain = g})) = case g of
|
||||
Nothing -> double $ v1 * v2
|
||||
Just grain | v2 > v1 -> double (v1 * v2) >>= withGrain grain
|
||||
| otherwise -> Nothing
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.ID.Corpus
|
||||
module Duckling.Numeral.ID.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,69 +24,69 @@ corpus = (testContext {lang = ID}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "nol"
|
||||
, "kosong"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "satu"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "Dua"
|
||||
]
|
||||
, examples (NumberValue 10)
|
||||
, examples (NumeralValue 10)
|
||||
[ "10"
|
||||
, "sepuluh"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "tiga puluh tiga"
|
||||
, "0033"
|
||||
]
|
||||
, examples (NumberValue 100)
|
||||
, examples (NumeralValue 100)
|
||||
[ "100"
|
||||
, "seratus"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "tujuh belas"
|
||||
]
|
||||
, examples (NumberValue 28)
|
||||
, examples (NumeralValue 28)
|
||||
[ "28"
|
||||
, "dua puluh delapan"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1,1"
|
||||
, "1,10"
|
||||
, "01,10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0,77"
|
||||
, ",77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100.000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3.000.000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1.200.000"
|
||||
, "1200000"
|
||||
, "1,2M"
|
||||
, "1200K"
|
||||
, ",0012G"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1.200.000"
|
||||
, "-1200000"
|
||||
, "minus 1.200.000"
|
||||
@ -96,23 +96,23 @@ allExamples = concat
|
||||
, "-,0012G"
|
||||
, "-0,0012G"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "5 ribu"
|
||||
, "lima ribu"
|
||||
]
|
||||
, examples (NumberValue 122)
|
||||
, examples (NumeralValue 122)
|
||||
[ "seratus dua puluh dua"
|
||||
]
|
||||
, examples (NumberValue 200000)
|
||||
, examples (NumeralValue 200000)
|
||||
[ "dua ratus ribu"
|
||||
]
|
||||
, examples (NumberValue 10011)
|
||||
, examples (NumeralValue 10011)
|
||||
[ "sepuluh ribu sebelas"
|
||||
]
|
||||
, examples (NumberValue 721012)
|
||||
, examples (NumeralValue 721012)
|
||||
[ "tujuh ratus dua puluh satu ribu dua belas"
|
||||
]
|
||||
, examples (NumberValue 31256721)
|
||||
, examples (NumeralValue 31256721)
|
||||
[ "tiga puluh satu juta dua ratus lima puluh enam ribu tujuh ratus dua puluh satu"
|
||||
]
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.ID.Rules
|
||||
module Duckling.Numeral.ID.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.Maybe
|
||||
@ -18,9 +18,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -32,33 +32,33 @@ ruleTeen = Rule
|
||||
, regex "belas"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v + 10
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v + 10
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberCommaNumber :: Rule
|
||||
ruleNumberCommaNumber = Rule
|
||||
ruleNumeralCommaNumeral :: Rule
|
||||
ruleNumeralCommaNumeral = Rule
|
||||
{ name = "number comma number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "koma"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
double $ TNumber.value nd1 + decimalsToDouble (TNumber.value nd2)
|
||||
double $ TNumeral.value nd1 + decimalsToDouble (TNumeral.value nd2)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|minus\\s?|negatif\\s?"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
@ -112,8 +112,8 @@ ruleMultiply = Rule
|
||||
}
|
||||
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*,\\d+)"
|
||||
@ -131,8 +131,8 @@ ruleInteger3 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -141,12 +141,12 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
, numberWith TNumber.multipliable not
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -160,15 +160,15 @@ ruleSomefewcouple = Rule
|
||||
, prod = \_ -> integer 3
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -231,11 +231,11 @@ ruleInteger2 = Rule
|
||||
{ name = "integer 20..90"
|
||||
, pattern =
|
||||
[ numberBetween 2 10
|
||||
, numberWith TNumber.value (== 10)
|
||||
, numberWith TNumeral.value (== 10)
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2, TNumber.grain = Just g}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2, TNumeral.grain = Just g}):
|
||||
_) -> double (v1 * v2) >>= withGrain g
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -254,7 +254,7 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDecimalNumber
|
||||
[ ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleDozen
|
||||
, ruleInteger
|
||||
@ -264,9 +264,9 @@ rules =
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleIntersect
|
||||
, ruleMultiply
|
||||
, ruleNumberCommaNumber
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeralCommaNumeral
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
, rulePowersOfTen
|
||||
, ruleSomefewcouple
|
||||
, ruleTeen
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.ID.Tests
|
||||
module Duckling.Numeral.ID.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.ID.Corpus
|
||||
import Duckling.Numeral.ID.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.IT.Corpus
|
||||
module Duckling.Numeral.IT.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,126 +24,126 @@ corpus = (testContext {lang = IT}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "nulla"
|
||||
, "zero"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "uno"
|
||||
, "Un"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "due"
|
||||
]
|
||||
, examples (NumberValue 3)
|
||||
, examples (NumeralValue 3)
|
||||
[ "3"
|
||||
, "tre"
|
||||
]
|
||||
, examples (NumberValue 4)
|
||||
, examples (NumeralValue 4)
|
||||
[ "4"
|
||||
, "quattro"
|
||||
]
|
||||
, examples (NumberValue 5)
|
||||
, examples (NumeralValue 5)
|
||||
[ "5"
|
||||
, "cinque"
|
||||
]
|
||||
, examples (NumberValue 6)
|
||||
, examples (NumeralValue 6)
|
||||
[ "6"
|
||||
, "sei"
|
||||
]
|
||||
, examples (NumberValue 7)
|
||||
, examples (NumeralValue 7)
|
||||
[ "7"
|
||||
, "sette"
|
||||
]
|
||||
, examples (NumberValue 8)
|
||||
, examples (NumeralValue 8)
|
||||
[ "8"
|
||||
, "otto"
|
||||
]
|
||||
, examples (NumberValue 9)
|
||||
, examples (NumeralValue 9)
|
||||
[ "9"
|
||||
, "nove"
|
||||
]
|
||||
, examples (NumberValue 10)
|
||||
, examples (NumeralValue 10)
|
||||
[ "10"
|
||||
, "dieci"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "trentatré"
|
||||
, "0033"
|
||||
]
|
||||
, examples (NumberValue 11)
|
||||
, examples (NumeralValue 11)
|
||||
[ "11"
|
||||
, "Undici"
|
||||
]
|
||||
, examples (NumberValue 12)
|
||||
, examples (NumeralValue 12)
|
||||
[ "12"
|
||||
, "dodici"
|
||||
]
|
||||
, examples (NumberValue 13)
|
||||
, examples (NumeralValue 13)
|
||||
[ "13"
|
||||
, "tredici"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "quattordici"
|
||||
]
|
||||
, examples (NumberValue 15)
|
||||
, examples (NumeralValue 15)
|
||||
[ "15"
|
||||
, "quindici"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "sedici"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "diciassette"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "diciotto"
|
||||
]
|
||||
, examples (NumberValue 19)
|
||||
, examples (NumeralValue 19)
|
||||
[ "19"
|
||||
, "diciannove"
|
||||
]
|
||||
, examples (NumberValue 20)
|
||||
, examples (NumeralValue 20)
|
||||
[ "20"
|
||||
, "venti"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1,1"
|
||||
, "1,10"
|
||||
, "01,10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0,77"
|
||||
, ",77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100.000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3.000.000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1.200.000"
|
||||
, "1200000"
|
||||
, "1,2M"
|
||||
, "1200K"
|
||||
, ",0012G"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1.200.000"
|
||||
, "-1200000"
|
||||
, "meno 1.200.000"
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.IT.Rules
|
||||
module Duckling.Numeral.IT.Rules
|
||||
( rules ) where
|
||||
|
||||
import qualified Data.Text as Text
|
||||
@ -17,21 +17,21 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|meno|negativo"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -55,16 +55,16 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
[ regex "(\\d+(\\.\\d\\d\\d)+,\\d+)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> let dot = Text.singleton '.'
|
||||
comma = Text.singleton ','
|
||||
fmt = Text.replace comma dot $ Text.replace dot Text.empty match
|
||||
(Token RegexMatch (GroupMatch (match:_)):_) ->
|
||||
let dot = Text.singleton '.'
|
||||
comma = Text.singleton ','
|
||||
fmt = Text.replace comma dot $ Text.replace dot Text.empty match
|
||||
in parseDouble fmt >>= double
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*,\\d+)"
|
||||
@ -75,8 +75,8 @@ ruleDecimalNumber = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber2 :: Rule
|
||||
ruleNumber2 = Rule
|
||||
ruleNumeral2 :: Rule
|
||||
ruleNumeral2 = Rule
|
||||
{ name = "number (20..90)"
|
||||
, pattern =
|
||||
[ regex "(venti|trenta|quaranta|cinquanta|sessanta|settanta|ottanta|novanta)"
|
||||
@ -95,8 +95,8 @@ ruleNumber2 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber :: Rule
|
||||
ruleNumber = Rule
|
||||
ruleNumeral :: Rule
|
||||
ruleNumeral = Rule
|
||||
{ name = "number (0..19)"
|
||||
, pattern =
|
||||
[ regex "(zero|nulla|niente|uno|due|tredici|tre|quattro|cinque|sei|sette|otto|nove|dieci|undici|dodici|quattordici|quindici|sedici|diciassette|diciotto|diciannove|un)"
|
||||
@ -130,8 +130,8 @@ ruleNumber = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber5 :: Rule
|
||||
ruleNumber5 = Rule
|
||||
ruleNumeral5 :: Rule
|
||||
ruleNumeral5 = Rule
|
||||
{ name = "number 100..1000 "
|
||||
, pattern =
|
||||
[ regex "(due|tre|quattro|cinque|sei|sette|otto|nove)?cento|mil(a|le)"
|
||||
@ -153,8 +153,8 @@ ruleNumber5 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber3 :: Rule
|
||||
ruleNumber3 = Rule
|
||||
ruleNumeral3 :: Rule
|
||||
ruleNumeral3 = Rule
|
||||
{ name = "number (21..29 31..39 41..49 51..59 61..69 71..79 81..89 91..99)"
|
||||
, pattern =
|
||||
[ oneOf [70, 20, 60, 50, 40, 90, 30, 80]
|
||||
@ -162,22 +162,22 @@ ruleNumber3 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -187,8 +187,8 @@ ruleNumbersSuffixesKMG = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber4 :: Rule
|
||||
ruleNumber4 = Rule
|
||||
ruleNumeral4 :: Rule
|
||||
ruleNumeral4 = Rule
|
||||
{ name = "number (21..29 31..39 41..49 51..59 61..69 71..79 81..89 91..99)"
|
||||
, pattern =
|
||||
[ regex "((venti|trenta|quaranta|cinquanta|sessanta|settanta|ottanta|novanta)(due|tre|tr\x00e9|quattro|cinque|sei|sette|nove))|((vent|trent|quarant|cinquant|sessant|settant|ottant|novant)(uno|otto))"
|
||||
@ -279,18 +279,18 @@ ruleNumber4 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbers :: Rule
|
||||
ruleNumbers = Rule
|
||||
ruleNumerals :: Rule
|
||||
ruleNumerals = Rule
|
||||
{ name = "numbers 200..999"
|
||||
, pattern =
|
||||
[ numberBetween 2 10
|
||||
, numberWith TNumber.value (== 100)
|
||||
, numberWith TNumeral.value (== 100)
|
||||
, numberBetween 0 100
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumberData {TNumber.value = v3}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v3}):
|
||||
_) -> double $ v1 * v2 + v3
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -309,16 +309,16 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDecimalNumber
|
||||
[ ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleIntegerNumeric
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleNumber
|
||||
, ruleNumber2
|
||||
, ruleNumber3
|
||||
, ruleNumber4
|
||||
, ruleNumber5
|
||||
, ruleNumbers
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeral
|
||||
, ruleNumeral2
|
||||
, ruleNumeral3
|
||||
, ruleNumeral4
|
||||
, ruleNumeral5
|
||||
, ruleNumerals
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.IT.Tests
|
||||
module Duckling.Numeral.IT.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.IT.Corpus
|
||||
import Duckling.Numeral.IT.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.JA.Corpus
|
||||
module Duckling.Numeral.JA.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,86 +24,86 @@ corpus = (testContext {lang = JA}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "零"
|
||||
, "ゼロ"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "一"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "三十三"
|
||||
, "0033"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "十四"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "十六"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "十七"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "十八"
|
||||
]
|
||||
, examples (NumberValue 100)
|
||||
, examples (NumeralValue 100)
|
||||
[ "100"
|
||||
, "百"
|
||||
]
|
||||
, examples (NumberValue 101)
|
||||
, examples (NumeralValue 101)
|
||||
[ "101"
|
||||
, "百一"
|
||||
]
|
||||
, examples (NumberValue 200)
|
||||
, examples (NumeralValue 200)
|
||||
[ "200"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1.1"
|
||||
, "1.10"
|
||||
, "01.10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0.77"
|
||||
, ".77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100,000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3,000,000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1,200,000"
|
||||
, "1200000"
|
||||
, "1.2M"
|
||||
, "1200K"
|
||||
, ".0012G"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1,200,000"
|
||||
, "-1200000"
|
||||
, "-1.2M"
|
||||
, "-1200K"
|
||||
, "-.0012G"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "5千"
|
||||
]
|
||||
, examples (NumberValue 20000)
|
||||
, examples (NumeralValue 20000)
|
||||
[ "2万"
|
||||
]
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.JA.Rules
|
||||
module Duckling.Numeral.JA.Rules
|
||||
( rules ) where
|
||||
|
||||
import qualified Data.Text as Text
|
||||
@ -17,9 +17,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -32,15 +32,15 @@ ruleInteger5 = Rule
|
||||
, prod = \_ -> integer 100
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|\x30de\x30a4\x30ca\x30b9\\s?|\x8ca0\\s?"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -89,7 +89,8 @@ ruleInteger10 = Rule
|
||||
, numberBetween 1 1000
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v + 1000
|
||||
(_:Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
double $ v + 1000
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -113,12 +114,12 @@ ruleInteger15 = Rule
|
||||
, regex "\x4e07"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v * 10000
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v * 10000
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*\\.\\d+)"
|
||||
@ -128,8 +129,8 @@ ruleDecimalNumber = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber :: Rule
|
||||
ruleNumber = Rule
|
||||
ruleNumeral :: Rule
|
||||
ruleNumeral = Rule
|
||||
{ name = "<number>个"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
@ -148,7 +149,7 @@ ruleInteger3 = Rule
|
||||
, regex "\x5341"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v * 10
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v * 10
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -169,7 +170,7 @@ ruleInteger6 = Rule
|
||||
, numberBetween 1 100
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v + 100
|
||||
(_:Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v + 100
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -181,21 +182,21 @@ ruleInteger12 = Rule
|
||||
, numberBetween 1 1000
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G, 千, 万)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "(k|m|g|\x5343|\x4e07)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -215,7 +216,7 @@ ruleInteger7 = Rule
|
||||
, regex "\x767e"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v * 100
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v * 100
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -227,7 +228,8 @@ ruleInteger14 = Rule
|
||||
, numberBetween 1 10000
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v + 10000
|
||||
(_:Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
double $ v + 10000
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -239,8 +241,8 @@ ruleInteger8 = Rule
|
||||
, numberBetween 1 100
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -253,8 +255,8 @@ ruleInteger16 = Rule
|
||||
, numberBetween 1 10000
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -300,8 +302,8 @@ ruleInteger4 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -314,7 +316,7 @@ ruleInteger2 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v + 10
|
||||
(_:Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v + 10
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -326,7 +328,7 @@ ruleInteger11 = Rule
|
||||
, regex "\x5343"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v * 1000
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v * 1000
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -344,7 +346,7 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDecimalNumber
|
||||
[ ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleInteger
|
||||
, ruleInteger10
|
||||
@ -365,7 +367,7 @@ rules =
|
||||
, ruleInteger9
|
||||
, ruleIntegerNumeric
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleNumber
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeral
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.JA.Tests
|
||||
module Duckling.Numeral.JA.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.JA.Corpus
|
||||
import Duckling.Numeral.JA.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.KO.Corpus
|
||||
module Duckling.Numeral.KO.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,162 +24,162 @@ corpus = (testContext {lang = KO}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "영"
|
||||
, "빵"
|
||||
, "공"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "일"
|
||||
, "하나"
|
||||
, "한"
|
||||
]
|
||||
, examples (NumberValue 10)
|
||||
, examples (NumeralValue 10)
|
||||
[ "10"
|
||||
, "십"
|
||||
, "열"
|
||||
]
|
||||
, examples (NumberValue 11)
|
||||
, examples (NumeralValue 11)
|
||||
[ "11"
|
||||
, "십일"
|
||||
, "열하나"
|
||||
, "십하나"
|
||||
, "열한"
|
||||
]
|
||||
, examples (NumberValue 20)
|
||||
, examples (NumeralValue 20)
|
||||
[ "20"
|
||||
, "이십"
|
||||
, "스물"
|
||||
]
|
||||
, examples (NumberValue 35)
|
||||
, examples (NumeralValue 35)
|
||||
[ "35"
|
||||
, "삼십오"
|
||||
, "서른다섯"
|
||||
]
|
||||
, examples (NumberValue 47)
|
||||
, examples (NumeralValue 47)
|
||||
[ "47"
|
||||
, "사십칠"
|
||||
, "마흔일곱"
|
||||
]
|
||||
, examples (NumberValue 52)
|
||||
, examples (NumeralValue 52)
|
||||
[ "52"
|
||||
, "오십이"
|
||||
, "쉰둘"
|
||||
, "쉰두"
|
||||
]
|
||||
, examples (NumberValue 69)
|
||||
, examples (NumeralValue 69)
|
||||
[ "69"
|
||||
, "육십구"
|
||||
, "예순아홉"
|
||||
]
|
||||
, examples (NumberValue 71)
|
||||
, examples (NumeralValue 71)
|
||||
[ "71"
|
||||
, "칠십일"
|
||||
, "일흔하나"
|
||||
, "일흔한"
|
||||
]
|
||||
, examples (NumberValue 84)
|
||||
, examples (NumeralValue 84)
|
||||
[ "84"
|
||||
, "팔십사"
|
||||
, "여든넷"
|
||||
]
|
||||
, examples (NumberValue 93)
|
||||
, examples (NumeralValue 93)
|
||||
[ "93"
|
||||
, "구십삼"
|
||||
, "아흔셋"
|
||||
]
|
||||
, examples (NumberValue 100)
|
||||
, examples (NumeralValue 100)
|
||||
[ "100"
|
||||
, "백"
|
||||
]
|
||||
, examples (NumberValue 123)
|
||||
, examples (NumeralValue 123)
|
||||
[ "123"
|
||||
, "백이십삼"
|
||||
]
|
||||
, examples (NumberValue 579)
|
||||
, examples (NumeralValue 579)
|
||||
[ "579"
|
||||
, "오백칠십구"
|
||||
]
|
||||
, examples (NumberValue 1000)
|
||||
, examples (NumeralValue 1000)
|
||||
[ "1000"
|
||||
, "천"
|
||||
]
|
||||
, examples (NumberValue 1723)
|
||||
, examples (NumeralValue 1723)
|
||||
[ "1723"
|
||||
, "천칠백이십삼"
|
||||
]
|
||||
, examples (NumberValue 5619)
|
||||
, examples (NumeralValue 5619)
|
||||
[ "5619"
|
||||
, "오천육백십구"
|
||||
]
|
||||
, examples (NumberValue 10000)
|
||||
, examples (NumeralValue 10000)
|
||||
[ "10000"
|
||||
, "만"
|
||||
, "일만"
|
||||
]
|
||||
, examples (NumberValue 12345)
|
||||
, examples (NumeralValue 12345)
|
||||
[ "12345"
|
||||
, "만이천삼백사십오"
|
||||
, "일만이천삼백사십오"
|
||||
]
|
||||
, examples (NumberValue 58194)
|
||||
, examples (NumeralValue 58194)
|
||||
[ "58194"
|
||||
, "오만팔천백구십사"
|
||||
]
|
||||
, examples (NumberValue 581900)
|
||||
, examples (NumeralValue 581900)
|
||||
[ "581900"
|
||||
, "오십팔만천구백"
|
||||
]
|
||||
, examples (NumberValue 5819014)
|
||||
, examples (NumeralValue 5819014)
|
||||
[ "5819014"
|
||||
, "오백팔십일만구천십사"
|
||||
]
|
||||
, examples (NumberValue 58190148)
|
||||
, examples (NumeralValue 58190148)
|
||||
[ "58190148"
|
||||
, "오천팔백십구만백사십팔"
|
||||
]
|
||||
, examples (NumberValue 100000000)
|
||||
, examples (NumeralValue 100000000)
|
||||
[ "100000000"
|
||||
, "일억"
|
||||
]
|
||||
, examples (NumberValue 274500000000)
|
||||
, examples (NumeralValue 274500000000)
|
||||
[ "274500000000"
|
||||
, "이천칠백사십오억"
|
||||
]
|
||||
, examples (NumberValue 100000002)
|
||||
, examples (NumeralValue 100000002)
|
||||
[ "100000002"
|
||||
, "일억이"
|
||||
]
|
||||
, examples (NumberValue 27350000)
|
||||
, examples (NumeralValue 27350000)
|
||||
[ "27350000"
|
||||
, "이천칠백삼십오만"
|
||||
]
|
||||
, examples (NumberValue 3235698120)
|
||||
, examples (NumeralValue 3235698120)
|
||||
[ "3235698120"
|
||||
, "삼십이억삼천오백육십구만팔천백이십"
|
||||
]
|
||||
, examples (NumberValue 40234985729)
|
||||
, examples (NumeralValue 40234985729)
|
||||
[ "40234985729"
|
||||
, "사백이억삼천사백구십팔만오천칠백이십구"
|
||||
]
|
||||
, examples (NumberValue 701239801123)
|
||||
, examples (NumeralValue 701239801123)
|
||||
[ "701239801123"
|
||||
, "칠천십이억삼천구백팔십만천백이십삼"
|
||||
]
|
||||
, examples (NumberValue 3.4)
|
||||
, examples (NumeralValue 3.4)
|
||||
[ "3.4"
|
||||
, "삼점사"
|
||||
]
|
||||
, examples (NumberValue 4123.3)
|
||||
, examples (NumeralValue 4123.3)
|
||||
[ "4123.3"
|
||||
, "사천백이십삼점삼"
|
||||
]
|
||||
, examples (NumberValue 1.23)
|
||||
, examples (NumeralValue 1.23)
|
||||
[ "일점이삼"
|
||||
]
|
||||
, examples (NumberValue (-3))
|
||||
, examples (NumeralValue (-3))
|
||||
[ "-3"
|
||||
, "마이너스3"
|
||||
, "마이너스삼"
|
||||
@ -187,7 +187,7 @@ allExamples = concat
|
||||
, "마이나스3"
|
||||
, "마이나스 3"
|
||||
]
|
||||
, examples (NumberValue 0.75)
|
||||
, examples (NumeralValue 0.75)
|
||||
[ "3/4"
|
||||
, "사분의삼"
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.KO.Rules
|
||||
module Duckling.Numeral.KO.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.Maybe
|
||||
@ -18,9 +18,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -75,8 +75,8 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*\\.\\d+)"
|
||||
@ -95,22 +95,22 @@ ruleFraction2 = Rule
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 / v2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithOr :: Rule
|
||||
ruleNumbersPrefixWithOr = Rule
|
||||
ruleNumeralsPrefixWithOr :: Rule
|
||||
ruleNumeralsPrefixWithOr = Rule
|
||||
{ name = "numbers prefix with -, 마이너스, or 마이나스"
|
||||
, pattern =
|
||||
[ regex "-|\xb9c8\xc774\xb108\xc2a4\\s?|\xb9c8\xc774\xb098\xc2a4\\s?"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -197,13 +197,13 @@ ruleSum :: Rule
|
||||
ruleSum = Rule
|
||||
{ name = "intersect 2 numbers"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
, numberWith TNumber.multipliable not
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens ->
|
||||
case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -213,7 +213,7 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
@ -250,22 +250,22 @@ ruleFraction = Rule
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v2 / v1
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number - 삼점사"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "(\xc810|\xca5c)((\xc601|\xc77c|\xc774|\xc0bc|\xc0ac|\xc624|\xc721|\xce60|\xd314|\xad6c)+)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token RegexMatch (GroupMatch (_:match:_)):
|
||||
_) -> do
|
||||
let getDigit '\xc601' = Just "0"
|
||||
@ -292,8 +292,8 @@ ruleIntegerType3 = Rule
|
||||
, oneOf [1 .. 9]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -312,7 +312,7 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDecimalNumber
|
||||
[ ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleFew
|
||||
, ruleFraction
|
||||
@ -329,6 +329,6 @@ rules =
|
||||
, ruleIntegerType3
|
||||
, ruleIntegerTypeAndOrdinals
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumbersPrefixWithOr
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumeralsPrefixWithOr
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.KO.Tests
|
||||
module Duckling.Numeral.KO.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.KO.Corpus
|
||||
import Duckling.Numeral.KO.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.MY.Corpus
|
||||
module Duckling.Numeral.MY.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,48 +24,48 @@ corpus = (testContext {lang = MY}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "၀"
|
||||
, "သုံည"
|
||||
, "မရှိ"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "၁"
|
||||
, "တစ်"
|
||||
, "ပထမ"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "၂"
|
||||
, "နှစ်"
|
||||
, "ဒုတိယ"
|
||||
]
|
||||
, examples (NumberValue 3)
|
||||
, examples (NumeralValue 3)
|
||||
[ "၃"
|
||||
, "သုံး"
|
||||
, "တတိယ"
|
||||
]
|
||||
, examples (NumberValue 30)
|
||||
, examples (NumeralValue 30)
|
||||
[ "သုံးဆယ်"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "သုံးဆယ့်သုံး"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "ဆယ့်လေး"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "ဆယ့်ခုနှစ်"
|
||||
]
|
||||
, examples (NumberValue 200)
|
||||
, examples (NumeralValue 200)
|
||||
[ "နှစ်ရာ"
|
||||
]
|
||||
, examples (NumberValue 900)
|
||||
, examples (NumeralValue 900)
|
||||
[ "ကိုးရာ"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "ငါးထောင်"
|
||||
]
|
||||
, examples (NumberValue 80000)
|
||||
, examples (NumeralValue 80000)
|
||||
[ "ရှစ်သောင်း"
|
||||
]
|
||||
]
|
@ -9,16 +9,16 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.MY.Rules
|
||||
module Duckling.Numeral.MY.Rules
|
||||
( rules ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -31,9 +31,9 @@ ruleInteger5 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2 * 10
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -68,7 +68,7 @@ ruleInteger3 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v + 10
|
||||
(_:Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v + 10
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ ruleInteger6 = Rule
|
||||
, regex "\x101b\x102c"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v * 100
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v * 100
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ ruleInteger7 = Rule
|
||||
, regex "\x1011\x1031\x102c\x1004\x103a"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v * 1000
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v * 1000
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ ruleInteger8 = Rule
|
||||
, regex "\x101e\x1031\x102c\x1004\x103a\x1038"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v * 10000
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v * 10000
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ ruleInteger4 = Rule
|
||||
, regex "\x1006\x101a\x103a"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v * 10
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v * 10
|
||||
_ -> Nothing
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.MY.Tests
|
||||
module Duckling.Numeral.MY.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.MY.Corpus
|
||||
import Duckling.Numeral.MY.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.NB.Corpus
|
||||
module Duckling.Numeral.NB.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,77 +24,77 @@ corpus = (testContext {lang = NB}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "null"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "én"
|
||||
, "en"
|
||||
, "Ett"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "to"
|
||||
, "et par"
|
||||
]
|
||||
, examples (NumberValue 7)
|
||||
, examples (NumeralValue 7)
|
||||
[ "7"
|
||||
, "syv"
|
||||
, "sju"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "fjorten"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "seksten"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "sytten"
|
||||
, "søtten"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "atten"
|
||||
]
|
||||
, examples (NumberValue 20)
|
||||
, examples (NumeralValue 20)
|
||||
[ "20"
|
||||
, "tyve"
|
||||
, "Tjue"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1,1"
|
||||
, "1,10"
|
||||
, "01,10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0,77"
|
||||
, ",77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100.000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3.000.000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1.200.000"
|
||||
, "1200000"
|
||||
, "1,2M"
|
||||
, "1200K"
|
||||
, ",0012G"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1.200.000"
|
||||
, "-1200000"
|
||||
, "minus 1.200.000"
|
||||
@ -103,11 +103,11 @@ allExamples = concat
|
||||
, "-1200K"
|
||||
, "-,0012G"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "5 tusen"
|
||||
, "fem tusen"
|
||||
]
|
||||
, examples (NumberValue 5020)
|
||||
, examples (NumeralValue 5020)
|
||||
[ "fem tusen og tjue"
|
||||
]
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.NB.Rules
|
||||
module Duckling.Numeral.NB.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.HashMap.Strict (HashMap)
|
||||
@ -21,9 +21,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -31,27 +31,27 @@ ruleIntersectWithAnd :: Rule
|
||||
ruleIntersectWithAnd = Rule
|
||||
{ name = "intersect (with and)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, regex "og"
|
||||
, numberWith TNumber.multipliable not
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|minus\\s?|negativ\\s?"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -97,15 +97,15 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*,\\d+)"
|
||||
@ -124,8 +124,8 @@ ruleInteger3 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -143,25 +143,25 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
, numberWith TNumber.multipliable not
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -274,17 +274,17 @@ ruleInteger2 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "komma"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
double $ TNumber.value nd1 + decimalsToDouble (TNumber.value nd2)
|
||||
double $ TNumeral.value nd1 + decimalsToDouble (TNumeral.value nd2)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -303,7 +303,7 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleAPair
|
||||
, ruleDecimalNumber
|
||||
, ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleDozen
|
||||
, ruleFew
|
||||
@ -315,9 +315,9 @@ rules =
|
||||
, ruleIntersect
|
||||
, ruleIntersectWithAnd
|
||||
, ruleMultiply
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
, rulePowersOfTen
|
||||
, ruleSingle
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.NB.Tests
|
||||
module Duckling.Numeral.NB.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.NB.Corpus
|
||||
import Duckling.Numeral.NB.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.NL.Corpus
|
||||
module Duckling.Numeral.NL.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,22 +24,22 @@ corpus = (testContext {lang = NL}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "nul"
|
||||
, "geen"
|
||||
, "niks"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "een"
|
||||
, "één"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "twee"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "3 en 30"
|
||||
, "drieendertig"
|
||||
@ -47,45 +47,45 @@ allExamples = concat
|
||||
, "drie en dertig"
|
||||
, "0033"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "veertien"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "zestien"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "zeventien"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "achtien"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1,1"
|
||||
, "1,10"
|
||||
, "01,10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0,77"
|
||||
, ",77"
|
||||
]
|
||||
, examples (NumberValue 300)
|
||||
, examples (NumeralValue 300)
|
||||
[ "3 honderd"
|
||||
, "drie honderd"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "5 duizend"
|
||||
, "vijf duizend"
|
||||
]
|
||||
, examples (NumberValue 122)
|
||||
, examples (NumeralValue 122)
|
||||
[ "honderd tweeëntwintig"
|
||||
, "honderd tweeentwintig"
|
||||
, "honderd twee en twintig"
|
||||
]
|
||||
, examples (NumberValue 20000)
|
||||
, examples (NumeralValue 20000)
|
||||
[ "twintig duizend"
|
||||
]
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.NL.Rules
|
||||
module Duckling.Numeral.NL.Rules
|
||||
( rules ) where
|
||||
|
||||
import Control.Monad (join)
|
||||
@ -22,21 +22,21 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|min|minus|negatief"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -86,8 +86,8 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*,\\d+)"
|
||||
@ -117,7 +117,7 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
@ -128,25 +128,25 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -156,8 +156,8 @@ ruleNumbersSuffixesKMG = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersEn :: Rule
|
||||
ruleNumbersEn = Rule
|
||||
ruleNumeralsEn :: Rule
|
||||
ruleNumeralsEn = Rule
|
||||
{ name = "numbers en"
|
||||
, pattern =
|
||||
[ numberBetween 1 10
|
||||
@ -165,9 +165,9 @@ ruleNumbersEn = Rule
|
||||
, oneOf [20, 30 .. 90]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -271,7 +271,7 @@ ruleInteger2 = Rule
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleCouple
|
||||
, ruleDecimalNumber
|
||||
, ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleDozen
|
||||
, ruleFew
|
||||
@ -281,9 +281,9 @@ rules =
|
||||
, ruleIntegerNumeric
|
||||
, ruleIntersect
|
||||
, ruleMultiply
|
||||
, ruleNumbersEn
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeralsEn
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
, rulePowersOfTen
|
||||
, ruleTen
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.NL.Tests
|
||||
module Duckling.Numeral.NL.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.NL.Corpus
|
||||
import Duckling.Numeral.NL.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.PL.Corpus
|
||||
module Duckling.Numeral.PL.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,70 +24,70 @@ corpus = (testContext {lang = PL}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "nic"
|
||||
, "zero"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "jeden"
|
||||
, "pojedynczy"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "dwa"
|
||||
, "para"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "trzydzieści trzy"
|
||||
, "0033"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "czternaście"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "szesnaście"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "siedemnaście"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "osiemnaście"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1.1"
|
||||
, "1.10"
|
||||
, "01.10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0.77"
|
||||
, ".77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100,000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3,000,000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1,200,000"
|
||||
, "1200000"
|
||||
, "1.2M"
|
||||
, "1200K"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1,200,000"
|
||||
, "-1200000"
|
||||
, "minus 1,200,000"
|
||||
@ -95,31 +95,31 @@ allExamples = concat
|
||||
, "-1200K"
|
||||
, "-.0012G"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "5 tysięcy"
|
||||
, "pięć tysięcy"
|
||||
]
|
||||
, examples (NumberValue 122)
|
||||
, examples (NumeralValue 122)
|
||||
[ "sto dwadzieścia dwa"
|
||||
]
|
||||
, examples (NumberValue 200000)
|
||||
, examples (NumeralValue 200000)
|
||||
[ "dwieście tysięcy"
|
||||
]
|
||||
, examples (NumberValue 21011)
|
||||
, examples (NumeralValue 21011)
|
||||
[ "dwadzieścia jeden tysięcy i jedenaście"
|
||||
, "dwadzieścia jeden tysięcy jedenaście"
|
||||
]
|
||||
, examples (NumberValue 721012)
|
||||
, examples (NumeralValue 721012)
|
||||
[ "siedemset dwadzieścia jeden tysięcy dwanaście"
|
||||
, "siedemset dwadzieścia jeden tysięcy i dwanaście"
|
||||
]
|
||||
, examples (NumberValue 65000000)
|
||||
, examples (NumeralValue 65000000)
|
||||
[ "sześćdziesiąt pięć milionów"
|
||||
]
|
||||
, examples (NumberValue 31256721)
|
||||
, examples (NumeralValue 31256721)
|
||||
[ "trzydzieści jeden milionów dwieście pięćdziesiąt sześć tysięcy siedemset dwadzieścia jeden"
|
||||
]
|
||||
, examples (NumberValue 15)
|
||||
, examples (NumeralValue 15)
|
||||
[ "piętnasta"
|
||||
]
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.PL.Rules
|
||||
module Duckling.Numeral.PL.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.Maybe
|
||||
@ -18,9 +18,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -64,27 +64,27 @@ ruleIntersectWithAnd :: Rule
|
||||
ruleIntersectWithAnd = Rule
|
||||
{ name = "intersect (with and)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, regex "i|a"
|
||||
, numberWith TNumber.multipliable not
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|minus\\s?|negative\\s?"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -127,8 +127,8 @@ ruleSpecialCompositionForMissingHundredsLikeInOneTwentyTwo = Rule
|
||||
, numberBetween 10 100
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double (v1 * 100 + v2)
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -154,8 +154,8 @@ ruleNine = Rule
|
||||
, prod = \_ -> integer 9
|
||||
}
|
||||
|
||||
ruleNumber8 :: Rule
|
||||
ruleNumber8 = Rule
|
||||
ruleNumeral8 :: Rule
|
||||
ruleNumeral8 = Rule
|
||||
{ name = "number 800"
|
||||
, pattern =
|
||||
[ regex "(osiem(set| setek))"
|
||||
@ -172,8 +172,8 @@ ruleTwelve = Rule
|
||||
, prod = \_ -> integer 12
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*\\.\\d+)"
|
||||
@ -219,8 +219,8 @@ ruleThirty = Rule
|
||||
, prod = \_ -> integer 30
|
||||
}
|
||||
|
||||
ruleNumber2 :: Rule
|
||||
ruleNumber2 = Rule
|
||||
ruleNumeral2 :: Rule
|
||||
ruleNumeral2 = Rule
|
||||
{ name = "number 200"
|
||||
, pattern =
|
||||
[ regex "dwie((\x015b)cie| setki)"
|
||||
@ -237,8 +237,8 @@ ruleSeventeen = Rule
|
||||
, prod = \_ -> integer 17
|
||||
}
|
||||
|
||||
ruleNumber :: Rule
|
||||
ruleNumber = Rule
|
||||
ruleNumeral :: Rule
|
||||
ruleNumeral = Rule
|
||||
{ name = "number 100"
|
||||
, pattern =
|
||||
[ regex "(sto|setki)"
|
||||
@ -246,8 +246,8 @@ ruleNumber = Rule
|
||||
, prod = \_ -> integer 100 >>= withGrain 2
|
||||
}
|
||||
|
||||
ruleNumber9 :: Rule
|
||||
ruleNumber9 = Rule
|
||||
ruleNumeral9 :: Rule
|
||||
ruleNumeral9 = Rule
|
||||
{ name = "number 900"
|
||||
, pattern =
|
||||
[ regex "dziewi(\x0119\x0107)(set| setek)"
|
||||
@ -291,8 +291,8 @@ ruleEight = Rule
|
||||
, prod = \_ -> integer 8
|
||||
}
|
||||
|
||||
ruleNumber5 :: Rule
|
||||
ruleNumber5 = Rule
|
||||
ruleNumeral5 :: Rule
|
||||
ruleNumeral5 = Rule
|
||||
{ name = "number 500"
|
||||
, pattern =
|
||||
[ regex "pi(\x0119\x0107)(set| setek)"
|
||||
@ -300,8 +300,8 @@ ruleNumber5 = Rule
|
||||
, prod = \_ -> integer 500 >>= withGrain 2
|
||||
}
|
||||
|
||||
ruleNumber3 :: Rule
|
||||
ruleNumber3 = Rule
|
||||
ruleNumeral3 :: Rule
|
||||
ruleNumeral3 = Rule
|
||||
{ name = "number 300"
|
||||
, pattern =
|
||||
[ regex "(trzy(sta| setki))"
|
||||
@ -340,12 +340,12 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
, numberWith TNumber.multipliable not
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -355,7 +355,7 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
@ -380,15 +380,15 @@ ruleFour = Rule
|
||||
, prod = \_ -> integer 4
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -398,8 +398,8 @@ ruleNumbersSuffixesKMG = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber7 :: Rule
|
||||
ruleNumber7 = Rule
|
||||
ruleNumeral7 :: Rule
|
||||
ruleNumeral7 = Rule
|
||||
{ name = "number 700"
|
||||
, pattern =
|
||||
[ regex "(siedem(set| setek))"
|
||||
@ -434,8 +434,8 @@ ruleSix = Rule
|
||||
, prod = \_ -> integer 6
|
||||
}
|
||||
|
||||
ruleNumber6 :: Rule
|
||||
ruleNumber6 = Rule
|
||||
ruleNumeral6 :: Rule
|
||||
ruleNumeral6 = Rule
|
||||
{ name = "number 600"
|
||||
, pattern =
|
||||
[ regex "(sze\x015b\x0107(set| setek))"
|
||||
@ -443,8 +443,8 @@ ruleNumber6 = Rule
|
||||
, prod = \_ -> integer 600 >>= withGrain 2
|
||||
}
|
||||
|
||||
ruleNumber4 :: Rule
|
||||
ruleNumber4 = Rule
|
||||
ruleNumeral4 :: Rule
|
||||
ruleNumeral4 = Rule
|
||||
{ name = "number 400"
|
||||
, pattern =
|
||||
[ regex "(cztery(sta| setki))"
|
||||
@ -505,8 +505,8 @@ ruleInteger2 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -520,17 +520,17 @@ ruleEighteen = Rule
|
||||
, prod = \_ -> integer 18
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "dot|point"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
double $ TNumber.value nd1 + decimalsToDouble (TNumber.value nd2)
|
||||
double $ TNumeral.value nd1 + decimalsToDouble (TNumeral.value nd2)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -560,7 +560,7 @@ rules =
|
||||
[ ruleAFew
|
||||
, ruleAPair
|
||||
, ruleCouple
|
||||
, ruleDecimalNumber
|
||||
, ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleDozen
|
||||
, ruleEight
|
||||
@ -581,18 +581,18 @@ rules =
|
||||
, ruleMultiply
|
||||
, ruleNine
|
||||
, ruleNineteen
|
||||
, ruleNumber
|
||||
, ruleNumber2
|
||||
, ruleNumber3
|
||||
, ruleNumber4
|
||||
, ruleNumber5
|
||||
, ruleNumber6
|
||||
, ruleNumber7
|
||||
, ruleNumber8
|
||||
, ruleNumber9
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeral
|
||||
, ruleNumeral2
|
||||
, ruleNumeral3
|
||||
, ruleNumeral4
|
||||
, ruleNumeral5
|
||||
, ruleNumeral6
|
||||
, ruleNumeral7
|
||||
, ruleNumeral8
|
||||
, ruleNumeral9
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
, ruleOne
|
||||
, ruleSeven
|
||||
, ruleSeventeen
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.PL.Tests
|
||||
module Duckling.Numeral.PL.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.PL.Corpus
|
||||
import Duckling.Numeral.PL.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.PT.Corpus
|
||||
module Duckling.Numeral.PT.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,133 +24,133 @@ corpus = (testContext {lang = PT}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 1)
|
||||
[ examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "um"
|
||||
, "Uma"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "dois"
|
||||
, "duas"
|
||||
]
|
||||
, examples (NumberValue 3)
|
||||
, examples (NumeralValue 3)
|
||||
[ "3"
|
||||
, "três"
|
||||
, "tres"
|
||||
]
|
||||
, examples (NumberValue 6)
|
||||
, examples (NumeralValue 6)
|
||||
[ "6"
|
||||
, "seis"
|
||||
]
|
||||
, examples (NumberValue 11)
|
||||
, examples (NumeralValue 11)
|
||||
[ "11"
|
||||
, "onze"
|
||||
]
|
||||
, examples (NumberValue 12)
|
||||
, examples (NumeralValue 12)
|
||||
[ "12"
|
||||
, "doze"
|
||||
, "uma dúzia"
|
||||
, "uma duzia"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "Catorze"
|
||||
, "quatorze"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "dezesseis"
|
||||
, "dezasseis"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "dezessete"
|
||||
, "dezassete"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "dezoito"
|
||||
]
|
||||
, examples (NumberValue 19)
|
||||
, examples (NumeralValue 19)
|
||||
[ "19"
|
||||
, "dezenove"
|
||||
, "dezanove"
|
||||
]
|
||||
, examples (NumberValue 21)
|
||||
, examples (NumeralValue 21)
|
||||
[ "21"
|
||||
, "vinte e um"
|
||||
]
|
||||
, examples (NumberValue 23)
|
||||
, examples (NumeralValue 23)
|
||||
[ "23"
|
||||
, "vinte e tres"
|
||||
, "vinte e três"
|
||||
]
|
||||
, examples (NumberValue 24)
|
||||
, examples (NumeralValue 24)
|
||||
[ "24"
|
||||
, "vinte e quatro"
|
||||
, "duas dúzias"
|
||||
, "duas duzias"
|
||||
]
|
||||
, examples (NumberValue 50)
|
||||
, examples (NumeralValue 50)
|
||||
[ "50"
|
||||
, "cinquenta"
|
||||
, "cinqüenta"
|
||||
, "cincoenta"
|
||||
]
|
||||
, examples (NumberValue 70)
|
||||
, examples (NumeralValue 70)
|
||||
[ "setenta"
|
||||
]
|
||||
, examples (NumberValue 78)
|
||||
, examples (NumeralValue 78)
|
||||
[ "setenta e oito"
|
||||
]
|
||||
, examples (NumberValue 80)
|
||||
, examples (NumeralValue 80)
|
||||
[ "oitenta"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "trinta e três"
|
||||
, "trinta e tres"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1,1"
|
||||
, "1,10"
|
||||
, "01,10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0,77"
|
||||
, ",77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100.000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
]
|
||||
, examples (NumberValue 100)
|
||||
, examples (NumeralValue 100)
|
||||
[ "100"
|
||||
, "Cem"
|
||||
]
|
||||
, examples (NumberValue 243)
|
||||
, examples (NumeralValue 243)
|
||||
[ "243"
|
||||
]
|
||||
, examples (NumberValue 300)
|
||||
, examples (NumeralValue 300)
|
||||
[ "trezentos"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3.000.000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1.200.000"
|
||||
, "1200000"
|
||||
, "1,2M"
|
||||
, "1200K"
|
||||
, ",0012G"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1.200.000"
|
||||
, "-1200000"
|
||||
, "menos 1.200.000"
|
||||
@ -158,7 +158,7 @@ allExamples = concat
|
||||
, "-1200K"
|
||||
, "-,0012G"
|
||||
]
|
||||
, examples (NumberValue 1.5)
|
||||
, examples (NumeralValue 1.5)
|
||||
[ "1 ponto cinco"
|
||||
, "um ponto cinco"
|
||||
, "1,5"
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.PT.Rules
|
||||
module Duckling.Numeral.PT.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.Maybe
|
||||
@ -18,21 +18,21 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|menos"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -64,8 +64,8 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*,\\d+)"
|
||||
@ -76,8 +76,8 @@ ruleDecimalNumber = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber2 :: Rule
|
||||
ruleNumber2 = Rule
|
||||
ruleNumeral2 :: Rule
|
||||
ruleNumeral2 = Rule
|
||||
{ name = "number (20..90)"
|
||||
, pattern =
|
||||
[ regex "(vinte|trinta|quarenta|cincoenta|cinq(\x00fc)enta|cinquenta|sessenta|setenta|oitenta|noventa)"
|
||||
@ -98,8 +98,8 @@ ruleNumber2 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber :: Rule
|
||||
ruleNumber = Rule
|
||||
ruleNumeral :: Rule
|
||||
ruleNumeral = Rule
|
||||
{ name = "number (0..15)"
|
||||
, pattern =
|
||||
[ regex "(zero|uma?|d(oi|ua)s|tr(\x00ea|e)s|quatro|cinco|seis|sete|oito|nove|dez|onze|doze|treze|(ca|qua)torze|quinze)"
|
||||
@ -130,8 +130,8 @@ ruleNumber = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber5 :: Rule
|
||||
ruleNumber5 = Rule
|
||||
ruleNumeral5 :: Rule
|
||||
ruleNumeral5 = Rule
|
||||
{ name = "number (16..19)"
|
||||
, pattern =
|
||||
[ regex "(dez[ea]sseis|dez[ea]ssete|dezoito|dez[ea]nove)"
|
||||
@ -149,28 +149,28 @@ ruleNumber5 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber3 :: Rule
|
||||
ruleNumber3 = Rule
|
||||
ruleNumeral3 :: Rule
|
||||
ruleNumeral3 = Rule
|
||||
{ name = "number (16..19)"
|
||||
, pattern =
|
||||
[ numberWith TNumber.value (== 10)
|
||||
[ numberWith TNumeral.value (== 10)
|
||||
, regex "e"
|
||||
, numberBetween 6 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral (NumberData {TNumber.value = v}):_) -> double $ 10 + v
|
||||
(_:Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ 10 + v
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -180,8 +180,8 @@ ruleNumbersSuffixesKMG = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber6 :: Rule
|
||||
ruleNumber6 = Rule
|
||||
ruleNumeral6 :: Rule
|
||||
ruleNumeral6 = Rule
|
||||
{ name = "number 100..1000 "
|
||||
, pattern =
|
||||
[ regex "(ce(m|to)|duzentos|trezentos|quatrocentos|quinhentos|seiscentos|setecentos|oitocentos|novecentos|mil)"
|
||||
@ -203,8 +203,8 @@ ruleNumber6 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumber4 :: Rule
|
||||
ruleNumber4 = Rule
|
||||
ruleNumeral4 :: Rule
|
||||
ruleNumeral4 = Rule
|
||||
{ name = "number (21..29 31..39 41..49 51..59 61..69 71..79 81..89 91..99)"
|
||||
, pattern =
|
||||
[ oneOf [70, 20, 60, 50, 40, 90, 30, 80]
|
||||
@ -212,9 +212,9 @@ ruleNumber4 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -228,47 +228,47 @@ ruleDozen = Rule
|
||||
, prod = \_ -> integer 12 >>= withGrain 1 >>= withMultipliable
|
||||
}
|
||||
|
||||
ruleNumberDozen :: Rule
|
||||
ruleNumberDozen = Rule
|
||||
ruleNumeralDozen :: Rule
|
||||
ruleNumeralDozen = Rule
|
||||
{ name = "number dozen"
|
||||
, pattern =
|
||||
[ numberBetween 1 11
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2, TNumber.grain = Just g}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2, TNumeral.grain = Just g}):
|
||||
_) -> double (v1 * v2) >>= withGrain g
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbers :: Rule
|
||||
ruleNumbers = Rule
|
||||
ruleNumerals :: Rule
|
||||
ruleNumerals = Rule
|
||||
{ name = "numbers 200..999"
|
||||
, pattern =
|
||||
[ numberBetween 2 10
|
||||
, numberWith TNumber.value (== 100)
|
||||
, numberWith TNumeral.value (== 100)
|
||||
, numberBetween 0 100
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 * 100 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "ponto"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
double $ TNumber.value nd1 + decimalsToDouble (TNumber.value nd2)
|
||||
double $ TNumeral.value nd1 + decimalsToDouble (TNumeral.value nd2)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -287,20 +287,20 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDecimalNumber
|
||||
[ ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleDozen
|
||||
, ruleIntegerNumeric
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleNumber
|
||||
, ruleNumber2
|
||||
, ruleNumber3
|
||||
, ruleNumber4
|
||||
, ruleNumber5
|
||||
, ruleNumber6
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumberDozen
|
||||
, ruleNumbers
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeral
|
||||
, ruleNumeral2
|
||||
, ruleNumeral3
|
||||
, ruleNumeral4
|
||||
, ruleNumeral5
|
||||
, ruleNumeral6
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumeralDozen
|
||||
, ruleNumerals
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.PT.Tests
|
||||
module Duckling.Numeral.PT.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.PT.Corpus
|
||||
import Duckling.Numeral.PT.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.RO.Corpus
|
||||
module Duckling.Numeral.RO.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,7 +24,7 @@ corpus = (testContext {lang = RO}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "zero"
|
||||
, "nici unul"
|
||||
@ -34,7 +34,7 @@ allExamples = concat
|
||||
, "nicio"
|
||||
, "nimic"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "unu"
|
||||
, "unul"
|
||||
@ -43,144 +43,144 @@ allExamples = concat
|
||||
, "intai"
|
||||
, "întâi"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "doi"
|
||||
, "doua"
|
||||
, "două"
|
||||
]
|
||||
, examples (NumberValue 3)
|
||||
, examples (NumeralValue 3)
|
||||
[ "3"
|
||||
, "trei"
|
||||
]
|
||||
, examples (NumberValue 4)
|
||||
, examples (NumeralValue 4)
|
||||
[ "4"
|
||||
, "patru"
|
||||
]
|
||||
, examples (NumberValue 5)
|
||||
, examples (NumeralValue 5)
|
||||
[ "5"
|
||||
, "cinci"
|
||||
]
|
||||
, examples (NumberValue 6)
|
||||
, examples (NumeralValue 6)
|
||||
[ "6"
|
||||
, "sase"
|
||||
, "șase"
|
||||
]
|
||||
, examples (NumberValue 7)
|
||||
, examples (NumeralValue 7)
|
||||
[ "7"
|
||||
, "sapte"
|
||||
, "șapte"
|
||||
]
|
||||
, examples (NumberValue 8)
|
||||
, examples (NumeralValue 8)
|
||||
[ "8"
|
||||
, "opt"
|
||||
]
|
||||
, examples (NumberValue 9)
|
||||
, examples (NumeralValue 9)
|
||||
[ "9"
|
||||
, "noua"
|
||||
, "nouă"
|
||||
]
|
||||
, examples (NumberValue 10)
|
||||
, examples (NumeralValue 10)
|
||||
[ "10"
|
||||
, "zece"
|
||||
, "zeci"
|
||||
]
|
||||
, examples (NumberValue 10)
|
||||
, examples (NumeralValue 10)
|
||||
[ "10"
|
||||
, "zece"
|
||||
]
|
||||
, examples (NumberValue 11)
|
||||
, examples (NumeralValue 11)
|
||||
[ "11"
|
||||
, "unsprezece"
|
||||
, "unspe"
|
||||
, "unșpe"
|
||||
]
|
||||
, examples (NumberValue 19)
|
||||
, examples (NumeralValue 19)
|
||||
[ "19"
|
||||
, "nouasprezece"
|
||||
, "nouaspe"
|
||||
, "nouăsprezece"
|
||||
, "nouășpe"
|
||||
]
|
||||
, examples (NumberValue 70)
|
||||
, examples (NumeralValue 70)
|
||||
[ "70"
|
||||
, "sapte zeci"
|
||||
, "șapte zeci"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1,1"
|
||||
, "1,10"
|
||||
, "01,10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0,77"
|
||||
, ",77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100.000"
|
||||
, "100000"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3000000"
|
||||
, "3.000.000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1.200.000"
|
||||
, "1200000"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "-1.200.000"
|
||||
, "-1200000"
|
||||
, "minus 1.200.000"
|
||||
]
|
||||
, examples (NumberValue (-3))
|
||||
, examples (NumeralValue (-3))
|
||||
[ "-3"
|
||||
, "3 negativ"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "5 mii"
|
||||
, "cinci mii"
|
||||
]
|
||||
, examples (NumberValue 1000)
|
||||
, examples (NumeralValue 1000)
|
||||
[ "o mie"
|
||||
, "1 mie"
|
||||
]
|
||||
, examples (NumberValue 100)
|
||||
, examples (NumeralValue 100)
|
||||
[ "o suta"
|
||||
, "o sută"
|
||||
, "1 suta"
|
||||
, "1 sută"
|
||||
]
|
||||
, examples (NumberValue 300)
|
||||
, examples (NumeralValue 300)
|
||||
[ "3 sute"
|
||||
, "trei sute"
|
||||
]
|
||||
, examples (NumberValue 1000000)
|
||||
, examples (NumeralValue 1000000)
|
||||
[ "un milion"
|
||||
, "1 milion"
|
||||
]
|
||||
, examples (NumberValue 7000000)
|
||||
, examples (NumeralValue 7000000)
|
||||
[ "7 milioane"
|
||||
, "sapte milioane"
|
||||
, "șapte milioane"
|
||||
]
|
||||
, examples (NumberValue 1000000000)
|
||||
, examples (NumeralValue 1000000000)
|
||||
[ "un miliard"
|
||||
, "1 miliard"
|
||||
]
|
||||
, examples (NumberValue 9000000000)
|
||||
, examples (NumeralValue 9000000000)
|
||||
[ "9 miliarde"
|
||||
, "noua miliarde"
|
||||
, "nouă miliarde"
|
||||
]
|
||||
, examples (NumberValue 20)
|
||||
, examples (NumeralValue 20)
|
||||
[ "20"
|
||||
, "douazeci"
|
||||
, "doua zeci"
|
||||
, "douăzeci"
|
||||
, "două zeci"
|
||||
]
|
||||
, examples (NumberValue 23)
|
||||
, examples (NumeralValue 23)
|
||||
[ "23"
|
||||
, "20 3"
|
||||
, "douazeci 3"
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.RO.Rules
|
||||
module Duckling.Numeral.RO.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.HashMap.Strict (HashMap)
|
||||
@ -21,21 +21,21 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
ruleNumbersPrefixWithOrMinus :: Rule
|
||||
ruleNumbersPrefixWithOrMinus = Rule
|
||||
ruleNumeralsPrefixWithOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithOrMinus = Rule
|
||||
{ name = "numbers prefix with - or minus"
|
||||
, pattern =
|
||||
[ regex "-|minus\\s?"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -60,8 +60,8 @@ ruleSpecialCompositionForMissingHundredsLikeInOneTwentyTwo = Rule
|
||||
, numberBetween 11 100
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = hundreds}):
|
||||
Token Numeral (NumberData {TNumber.value = rest}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = hundreds}):
|
||||
Token Numeral (NumeralData {TNumeral.value = rest}):
|
||||
_) -> double $ hundreds * 100 + rest
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -81,8 +81,8 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*,\\d+)"
|
||||
@ -101,8 +101,8 @@ ruleInteger3 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -112,7 +112,7 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
@ -123,12 +123,12 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -137,27 +137,27 @@ ruleIntersectCuI :: Rule
|
||||
ruleIntersectCuI = Rule
|
||||
{ name = "intersect (cu și)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, regex "(s|\x0219)i"
|
||||
, numberWith TNumber.multipliable not
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesWithNegativ :: Rule
|
||||
ruleNumbersSuffixesWithNegativ = Rule
|
||||
ruleNumeralsSuffixesWithNegativ :: Rule
|
||||
ruleNumeralsSuffixesWithNegativ = Rule
|
||||
{ name = "numbers suffixes with (negativ)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "(negativ|neg)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
_) -> double $ v * (-1)
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -298,7 +298,7 @@ ruleIntegerCuSeparatorDeMiiDot = Rule
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDecimalNumber
|
||||
[ ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleInteger
|
||||
, ruleIntegerZeroTen
|
||||
@ -309,8 +309,8 @@ rules =
|
||||
, ruleIntersect
|
||||
, ruleIntersectCuI
|
||||
, ruleMultiply
|
||||
, ruleNumbersPrefixWithOrMinus
|
||||
, ruleNumbersSuffixesWithNegativ
|
||||
, ruleNumeralsPrefixWithOrMinus
|
||||
, ruleNumeralsSuffixesWithNegativ
|
||||
, rulePowersOfTen
|
||||
, ruleSpecialCompositionForMissingHundredsLikeInOneTwentyTwo
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.RO.Tests
|
||||
module Duckling.Numeral.RO.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.RO.Corpus
|
||||
import Duckling.Numeral.RO.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.RU.Corpus
|
||||
module Duckling.Numeral.RU.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,87 +24,87 @@ corpus = (testContext {lang = RU}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "ноль"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "один"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "02"
|
||||
, "два"
|
||||
]
|
||||
, examples (NumberValue 3)
|
||||
, examples (NumeralValue 3)
|
||||
[ "3"
|
||||
, "три"
|
||||
, "03"
|
||||
]
|
||||
, examples (NumberValue 4)
|
||||
, examples (NumeralValue 4)
|
||||
[ "4"
|
||||
, "четыре"
|
||||
, "04"
|
||||
]
|
||||
, examples (NumberValue 5)
|
||||
, examples (NumeralValue 5)
|
||||
[ "пять"
|
||||
, "5"
|
||||
, "05"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "тридцать три"
|
||||
, "0033"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "четырнадцать"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "шестнадцать"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "семнадцать"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "восемнадцать"
|
||||
]
|
||||
, examples (NumberValue 525)
|
||||
, examples (NumeralValue 525)
|
||||
[ "пятьсот двадцать пять"
|
||||
, "525"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1.1"
|
||||
, "1.10"
|
||||
, "01.10"
|
||||
, "1 точка 1"
|
||||
, "один точка один"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0.77"
|
||||
, ".77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100000"
|
||||
, "100к"
|
||||
, "100К"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3М"
|
||||
, "3000К"
|
||||
, "3000000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1200000"
|
||||
, "1.2М"
|
||||
, "1200К"
|
||||
, ".0012Г"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "-1200000"
|
||||
, "минус 1200000"
|
||||
, "-1.2М"
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.RU.Rules
|
||||
module Duckling.Numeral.RU.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.Maybe
|
||||
@ -18,9 +18,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -69,8 +69,8 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*\\.\\d+)"
|
||||
@ -110,27 +110,27 @@ ruleInteger6 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithMinus :: Rule
|
||||
ruleNumbersPrefixWithMinus = Rule
|
||||
ruleNumeralsPrefixWithMinus :: Rule
|
||||
ruleNumeralsPrefixWithMinus = Rule
|
||||
{ name = "numbers prefix with -, minus"
|
||||
, pattern =
|
||||
[ regex "-|\x043c\x0438\x043d\x0443\x0441\\s?"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "((\x043a|\x043c|\x0433)|(\x041a|\x041c|\x0413))(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"\x043a" -> double $ v * 1e3
|
||||
@ -151,8 +151,8 @@ ruleInteger7 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -165,8 +165,8 @@ ruleInteger8 = Rule
|
||||
, numberBetween 1 100
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -218,17 +218,17 @@ ruleInteger2 = Rule
|
||||
, prod = \_ -> integer 1
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "\x0442\x043e\x0447\x043a\x0430"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
double $ TNumber.value nd1 + decimalsToDouble (TNumber.value nd2)
|
||||
double $ TNumeral.value nd1 + decimalsToDouble (TNumeral.value nd2)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -246,7 +246,7 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDecimalNumber
|
||||
[ ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleInteger
|
||||
, ruleInteger2
|
||||
@ -258,7 +258,7 @@ rules =
|
||||
, ruleInteger8
|
||||
, ruleIntegerNumeric
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumbersPrefixWithMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumeralsPrefixWithMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.RU.Tests
|
||||
module Duckling.Numeral.RU.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.RU.Corpus
|
||||
import Duckling.Numeral.RU.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.SV.Corpus
|
||||
module Duckling.Numeral.SV.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,73 +24,73 @@ corpus = (testContext {lang = SV}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "noll"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "en"
|
||||
, "ett"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "två"
|
||||
, "ett par"
|
||||
]
|
||||
, examples (NumberValue 7)
|
||||
, examples (NumeralValue 7)
|
||||
[ "7"
|
||||
, "sju"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "Fjorton"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "sexton"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "sjutton"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "arton"
|
||||
]
|
||||
, examples (NumberValue 20)
|
||||
, examples (NumeralValue 20)
|
||||
[ "20"
|
||||
, "tjugo"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1,1"
|
||||
, "1,10"
|
||||
, "01,10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0,77"
|
||||
, ",77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100.000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3.000.000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1.200.000"
|
||||
, "1200000"
|
||||
, "1,2M"
|
||||
, "1200K"
|
||||
, ",0012G"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1.200.000"
|
||||
, "-1200000"
|
||||
, "minus 1.200.000"
|
||||
@ -99,7 +99,7 @@ allExamples = concat
|
||||
, "-1200K"
|
||||
, "-,0012G"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "5 tusen"
|
||||
, "fem tusen"
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.SV.Rules
|
||||
module Duckling.Numeral.SV.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.Maybe
|
||||
@ -18,9 +18,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -28,20 +28,20 @@ ruleIntersectWithAnd :: Rule
|
||||
ruleIntersectWithAnd = Rule
|
||||
{ name = "intersect (with and)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, regex "och"
|
||||
, numberWith TNumber.multipliable not
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|minus\\s?|negativ\\s?"
|
||||
@ -49,7 +49,7 @@ ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:
|
||||
Token Numeral (NumberData {TNumber.value = v}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
_) -> double $ v * (-1)
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -84,16 +84,16 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
[ regex "(\\d+(\\.\\d\\d\\d)+\\,\\d+)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> let dot = Text.singleton '.'
|
||||
comma = Text.singleton ','
|
||||
fmt = Text.replace comma dot $ Text.replace dot Text.empty match
|
||||
(Token RegexMatch (GroupMatch (match:_)):_) ->
|
||||
let dot = Text.singleton '.'
|
||||
comma = Text.singleton ','
|
||||
fmt = Text.replace comma dot $ Text.replace dot Text.empty match
|
||||
in parseDouble fmt >>= double
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*,\\d+)"
|
||||
@ -112,8 +112,8 @@ ruleInteger3 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -131,12 +131,12 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
, numberWith TNumber.multipliable not
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -146,22 +146,22 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -262,17 +262,17 @@ ruleInteger2 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "komma"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
double $ TNumber.value nd1 + decimalsToDouble (TNumber.value nd2)
|
||||
double $ TNumeral.value nd1 + decimalsToDouble (TNumeral.value nd2)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -292,7 +292,7 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleCouple
|
||||
, ruleDecimalNumber
|
||||
, ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleDozen
|
||||
, ruleFew
|
||||
@ -304,9 +304,9 @@ rules =
|
||||
, ruleIntersect
|
||||
, ruleIntersectWithAnd
|
||||
, ruleMultiply
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
, rulePowersOfTen
|
||||
, ruleSingle
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.SV.Tests
|
||||
module Duckling.Numeral.SV.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.SV.Corpus
|
||||
import Duckling.Numeral.SV.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.TR.Corpus
|
||||
module Duckling.Numeral.TR.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,74 +24,74 @@ corpus = (testContext {lang = TR}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "yok"
|
||||
, "hiç"
|
||||
, "sıfır"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "bir"
|
||||
, "tek"
|
||||
, "yek"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "iki"
|
||||
, "çift"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "otuzüç"
|
||||
, "otuz üç"
|
||||
, "0033"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "ondört"
|
||||
, "on dört"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "onaltı"
|
||||
, "on altı"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "onyedi"
|
||||
, "on yedi"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "onsekiz"
|
||||
, "on sekiz"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1.1"
|
||||
, "1.10"
|
||||
, "01.10"
|
||||
, "bir virgül bir"
|
||||
, "bir nokta bir"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0.77"
|
||||
, ".77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100,000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
, "100b"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3,000,000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1,200,000"
|
||||
, "1200000"
|
||||
, "1.2M"
|
||||
@ -99,7 +99,7 @@ allExamples = concat
|
||||
, ".0012G"
|
||||
, "1200B"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1,200,000"
|
||||
, "-1200000"
|
||||
, "eksi 1,200,000"
|
||||
@ -109,70 +109,70 @@ allExamples = concat
|
||||
, "-.0012G"
|
||||
, "-1200B"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "5 bin"
|
||||
, "beş bin"
|
||||
]
|
||||
, examples (NumberValue 50)
|
||||
, examples (NumeralValue 50)
|
||||
[ "5 deste"
|
||||
, "beş deste"
|
||||
]
|
||||
, examples (NumberValue 200000)
|
||||
, examples (NumeralValue 200000)
|
||||
[ "iki yüz bin"
|
||||
, "ikiyüzbin"
|
||||
]
|
||||
, examples (NumberValue 21011)
|
||||
, examples (NumeralValue 21011)
|
||||
[ "yirmi bir bin on bir"
|
||||
, "yirmibir bin onbir"
|
||||
]
|
||||
, examples (NumberValue 721012)
|
||||
, examples (NumeralValue 721012)
|
||||
[ "yedi yüz yirmibir bin on iki"
|
||||
, "yedi yüz yirmi bir bin on iki"
|
||||
, "yediyüz yirmibir bin oniki"
|
||||
]
|
||||
, examples (NumberValue 300341)
|
||||
, examples (NumeralValue 300341)
|
||||
[ "üçyüzbin üçyüz kırkbir"
|
||||
, "üç yüz bin üç yüz kırk bir"
|
||||
]
|
||||
, examples (NumberValue 40348)
|
||||
, examples (NumeralValue 40348)
|
||||
[ "kırkbin üçyüz kırksekiz"
|
||||
, "kırk bin üç yüz kırk sekiz"
|
||||
]
|
||||
, examples (NumberValue 31256721)
|
||||
, examples (NumeralValue 31256721)
|
||||
[ "otuz bir milyon iki yüz elli altı bin yedi yüz yirmi bir"
|
||||
]
|
||||
, examples (NumberValue 107)
|
||||
, examples (NumeralValue 107)
|
||||
[ "107"
|
||||
, "yüz yedi"
|
||||
]
|
||||
, examples (NumberValue 5.5)
|
||||
, examples (NumeralValue 5.5)
|
||||
[ "beş buçuk"
|
||||
, "beşbuçuk"
|
||||
, "5 buçuk"
|
||||
, "5.5"
|
||||
]
|
||||
, examples (NumberValue 3500000)
|
||||
, examples (NumeralValue 3500000)
|
||||
[ "3.5 milyon"
|
||||
, "3500000"
|
||||
, "üç buçuk milyon"
|
||||
, "üçbuçuk milyon"
|
||||
, "3.5M"
|
||||
]
|
||||
, examples (NumberValue 0.5)
|
||||
, examples (NumeralValue 0.5)
|
||||
[ "yarım"
|
||||
, "0.5"
|
||||
]
|
||||
, examples (NumberValue 2500)
|
||||
, examples (NumeralValue 2500)
|
||||
[ "2.5 bin"
|
||||
, "2500"
|
||||
, "iki buçuk bin"
|
||||
, "ikibuçuk bin"
|
||||
]
|
||||
, examples (NumberValue 2200000)
|
||||
, examples (NumeralValue 2200000)
|
||||
[ "2.2 milyon"
|
||||
, "iki nokta iki milyon"
|
||||
]
|
||||
, examples (NumberValue 72.5)
|
||||
, examples (NumeralValue 72.5)
|
||||
[ "yetmişikibuçuk"
|
||||
, "yetmişiki buçuk"
|
||||
, "72.5"
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.TR.Rules
|
||||
module Duckling.Numeral.TR.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.Maybe
|
||||
@ -18,9 +18,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -45,15 +45,16 @@ ruleInteger5 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumbersPrefixWithNegativeOrMinus = Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
|
||||
ruleNumeralsPrefixWithNegativeOrMinus = Rule
|
||||
{ name = "numbers prefix with -, negative or minus"
|
||||
, pattern =
|
||||
[ regex "-|eksi\\s?|negatif\\s?"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral (NumberData {TNumber.value = v}):_) -> double (v * (- 1))
|
||||
(_:Token Numeral (NumeralData {TNumeral.value = v}):_) ->
|
||||
double (v * (- 1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -114,19 +115,19 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1}):
|
||||
Token Numeral (NumberData {TNumber.value = val2, TNumber.grain = g2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2, TNumeral.grain = g2}):
|
||||
_) | isNothing g2 || (isJust g2 && val2 > val1) -> case g2 of
|
||||
Nothing -> double $ val1 * val2
|
||||
Just g -> double (val1 * val2) >>= withGrain g
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*\\.\\d+)"
|
||||
@ -137,8 +138,8 @@ ruleDecimalNumber = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberSuffixesHalfsuffixText :: Rule
|
||||
ruleNumberSuffixesHalfsuffixText = Rule
|
||||
ruleNumeralSuffixesHalfsuffixText :: Rule
|
||||
ruleNumeralSuffixesHalfsuffixText = Rule
|
||||
{ name = "number suffixes (half-suffix text) (1..9)"
|
||||
, pattern =
|
||||
[ regex "((bir?|iki|\x00fc\x00e7|d\x00f6rt|be\x015f|alt\x0131|yedi|sekiz|dokuz)(bu\x00e7uk))"
|
||||
@ -294,25 +295,25 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
, numberWith TNumber.multipliable not
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmgb])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -536,8 +537,8 @@ ruleInteger = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberSuffixesHalfsuffixText2 :: Rule
|
||||
ruleNumberSuffixesHalfsuffixText2 = Rule
|
||||
ruleNumeralSuffixesHalfsuffixText2 :: Rule
|
||||
ruleNumeralSuffixesHalfsuffixText2 = Rule
|
||||
{ name = "number suffixes (half-suffix text) (10..90)"
|
||||
, pattern =
|
||||
[ regex "((on|yirmi|otuz|k\x0131rk|elli|atm\x0131\x015f|altm\x0131\x015f|yetmi\x015f|seksen|doksan)(bu\x00e7uk))"
|
||||
@ -558,15 +559,15 @@ ruleNumberSuffixesHalfsuffixText2 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberSuffixesHalfSuffix :: Rule
|
||||
ruleNumberSuffixesHalfSuffix = Rule
|
||||
ruleNumeralSuffixesHalfSuffix :: Rule
|
||||
ruleNumeralSuffixesHalfSuffix = Rule
|
||||
{ name = "number suffixes (half-suffix)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "(bu\x00e7uk)(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v + 0.5
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v + 0.5
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -578,8 +579,8 @@ ruleInteger4 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -624,18 +625,18 @@ ruleQuarter = Rule
|
||||
, prod = \_ -> double 0.25
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "nokta|virg\x00fcl"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + decimalsToDouble v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -655,7 +656,7 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleACoupleOf
|
||||
, ruleDecimalNumber
|
||||
, ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleDozen
|
||||
, ruleFew
|
||||
@ -673,12 +674,12 @@ rules =
|
||||
, ruleIntegerNumeric
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleIntersect
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumberSuffixesHalfSuffix
|
||||
, ruleNumberSuffixesHalfsuffixText
|
||||
, ruleNumberSuffixesHalfsuffixText2
|
||||
, ruleNumbersPrefixWithNegativeOrMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumeralSuffixesHalfSuffix
|
||||
, ruleNumeralSuffixesHalfsuffixText
|
||||
, ruleNumeralSuffixesHalfsuffixText2
|
||||
, ruleNumeralsPrefixWithNegativeOrMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
, rulePowersOfTen
|
||||
, ruleQuarter
|
||||
, ruleTen
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.TR.Tests
|
||||
module Duckling.Numeral.TR.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.TR.Corpus
|
||||
import Duckling.Numeral.TR.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
66
Duckling/Numeral/Tests.hs
Normal file
66
Duckling/Numeral/Tests.hs
Normal file
@ -0,0 +1,66 @@
|
||||
-- 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.
|
||||
|
||||
|
||||
module Duckling.Numeral.Tests (tests) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
import Test.Tasty
|
||||
|
||||
import qualified Duckling.Numeral.AR.Tests as AR
|
||||
import qualified Duckling.Numeral.DA.Tests as DA
|
||||
import qualified Duckling.Numeral.DE.Tests as DE
|
||||
import qualified Duckling.Numeral.EN.Tests as EN
|
||||
import qualified Duckling.Numeral.ES.Tests as ES
|
||||
import qualified Duckling.Numeral.ET.Tests as ET
|
||||
import qualified Duckling.Numeral.FR.Tests as FR
|
||||
import qualified Duckling.Numeral.GA.Tests as GA
|
||||
import qualified Duckling.Numeral.ID.Tests as ID
|
||||
import qualified Duckling.Numeral.IT.Tests as IT
|
||||
import qualified Duckling.Numeral.JA.Tests as JA
|
||||
import qualified Duckling.Numeral.KO.Tests as KO
|
||||
import qualified Duckling.Numeral.MY.Tests as MY
|
||||
import qualified Duckling.Numeral.NB.Tests as NB
|
||||
import qualified Duckling.Numeral.NL.Tests as NL
|
||||
import qualified Duckling.Numeral.PL.Tests as PL
|
||||
import qualified Duckling.Numeral.PT.Tests as PT
|
||||
import qualified Duckling.Numeral.RO.Tests as RO
|
||||
import qualified Duckling.Numeral.RU.Tests as RU
|
||||
import qualified Duckling.Numeral.SV.Tests as SV
|
||||
import qualified Duckling.Numeral.TR.Tests as TR
|
||||
import qualified Duckling.Numeral.UK.Tests as UK
|
||||
import qualified Duckling.Numeral.VI.Tests as VI
|
||||
import qualified Duckling.Numeral.ZH.Tests as ZH
|
||||
|
||||
tests :: TestTree
|
||||
tests = testGroup "Numeral Tests"
|
||||
[ AR.tests
|
||||
, DA.tests
|
||||
, DE.tests
|
||||
, EN.tests
|
||||
, ES.tests
|
||||
, ET.tests
|
||||
, FR.tests
|
||||
, GA.tests
|
||||
, ID.tests
|
||||
, IT.tests
|
||||
, JA.tests
|
||||
, KO.tests
|
||||
, MY.tests
|
||||
, NB.tests
|
||||
, NL.tests
|
||||
, PL.tests
|
||||
, PT.tests
|
||||
, RO.tests
|
||||
, RU.tests
|
||||
, SV.tests
|
||||
, TR.tests
|
||||
, UK.tests
|
||||
, VI.tests
|
||||
, ZH.tests
|
||||
]
|
@ -13,7 +13,7 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
|
||||
module Duckling.Number.Types where
|
||||
module Duckling.Numeral.Types where
|
||||
|
||||
import Control.DeepSeq
|
||||
import Data.Aeson
|
||||
@ -25,22 +25,22 @@ import Prelude
|
||||
|
||||
import Duckling.Resolve
|
||||
|
||||
data NumberData = NumberData
|
||||
data NumeralData = NumeralData
|
||||
{ value :: Double
|
||||
, grain :: Maybe Int
|
||||
, multipliable :: Bool
|
||||
}
|
||||
deriving (Eq, Generic, Hashable, Ord, Show, NFData)
|
||||
|
||||
instance Resolve NumberData where
|
||||
type ResolvedValue NumberData = NumberValue
|
||||
resolve _ NumberData {value} = Just NumberValue {vValue = value}
|
||||
instance Resolve NumeralData where
|
||||
type ResolvedValue NumeralData = NumeralValue
|
||||
resolve _ NumeralData {value} = Just NumeralValue {vValue = value}
|
||||
|
||||
newtype NumberValue = NumberValue { vValue :: Double }
|
||||
newtype NumeralValue = NumeralValue { vValue :: Double }
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance ToJSON NumberValue where
|
||||
toJSON (NumberValue value) = object
|
||||
instance ToJSON NumeralValue where
|
||||
toJSON (NumeralValue value) = object
|
||||
[ "type" .= ("value" :: Text)
|
||||
, "value" .= value
|
||||
]
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.UK.Corpus
|
||||
module Duckling.Numeral.UK.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,87 +24,87 @@ corpus = (testContext {lang = UK}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "нуль"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "один"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "02"
|
||||
, "два"
|
||||
]
|
||||
, examples (NumberValue 3)
|
||||
, examples (NumeralValue 3)
|
||||
[ "3"
|
||||
, "три"
|
||||
, "03"
|
||||
]
|
||||
, examples (NumberValue 4)
|
||||
, examples (NumeralValue 4)
|
||||
[ "4"
|
||||
, "чотири"
|
||||
, "04"
|
||||
]
|
||||
, examples (NumberValue 5)
|
||||
, examples (NumeralValue 5)
|
||||
[ "п‘ять"
|
||||
, "5"
|
||||
, "05"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "тридцять три"
|
||||
, "0033"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "чотирнадцять"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "шістнадцять"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "сімнадцять"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "вісімнадцять"
|
||||
]
|
||||
, examples (NumberValue 525)
|
||||
, examples (NumeralValue 525)
|
||||
[ "п‘ятсот двадцять п‘ять"
|
||||
, "525"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1.1"
|
||||
, "1.10"
|
||||
, "01.10"
|
||||
, "1 крапка 1"
|
||||
, "один крапка один"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0.77"
|
||||
, ".77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100000"
|
||||
, "100к"
|
||||
, "100К"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3М"
|
||||
, "3000К"
|
||||
, "3000000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1200000"
|
||||
, "1.2М"
|
||||
, "1200К"
|
||||
, ".0012Г"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "-1200000"
|
||||
, "мінус 1200000"
|
||||
, "-1.2М"
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.UK.Rules
|
||||
module Duckling.Numeral.UK.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.Maybe
|
||||
@ -18,9 +18,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -69,8 +69,8 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*\\.\\d+)"
|
||||
@ -110,27 +110,27 @@ ruleInteger6 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithMinus :: Rule
|
||||
ruleNumbersPrefixWithMinus = Rule
|
||||
ruleNumeralsPrefixWithMinus :: Rule
|
||||
ruleNumeralsPrefixWithMinus = Rule
|
||||
{ name = "numbers prefix with -, minus"
|
||||
, pattern =
|
||||
[ regex "-|\x043c\x0456\x043d\x0443\x0441\\s?"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "((\x043a|\x043c|\x0433)|(\x041a|\x041c|\x0413))(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"\x043a" -> double $ v * 1e3
|
||||
@ -151,8 +151,8 @@ ruleInteger7 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -165,8 +165,8 @@ ruleInteger8 = Rule
|
||||
, numberBetween 1 100
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -218,17 +218,17 @@ ruleInteger2 = Rule
|
||||
, prod = \_ -> integer 1
|
||||
}
|
||||
|
||||
ruleNumberDotNumber :: Rule
|
||||
ruleNumberDotNumber = Rule
|
||||
ruleNumeralDotNumeral :: Rule
|
||||
ruleNumeralDotNumeral = Rule
|
||||
{ name = "number dot number"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "\x043a\x0440\x0430\x043f\x043a\x0430"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
double $ TNumber.value nd1 + decimalsToDouble (TNumber.value nd2)
|
||||
double $ TNumeral.value nd1 + decimalsToDouble (TNumeral.value nd2)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -247,7 +247,7 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDecimalNumber
|
||||
[ ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleInteger
|
||||
, ruleInteger2
|
||||
@ -259,7 +259,7 @@ rules =
|
||||
, ruleInteger8
|
||||
, ruleIntegerNumeric
|
||||
, ruleIntegerWithThousandsSeparator
|
||||
, ruleNumberDotNumber
|
||||
, ruleNumbersPrefixWithMinus
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeralDotNumeral
|
||||
, ruleNumeralsPrefixWithMinus
|
||||
, ruleNumeralsSuffixesKMG
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.UK.Tests
|
||||
module Duckling.Numeral.UK.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.UK.Corpus
|
||||
import Duckling.Numeral.UK.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
@ -8,14 +8,14 @@
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.VI.Corpus
|
||||
module Duckling.Numeral.VI.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Number.Types
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
@ -24,67 +24,67 @@ corpus = (testContext {lang = VI}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumberValue 0)
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "không"
|
||||
]
|
||||
, examples (NumberValue 1)
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "một"
|
||||
]
|
||||
, examples (NumberValue 2)
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "hai"
|
||||
]
|
||||
, examples (NumberValue 33)
|
||||
, examples (NumeralValue 33)
|
||||
[ "33"
|
||||
, "ba mươi ba"
|
||||
]
|
||||
, examples (NumberValue 14)
|
||||
, examples (NumeralValue 14)
|
||||
[ "14"
|
||||
, "mười bốn"
|
||||
]
|
||||
, examples (NumberValue 16)
|
||||
, examples (NumeralValue 16)
|
||||
[ "16"
|
||||
, "mười sáu"
|
||||
]
|
||||
, examples (NumberValue 17)
|
||||
, examples (NumeralValue 17)
|
||||
[ "17"
|
||||
, "mười bảy"
|
||||
]
|
||||
, examples (NumberValue 18)
|
||||
, examples (NumeralValue 18)
|
||||
[ "18"
|
||||
, "mười tám"
|
||||
]
|
||||
, examples (NumberValue 1.1)
|
||||
, examples (NumeralValue 1.1)
|
||||
[ "1.1"
|
||||
, "1.10"
|
||||
, "01.10"
|
||||
]
|
||||
, examples (NumberValue 0.77)
|
||||
, examples (NumeralValue 0.77)
|
||||
[ "0.77"
|
||||
, ".77"
|
||||
]
|
||||
, examples (NumberValue 100000)
|
||||
, examples (NumeralValue 100000)
|
||||
[ "100,000"
|
||||
, "100000"
|
||||
, "100K"
|
||||
, "100k"
|
||||
]
|
||||
, examples (NumberValue 3000000)
|
||||
, examples (NumeralValue 3000000)
|
||||
[ "3M"
|
||||
, "3000K"
|
||||
, "3000000"
|
||||
, "3,000,000"
|
||||
]
|
||||
, examples (NumberValue 1200000)
|
||||
, examples (NumeralValue 1200000)
|
||||
[ "1,200,000"
|
||||
, "1200000"
|
||||
, "1.2M"
|
||||
, "1200K"
|
||||
, ".0012G"
|
||||
]
|
||||
, examples (NumberValue (-1200000))
|
||||
, examples (NumeralValue (-1200000))
|
||||
[ "- 1,200,000"
|
||||
, "-1200000"
|
||||
, "âm 1,200,000"
|
||||
@ -92,20 +92,20 @@ allExamples = concat
|
||||
, "-1200K"
|
||||
, "-.0012G"
|
||||
]
|
||||
, examples (NumberValue 5000)
|
||||
, examples (NumeralValue 5000)
|
||||
[ "5 nghìn"
|
||||
, "năm nghìn"
|
||||
]
|
||||
, examples (NumberValue 200000)
|
||||
, examples (NumeralValue 200000)
|
||||
[ "hai trăm nghìn"
|
||||
]
|
||||
, examples (NumberValue 1000000000)
|
||||
, examples (NumeralValue 1000000000)
|
||||
[ "một tỷ"
|
||||
]
|
||||
, examples (NumberValue 21011)
|
||||
, examples (NumeralValue 21011)
|
||||
[ "hai mươi mốt nghìn không trăm mười một"
|
||||
]
|
||||
, examples (NumberValue 721012)
|
||||
, examples (NumeralValue 721012)
|
||||
[ "bảy trăm hai mươi mốt nghìn không trăm mười hai"
|
||||
]
|
||||
]
|
@ -9,7 +9,7 @@
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Number.VI.Rules
|
||||
module Duckling.Numeral.VI.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.Maybe
|
||||
@ -18,9 +18,9 @@ import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.Helpers
|
||||
import Duckling.Number.Types (NumberData (..))
|
||||
import qualified Duckling.Number.Types as TNumber
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
|
||||
@ -48,14 +48,14 @@ ruleIntersectWithAnd :: Rule
|
||||
ruleIntersectWithAnd = Rule
|
||||
{ name = "intersect (with and)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, regex "and"
|
||||
, numberWith TNumber.multipliable not
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
_:
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -73,27 +73,27 @@ ruleIntegerNumeric = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersPrefixWithM :: Rule
|
||||
ruleNumbersPrefixWithM = Rule
|
||||
ruleNumeralsPrefixWithM :: Rule
|
||||
ruleNumeralsPrefixWithM = Rule
|
||||
{ name = "numbers prefix with -, âm"
|
||||
, pattern =
|
||||
[ regex "-|\x00e2m\\s?"
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double (TNumber.value nd * (-1))
|
||||
(_:Token Numeral nd:_) -> double (TNumeral.value nd * (-1))
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbers2 :: Rule
|
||||
ruleNumbers2 = Rule
|
||||
ruleNumerals2 :: Rule
|
||||
ruleNumerals2 = Rule
|
||||
{ name = "numbers 25 35 45 55 65 75 85 95"
|
||||
, pattern =
|
||||
[ oneOf [20, 30 .. 90]
|
||||
, regex "l\x0103m"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v + 5
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v + 5
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -109,8 +109,8 @@ ruleDecimalWithThousandsSeparator = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDecimalNumber :: Rule
|
||||
ruleDecimalNumber = Rule
|
||||
ruleDecimalNumeral :: Rule
|
||||
ruleDecimalNumeral = Rule
|
||||
{ name = "decimal number"
|
||||
, pattern =
|
||||
[ regex "(\\d*\\.\\d+)"
|
||||
@ -128,23 +128,23 @@ ruleInteger3 = Rule
|
||||
, numberBetween 1 10
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):
|
||||
Token Numeral (NumberData {TNumber.value = v2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2}):
|
||||
_) -> double $ v1 + v2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberDot :: Rule
|
||||
ruleNumberDot = Rule
|
||||
ruleNumeralDot :: Rule
|
||||
ruleNumeralDot = Rule
|
||||
{ name = "number dot 1 9"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "ch\x1ea5m|ph\x1ea9y"
|
||||
, numberWith TNumber.grain isNothing
|
||||
, numberWith TNumeral.grain isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
double $ TNumber.value nd1 + decimalsToDouble (TNumber.value nd2)
|
||||
double $ TNumeral.value nd1 + decimalsToDouble (TNumeral.value nd2)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -152,12 +152,12 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumber.grain) (>1)
|
||||
, numberWith TNumber.multipliable not
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
, numberWith TNumeral.multipliable not
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = val1, TNumber.grain = Just g}):
|
||||
Token Numeral (NumberData {TNumber.value = val2}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = val1, TNumeral.grain = Just g}):
|
||||
Token Numeral (NumeralData {TNumeral.value = val2}):
|
||||
_) | (10 ** fromIntegral g) > val2 -> double $ val1 + val2
|
||||
_ -> Nothing
|
||||
}
|
||||
@ -167,22 +167,22 @@ ruleMultiply = Rule
|
||||
{ name = "compose by multiplication"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, numberWith TNumber.multipliable id
|
||||
, numberWith TNumeral.multipliable id
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token1:token2:_) -> multiply token1 token2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbersSuffixesKMG :: Rule
|
||||
ruleNumbersSuffixesKMG = Rule
|
||||
ruleNumeralsSuffixesKMG :: Rule
|
||||
ruleNumeralsSuffixesKMG = Rule
|
||||
{ name = "numbers suffixes (K, M, G)"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "([kmg])(?=[\\W\\$\x20ac]|$)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"k" -> double $ v * 1e3
|
||||
@ -192,16 +192,17 @@ ruleNumbersSuffixesKMG = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumberNghn :: Rule
|
||||
ruleNumberNghn = Rule
|
||||
ruleNumeralNghn :: Rule
|
||||
ruleNumeralNghn = Rule
|
||||
{ name = "number nghìn"
|
||||
, pattern =
|
||||
[ numberBetween 1 1000
|
||||
, numberWith TNumber.value (== 1000)
|
||||
, numberWith TNumeral.value (== 1000)
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v1}):Token Numeral (NumberData {TNumber.value = v2, TNumber.grain = Just g}):_) ->
|
||||
double (v1 * v2) >>= withGrain g
|
||||
(Token Numeral (NumeralData {TNumeral.value = v1}):
|
||||
Token Numeral (NumeralData {TNumeral.value = v2, TNumeral.grain = Just g}):
|
||||
_) -> double (v1 * v2) >>= withGrain g
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -277,15 +278,15 @@ ruleInteger2 = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumbers :: Rule
|
||||
ruleNumbers = Rule
|
||||
ruleNumerals :: Rule
|
||||
ruleNumerals = Rule
|
||||
{ name = "numbers 21 31 41 51 61 71 81 91"
|
||||
, pattern =
|
||||
[ oneOf [20, 30 .. 90]
|
||||
, regex "m\x1ed1t"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral (NumberData {TNumber.value = v}):_) -> double $ v + 1
|
||||
(Token Numeral (NumeralData {TNumeral.value = v}):_) -> double $ v + 1
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -313,7 +314,7 @@ ruleIntegerWithThousandsSeparator = Rule
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDecimalNumber
|
||||
[ ruleDecimalNumeral
|
||||
, ruleDecimalWithThousandsSeparator
|
||||
, ruleInteger
|
||||
, ruleInteger2
|
||||
@ -323,12 +324,12 @@ rules =
|
||||
, ruleIntersect
|
||||
, ruleIntersectWithAnd
|
||||
, ruleMultiply
|
||||
, ruleNumberDot
|
||||
, ruleNumberNghn
|
||||
, ruleNumbers
|
||||
, ruleNumbers2
|
||||
, ruleNumbersPrefixWithM
|
||||
, ruleNumbersSuffixesKMG
|
||||
, ruleNumeralDot
|
||||
, ruleNumeralNghn
|
||||
, ruleNumerals
|
||||
, ruleNumerals2
|
||||
, ruleNumeralsPrefixWithM
|
||||
, ruleNumeralsSuffixesKMG
|
||||
, rulePowersOfTen
|
||||
, ruleT
|
||||
]
|
@ -6,7 +6,7 @@
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.Number.VI.Tests
|
||||
module Duckling.Numeral.VI.Tests
|
||||
( tests ) where
|
||||
|
||||
import Prelude
|
||||
@ -14,7 +14,7 @@ import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Number.VI.Corpus
|
||||
import Duckling.Numeral.VI.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user