diff --git a/Dockerfile b/Dockerfile index d357141b5..369f7895f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM haskell:8-buster AS builder RUN apt-get update -qq && \ - apt-get install -qq -y libssl-dev libpcre3 libpcre3-dev build-essential --fix-missing --no-install-recommends && \ + apt-get install -qq -y libssl-dev libpcre3 libpcre3-dev build-essential pkg-config --fix-missing --no-install-recommends && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* diff --git a/Duckling/AmountOfMoney/ZH/Rules.hs b/Duckling/AmountOfMoney/ZH/Rules.hs index 12fbae539..6f7568851 100644 --- a/Duckling/AmountOfMoney/ZH/Rules.hs +++ b/Duckling/AmountOfMoney/ZH/Rules.hs @@ -226,7 +226,7 @@ ruleOneDollarAnd = Rule { name = "one dollar and x dimes (short form)" , pattern = [ regex "個" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \case (_:Token Numeral NumeralData{TNumeral.value = v}:_) -> diff --git a/Duckling/Duration/DE/Rules.hs b/Duckling/Duration/DE/Rules.hs index 405622dc5..5333d38d1 100644 --- a/Duckling/Duration/DE/Rules.hs +++ b/Duckling/Duration/DE/Rules.hs @@ -19,7 +19,7 @@ import Duckling.Regex.Types import Control.Monad (join) import qualified Data.Text as Text import Prelude -import Duckling.Numeral.Helpers (parseInteger) +import Duckling.Numeral.Helpers (numberBetween, parseInteger) import Duckling.Duration.Types (DurationData(..)) import qualified Duckling.Duration.Types as TDuration import Data.String @@ -216,7 +216,7 @@ ruleHoursAndMinutes = Rule , pattern = [ Predicate isNatural , regex "(ein(en?) )?stunden?( und)?" - , Predicate isNatural + , Predicate $ and . sequence [isNatural, numberBetween 1 60] , Predicate $ isGrain TG.Minute ] , prod = \case diff --git a/Duckling/Duration/EN/Rules.hs b/Duckling/Duration/EN/Rules.hs index 639b220b5..06b8a2053 100644 --- a/Duckling/Duration/EN/Rules.hs +++ b/Duckling/Duration/EN/Rules.hs @@ -20,7 +20,7 @@ import qualified Data.Text as Text import Duckling.Dimensions.Types import Duckling.Duration.Helpers import Duckling.Duration.Types (DurationData(..)) -import Duckling.Numeral.Helpers (parseInteger) +import Duckling.Numeral.Helpers (numberBetween, parseInteger) import Duckling.Numeral.Types (NumeralData(..)) import Duckling.Regex.Types import Duckling.Types @@ -180,7 +180,7 @@ ruleDurationHoursAndMinutes = Rule , pattern = [ Predicate isNatural , regex "hours?( and)?" - , Predicate isNatural + , Predicate $ and . sequence [isNatural, numberBetween 1 60] ] , prod = \case (Token Numeral h: diff --git a/Duckling/Numeral/AF/Rules.hs b/Duckling/Numeral/AF/Rules.hs index 99bce9dd4..42f29cc28 100644 --- a/Duckling/Numeral/AF/Rules.hs +++ b/Duckling/Numeral/AF/Rules.hs @@ -124,7 +124,7 @@ ruleCompositeTens :: Rule ruleCompositeTens = Rule { name = "integer ([3-9][1-9])" , pattern = - [ numberBetween 1 10 + [ Predicate $ numberBetween 1 10 , regex "en" , oneOf [20, 30..90] ] diff --git a/Duckling/Numeral/AR/Rules.hs b/Duckling/Numeral/AR/Rules.hs index 37e638dbd..35cdaf04e 100644 --- a/Duckling/Numeral/AR/Rules.hs +++ b/Duckling/Numeral/AR/Rules.hs @@ -42,7 +42,7 @@ ruleInteger23 = Rule , pattern = [ oneOf [100, 200 .. 900] , regex "و" - , numberBetween 1 100 + , Predicate $ numberBetween 1 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -86,7 +86,7 @@ ruleInteger22 :: Rule ruleInteger22 = Rule { name = "integer 21..99" , pattern = - [ numberBetween 1 10 + [ Predicate $ numberBetween 1 10 , regex "و" , oneOf [20, 30 .. 90] ] @@ -102,7 +102,7 @@ ruleInteger21 :: Rule ruleInteger21 = Rule { name = "integer (13..19)" , pattern = - [ numberBetween 3 10 + [ Predicate $ numberBetween 3 10 , numberWith TNumeral.value (== 10) ] , prod = \tokens -> case tokens of diff --git a/Duckling/Numeral/BG/Rules.hs b/Duckling/Numeral/BG/Rules.hs index c5383b868..ebfa12e77 100644 --- a/Duckling/Numeral/BG/Rules.hs +++ b/Duckling/Numeral/BG/Rules.hs @@ -111,7 +111,7 @@ ruleCompositeTens = Rule , pattern = [ oneOf [20, 30..90] , regex "и" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = tens}: @@ -147,7 +147,7 @@ ruleCompositeHundreds = Rule { name = "integer 101..999" , pattern = [ oneOf [200, 300..900] - , numberBetween 1 100 + , Predicate $ numberBetween 1 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = hundreds}: diff --git a/Duckling/Numeral/CA/Rules.hs b/Duckling/Numeral/CA/Rules.hs index db6e6104c..9ad3536b3 100644 --- a/Duckling/Numeral/CA/Rules.hs +++ b/Duckling/Numeral/CA/Rules.hs @@ -140,7 +140,10 @@ ruleHigherTensWithOnes :: Rule ruleHigherTensWithOnes = Rule { name = "number (31..39 41..49 51..59 61..69 71..79 81..89 91..99)" , pattern = - [oneOf [30, 40, 50, 60, 70, 80, 90], regex "-", numberBetween 1 9] + [ oneOf [30, 40, 50, 60, 70, 80, 90] + , regex "-" + , Predicate $ numberBetween 1 9 + ] , prod = \case (Token Numeral NumeralData{TNumeral.value = v1}: _: @@ -185,7 +188,10 @@ ruleTwenties :: Rule ruleTwenties = Rule { name = "number (21..29)" , pattern = - [oneOf [20], regex "(-i-| i )", numberBetween 1 10] + [ oneOf [20] + , regex "(-i-| i )" + , Predicate $ numberBetween 1 10 + ] , prod = \case (Token Numeral NumeralData{TNumeral.value = v1}: _: @@ -212,10 +218,10 @@ ruleNumerals :: Rule ruleNumerals = Rule { name = "numbers 200..999" , pattern = - [ numberBetween 2 10 + [ Predicate $ numberBetween 2 10 , regex "-" , numberWith TNumeral.value (== 100) - , numberBetween 0 100 + , Predicate $ numberBetween 0 100 ] , prod = \case (Token Numeral NumeralData{TNumeral.value = v1}: @@ -242,7 +248,7 @@ ruleBelowTenWithTwoDigits = Rule { name = "integer (0-9) with two digits" , pattern = [ regex "zero|0" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \case (_:Token Numeral NumeralData{TNumeral.value = v}:_) -> double v diff --git a/Duckling/Numeral/DA/Rules.hs b/Duckling/Numeral/DA/Rules.hs index e60dd886e..6568e71e0 100644 --- a/Duckling/Numeral/DA/Rules.hs +++ b/Duckling/Numeral/DA/Rules.hs @@ -87,7 +87,7 @@ ruleInteger3 = Rule { name = "integer 21..99" , pattern = [ oneOf [20, 30 .. 90] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -170,7 +170,7 @@ ruleNumeralsOg :: Rule ruleNumeralsOg = Rule { name = "numbers og" , pattern = - [ numberBetween 1 10 + [ Predicate $ numberBetween 1 10 , regex "og" , oneOf [70, 20, 60, 50, 40, 90, 30, 80] ] diff --git a/Duckling/Numeral/DE/Corpus.hs b/Duckling/Numeral/DE/Corpus.hs index be6e2d3a7..4149ccd5d 100644 --- a/Duckling/Numeral/DE/Corpus.hs +++ b/Duckling/Numeral/DE/Corpus.hs @@ -140,6 +140,10 @@ allExamples = concat [ "1.416,15" ] , examples (NumeralValue 1000000.0) - [ "1.000.000,00" + [ "1.000.000,00", + "eine million" + ] + , examples (NumeralValue 2771090092000000.0) + [ "zwei billiarden sieben hundert ein und siebzig billionen neunzig milliarden zwei und neunzig millionen" ] ] diff --git a/Duckling/Numeral/DE/Rules.hs b/Duckling/Numeral/DE/Rules.hs index e551aeb3e..93581e76f 100644 --- a/Duckling/Numeral/DE/Rules.hs +++ b/Duckling/Numeral/DE/Rules.hs @@ -123,7 +123,7 @@ ruleNumeralsUnd :: Rule ruleNumeralsUnd = Rule { name = "numbers und" , pattern = - [ numberBetween 1 10 + [ Predicate $ numberBetween 1 10 , regex "und" , oneOf [20, 30 .. 90] ] @@ -201,17 +201,23 @@ rulePowersOfTen :: Rule rulePowersOfTen = Rule { name = "powers of tens" , pattern = - [ regex "(hunderte?|tausende?|million(en)?)" + [ regex "(hunderte?|tausende?|million(en)?|milliarde(n)?|billion(en)?|billiarde(n)?)" ] , prod = \tokens -> case tokens of (Token RegexMatch (GroupMatch (match:_)):_) -> case Text.toLower match of - "hundert" -> double 1e2 >>= withGrain 2 >>= withMultipliable - "hunderte" -> double 1e2 >>= withGrain 2 >>= withMultipliable - "tausend" -> double 1e3 >>= withGrain 3 >>= withMultipliable - "tausende" -> double 1e3 >>= withGrain 3 >>= withMultipliable - "million" -> double 1e6 >>= withGrain 6 >>= withMultipliable - "millionen" -> double 1e6 >>= withGrain 6 >>= withMultipliable - _ -> Nothing + "hundert" -> double 1e2 >>= withGrain 2 >>= withMultipliable + "hunderte" -> double 1e2 >>= withGrain 2 >>= withMultipliable + "tausend" -> double 1e3 >>= withGrain 3 >>= withMultipliable + "tausende" -> double 1e3 >>= withGrain 3 >>= withMultipliable + "million" -> double 1e6 >>= withGrain 6 >>= withMultipliable + "millionen" -> double 1e6 >>= withGrain 6 >>= withMultipliable + "milliarde" -> double 1e9 >>= withGrain 9 >>= withMultipliable + "milliarden" -> double 1e9 >>= withGrain 9 >>= withMultipliable + "billion" -> double 1e12 >>= withGrain 12 >>= withMultipliable + "billionen" -> double 1e12 >>= withGrain 12 >>= withMultipliable + "billiarde" -> double 1e15 >>= withGrain 15 >>= withMultipliable + "billiarden" -> double 1e15 >>= withGrain 15 >>= withMultipliable + _ -> Nothing _ -> Nothing } @@ -255,7 +261,7 @@ ruleZeroToNineteen :: Rule ruleZeroToNineteen = Rule { name = "integer (0..19)" , pattern = - [ regex "(keine[rn]|keine?s?|null|nichts|eins?(er)?|zwei|dreizehn|drei|vierzehn|vier|fünfzehn|fünf|sechzehn|sechs|siebzehn|sieben|achtzehn|acht|neunzehn|neun|elf|zwölf)" + [ regex "(keine[rn]|keine?s?|null|nichts|eins?(er?)?|zwei|dreizehn|drei|vierzehn|vier|fünfzehn|fünf|sechzehn|sechs|siebzehn|sieben|achtzehn|acht|neunzehn|neun|elf|zwölf)" ] , prod = \tokens -> case tokens of (Token RegexMatch (GroupMatch (match:_)):_) -> diff --git a/Duckling/Numeral/EL/Rules.hs b/Duckling/Numeral/EL/Rules.hs index 266490a3d..85fd5edbe 100644 --- a/Duckling/Numeral/EL/Rules.hs +++ b/Duckling/Numeral/EL/Rules.hs @@ -123,7 +123,7 @@ ruleCompositeTens = Rule { name = "integer 21..99" , pattern = [ oneOf [20,30..90] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = tens} : diff --git a/Duckling/Numeral/EN/Rules.hs b/Duckling/Numeral/EN/Rules.hs index a328184d4..4422458b5 100644 --- a/Duckling/Numeral/EN/Rules.hs +++ b/Duckling/Numeral/EN/Rules.hs @@ -161,7 +161,7 @@ ruleCompositeTens = Rule , pattern = [ oneOf [20,30..90] , regex "[\\s\\-]+" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = tens}: diff --git a/Duckling/Numeral/ES/Rules.hs b/Duckling/Numeral/ES/Rules.hs index 636845b8b..8638a4a14 100644 --- a/Duckling/Numeral/ES/Rules.hs +++ b/Duckling/Numeral/ES/Rules.hs @@ -69,9 +69,8 @@ ruleBelowTenWithTwoDigits = Rule { name = "integer (0-9) with two digits" , pattern = - [ - regex "((c|z)ero)|0" - , numberBetween 1 10 + [ regex "((c|z)ero)|0" + , Predicate $ numberBetween 1 10 ] , prod = \case ( @@ -124,12 +123,17 @@ ruleNumeralSixteenToTwentyNine = Rule ruleNumeralSixteenToNineteenWithDiez :: Rule ruleNumeralSixteenToNineteenWithDiez = Rule { name = "number (16..19, two words)" - , pattern = [numberWith TNumeral.value (== 10), regex "y", numberBetween 6 10] + , pattern = + [ numberWith TNumeral.value (== 10) + , regex "y" + , Predicate $ numberBetween 6 10 + ] , prod = \case (_ : _ : Token Numeral NumeralData { TNumeral.value = v } : _) -> double $ 10 + v _ -> Nothing } + byTensMap :: HashMap.HashMap Text.Text Integer byTensMap = HashMap.fromList @@ -161,7 +165,10 @@ ruleNumeralTwentyOneToNinetyNine :: Rule ruleNumeralTwentyOneToNinetyNine = Rule { name = "number (21..29 31..39 41..49 51..59 61..69 71..79 81..89 91..99)" , pattern = - [oneOf [20, 30 .. 90], regex "y", numberBetween 1 10] + [ oneOf [20, 30 .. 90] + , regex "y" + , Predicate $ numberBetween 1 10 + ] , prod = \case (Token Numeral NumeralData { TNumeral.value = v1 } : _ : Token Numeral NumeralData { TNumeral.value = v2 } : _) -> double $ v1 + v2 @@ -221,7 +228,7 @@ ruleTwoPartHundreds :: Rule ruleTwoPartHundreds = Rule { name = "2..9 cientos" , pattern = - [ numberBetween 2 10 + [ Predicate $ numberBetween 2 10 , regex "cientos" ] , prod = \case @@ -235,7 +242,7 @@ ruleNumeralHundredsAndSmaller = Rule { name = " 0..99" , pattern = [ numberWith TNumeral.value (TNumeral.isMultiple 100) - , numberBetween 0 100 + , Predicate $ numberBetween 0 100 ] , prod = \case (Token Numeral NumeralData { TNumeral.value = v1 } : Token Numeral NumeralData { TNumeral.value = v2 } : _) @@ -247,7 +254,7 @@ ruleNumeralMultiply :: Rule ruleNumeralMultiply = Rule { name = "2..999 " , pattern = - [ numberBetween 2 1000 + [ Predicate $ numberBetween 2 1000 , Predicate isMultipliable ] , prod = \case @@ -261,7 +268,7 @@ ruleNumeralThousandsAnd = Rule { name = " 0..999" , pattern = [ numberWith TNumeral.value (TNumeral.isMultiple 1000) - , numberBetween 0 999 + , Predicate $ numberBetween 0 999 ] , prod = \case (Token Numeral NumeralData { TNumeral.value = v1 } : Token Numeral NumeralData { TNumeral.value = v2 } : _) @@ -274,7 +281,7 @@ ruleNumeralMillionsAnd = Rule { name = " 0..999999" , pattern = [ numberWith TNumeral.value (TNumeral.isMultiple 1000000) - , numberBetween 0 999999 + , Predicate $ numberBetween 0 999999 ] , prod = \case (Token Numeral NumeralData { TNumeral.value = v1 } : Token Numeral NumeralData { TNumeral.value = v2 } : _) diff --git a/Duckling/Numeral/ET/Rules.hs b/Duckling/Numeral/ET/Rules.hs index 51ac86d91..3deb0b11e 100644 --- a/Duckling/Numeral/ET/Rules.hs +++ b/Duckling/Numeral/ET/Rules.hs @@ -87,7 +87,7 @@ ruleInteger3 = Rule { name = "integer 21..99" , pattern = [ oneOf [70, 20, 60, 50, 40, 90, 30, 80] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/FA/Rules.hs b/Duckling/Numeral/FA/Rules.hs index 1e08cbeb3..f58d9d246 100644 --- a/Duckling/Numeral/FA/Rules.hs +++ b/Duckling/Numeral/FA/Rules.hs @@ -135,7 +135,7 @@ ruleCompositeTens = Rule , pattern = [ oneOf [20,30..90] , regex "و" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = tens}: @@ -151,7 +151,7 @@ ruleCompositeHundred = Rule , pattern = [ oneOf [100,200..900] , regex "و" - , numberBetween 1 100 + , Predicate $ numberBetween 1 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = tens}: diff --git a/Duckling/Numeral/FR/Rules.hs b/Duckling/Numeral/FR/Rules.hs index 5c8a1d840..6529af5c3 100644 --- a/Duckling/Numeral/FR/Rules.hs +++ b/Duckling/Numeral/FR/Rules.hs @@ -57,7 +57,7 @@ ruleNumerals2 = Rule , pattern = [ oneOf [20, 50, 40, 30] , regex "[\\s\\-]+" - , numberBetween 2 10 + , Predicate $ numberBetween 2 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -119,7 +119,7 @@ ruleNumerals5 = Rule , pattern = [ oneOf [60, 80] , regex "[\\s\\-]+" - , numberBetween 2 20 + , Predicate $ numberBetween 2 20 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -170,7 +170,7 @@ ruleNumeral3 = Rule , pattern = [ numberWith TNumeral.value (== 10) , regex "[\\s\\-]+" - , numberBetween 7 10 + , Predicate $ numberBetween 7 10 ] , prod = \tokens -> case tokens of (_: diff --git a/Duckling/Numeral/HE/Rules.hs b/Duckling/Numeral/HE/Rules.hs index c213cc18c..87a8d07f7 100644 --- a/Duckling/Numeral/HE/Rules.hs +++ b/Duckling/Numeral/HE/Rules.hs @@ -68,7 +68,7 @@ ruleCompositeTens = Rule { name = "integer 21..99" , pattern = [ oneOf [ 20, 30..90 ] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = tens}: @@ -83,7 +83,7 @@ ruleCompositeTensWithAnd = Rule , pattern = [ oneOf [ 20, 30..90 ] , regex "ו" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = tens}: @@ -230,7 +230,7 @@ ruleInteger14 :: Rule ruleInteger14 = Rule { name = "integer 11..19" , pattern = - [ numberBetween 1 10 + [ Predicate $ numberBetween 1 10 , numberWith TNumeral.value (== 10) ] , prod = \tokens -> case tokens of @@ -263,7 +263,7 @@ ruleInteger16 = Rule { name = "integer 101..999" , pattern = [ oneOf [300, 600, 500, 100, 800, 200, 900, 700, 400] - , numberBetween 1 100 + , Predicate $ numberBetween 1 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/HI/Rules.hs b/Duckling/Numeral/HI/Rules.hs index 3c20e888d..d3a7bdc3d 100644 --- a/Duckling/Numeral/HI/Rules.hs +++ b/Duckling/Numeral/HI/Rules.hs @@ -222,7 +222,7 @@ ruleCompositeHundreds = Rule , pattern = [ oneOf [100,200..5000] , regex "[\\s\\-]+" - , numberBetween 1 99 + , Predicate $ numberBetween 1 99 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = hundreds}: @@ -239,7 +239,7 @@ ruleCompositeThousands = Rule , pattern = [ oneOf [1000,2000..50000] , regex "[\\s\\-]+" - , numberBetween 1 999 + , Predicate $ numberBetween 1 999 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = thousands}: diff --git a/Duckling/Numeral/HR/Rules.hs b/Duckling/Numeral/HR/Rules.hs index e854d6196..2bb039e5b 100644 --- a/Duckling/Numeral/HR/Rules.hs +++ b/Duckling/Numeral/HR/Rules.hs @@ -143,7 +143,7 @@ ruleNumbersI = Rule , pattern = [ oneOf [70, 20, 60, 50, 40, 90, 30, 80] , regex "i" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -255,7 +255,7 @@ ruleInteger4 = Rule { name = "integer 21..99" , pattern = [ oneOf [70, 20, 60, 50, 40, 90, 30, 80] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -290,9 +290,9 @@ ruleNumbers :: Rule ruleNumbers = Rule { name = "numbers 100..999" , pattern = - [ numberBetween 1 10 + [ Predicate $ numberBetween 1 10 , numberWith TNumeral.value (== 100) - , numberBetween 0 100 + , Predicate $ numberBetween 0 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/Helpers.hs b/Duckling/Numeral/Helpers.hs index 6c1da0408..b6d834db6 100644 --- a/Duckling/Numeral/Helpers.hs +++ b/Duckling/Numeral/Helpers.hs @@ -101,12 +101,10 @@ numberWith f pred = Predicate $ \x -> (Token Numeral x@NumeralData{}) -> pred (f x) _ -> False -numberBetween :: Double -> Double -> PatternItem -numberBetween low up = Predicate $ \x -> - case x of - (Token Numeral NumeralData {value = v, multipliable = False}) -> - low <= v && v < up - _ -> False +numberBetween :: Double -> Double -> Predicate +numberBetween low up (Token Numeral NumeralData {value = v, multipliable = False}) = + low <= v && v < up +numberBetween _ _ _ = False isNatural :: Predicate isNatural (Token Numeral NumeralData {value = v}) = diff --git a/Duckling/Numeral/ID/Rules.hs b/Duckling/Numeral/ID/Rules.hs index 4878065da..3f6c09c9e 100644 --- a/Duckling/Numeral/ID/Rules.hs +++ b/Duckling/Numeral/ID/Rules.hs @@ -47,7 +47,7 @@ ruleTeen :: Rule ruleTeen = Rule { name = "teen" , pattern = - [ numberBetween 2 10 + [ Predicate $ numberBetween 2 10 , regex "belas" ] , prod = \tokens -> case tokens of @@ -132,7 +132,7 @@ ruleInteger3 = Rule { name = "integer 21..99" , pattern = [ oneOf [70, 20, 60, 50, 40, 90, 30, 80] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -222,7 +222,7 @@ ruleInteger2 :: Rule ruleInteger2 = Rule { name = "integer 20..90" , pattern = - [ numberBetween 2 10 + [ Predicate $ numberBetween 2 10 , numberWith TNumeral.value (== 10) ] , prod = \tokens -> case tokens of diff --git a/Duckling/Numeral/IT/Rules.hs b/Duckling/Numeral/IT/Rules.hs index 2e2194ade..1bf989935 100644 --- a/Duckling/Numeral/IT/Rules.hs +++ b/Duckling/Numeral/IT/Rules.hs @@ -159,7 +159,7 @@ ruleNumeral3 = Rule , pattern = [ oneOf [70, 20, 60, 50, 40, 90, 30, 80] , regex "e" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -287,9 +287,9 @@ ruleNumerals :: Rule ruleNumerals = Rule { name = "numbers 200..999" , pattern = - [ numberBetween 2 10 + [ Predicate $ numberBetween 2 10 , numberWith TNumeral.value (== 100) - , numberBetween 0 100 + , Predicate $ numberBetween 0 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/JA/Rules.hs b/Duckling/Numeral/JA/Rules.hs index 1acb0217f..76b8fd2f4 100644 --- a/Duckling/Numeral/JA/Rules.hs +++ b/Duckling/Numeral/JA/Rules.hs @@ -52,7 +52,7 @@ ruleInteger10 = Rule { name = "integer (1000..1999)" , pattern = [ regex "千" - , numberBetween 1 1000 + , Predicate $ numberBetween 1 1000 ] , prod = \tokens -> case tokens of (_:Token Numeral NumeralData{TNumeral.value = v}:_) -> @@ -76,7 +76,7 @@ ruleInteger15 :: Rule ruleInteger15 = Rule { name = "integer (20000..90000)" , pattern = - [ numberBetween 2 10 + [ Predicate $ numberBetween 2 10 , regex "万" ] , prod = \tokens -> case tokens of @@ -111,7 +111,7 @@ ruleInteger3 :: Rule ruleInteger3 = Rule { name = "integer (20..90)" , pattern = - [ numberBetween 2 10 + [ Predicate $ numberBetween 2 10 , regex "十" ] , prod = \tokens -> case tokens of @@ -133,7 +133,7 @@ ruleInteger6 = Rule { name = "integer (100..199)" , pattern = [ regex "百" - , numberBetween 1 100 + , Predicate $ numberBetween 1 100 ] , prod = \tokens -> case tokens of (_:Token Numeral NumeralData{TNumeral.value = v}:_) -> double $ v + 100 @@ -145,7 +145,7 @@ ruleInteger12 = Rule { name = "integer 2001..9999" , pattern = [ oneOf [3000, 9000, 7000, 8000, 2000, 4000, 6000, 5000] - , numberBetween 1 1000 + , Predicate $ numberBetween 1 1000 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -178,7 +178,7 @@ ruleInteger7 :: Rule ruleInteger7 = Rule { name = "integer (200..900)" , pattern = - [ numberBetween 2 10 + [ Predicate $ numberBetween 2 10 , regex "百" ] , prod = \tokens -> case tokens of @@ -191,7 +191,7 @@ ruleInteger14 = Rule { name = "integer (10000..19999)" , pattern = [ regex "万" - , numberBetween 1 10000 + , Predicate $ numberBetween 1 10000 ] , prod = \tokens -> case tokens of (_:Token Numeral NumeralData{TNumeral.value = v}:_) -> @@ -204,7 +204,7 @@ ruleInteger8 = Rule { name = "integer 201..999" , pattern = [ oneOf [300, 600, 500, 800, 200, 900, 700, 400] - , numberBetween 1 100 + , Predicate $ numberBetween 1 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -218,7 +218,7 @@ ruleInteger16 = Rule { name = "integer 20001..99999" , pattern = [ oneOf [20000, 40000, 80000, 60000, 30000, 70000, 90000, 50000] - , numberBetween 1 10000 + , Predicate $ numberBetween 1 10000 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -269,7 +269,7 @@ ruleInteger4 = Rule { name = "integer 21..99" , pattern = [ oneOf [70, 20, 60, 50, 40, 90, 30, 80] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -283,7 +283,7 @@ ruleInteger2 = Rule { name = "integer (11..19)" , pattern = [ regex "十" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (_:Token Numeral NumeralData{TNumeral.value = v}:_) -> double $ v + 10 @@ -294,7 +294,7 @@ ruleInteger11 :: Rule ruleInteger11 = Rule { name = "integer (2000..9000)" , pattern = - [ numberBetween 2 10 + [ Predicate $ numberBetween 2 10 , regex "千" ] , prod = \tokens -> case tokens of diff --git a/Duckling/Numeral/KA/Rules.hs b/Duckling/Numeral/KA/Rules.hs index a079ef8e1..d0d3276d4 100644 --- a/Duckling/Numeral/KA/Rules.hs +++ b/Duckling/Numeral/KA/Rules.hs @@ -209,7 +209,7 @@ ruleCompositeTens = Rule { name = "integer 21..99" , pattern = [ oneOf [20,40..90] - , numberBetween 1 20 + , Predicate $ numberBetween 1 20 ] , prod = \case (Token Numeral NumeralData{TNumeral.value = tens}: @@ -224,7 +224,7 @@ ruleCompositeHundreds = Rule , pattern = [ oneOf [100,200..900] , oneOf [20,40..90] - , numberBetween 1 20 + , Predicate $ numberBetween 1 20 ] , prod = \case (Token Numeral NumeralData{TNumeral.value = hundreds}: @@ -239,7 +239,7 @@ ruleCompositeHundredsAndUnits = Rule { name = "integer 100..999" , pattern = [ oneOf [100,200..900] - , numberBetween 1 20 + , Predicate $ numberBetween 1 20 ] , prod = \case (Token Numeral NumeralData{TNumeral.value = hundreds}: diff --git a/Duckling/Numeral/MN/Rules.hs b/Duckling/Numeral/MN/Rules.hs index afe92267a..397795c19 100644 --- a/Duckling/Numeral/MN/Rules.hs +++ b/Duckling/Numeral/MN/Rules.hs @@ -112,7 +112,7 @@ ruleNumeralsUnd = Rule { name = "numbers und" , pattern = [ oneOf [20, 30 .. 90] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/MY/Rules.hs b/Duckling/Numeral/MY/Rules.hs index 5bed84f82..bc041152d 100644 --- a/Duckling/Numeral/MY/Rules.hs +++ b/Duckling/Numeral/MY/Rules.hs @@ -29,9 +29,9 @@ ruleInteger5 :: Rule ruleInteger5 = Rule { name = "integer (11..99) " , pattern = - [ numberBetween 1 10 + [ Predicate $ numberBetween 1 10 , regex "ဆယ့်" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -72,7 +72,7 @@ ruleInteger3 = Rule { name = "integer (11..19) " , pattern = [ regex "ဆယ့်" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (_:Token Numeral NumeralData{TNumeral.value = v}:_) -> double $ v + 10 @@ -102,7 +102,7 @@ ruleInteger6 :: Rule ruleInteger6 = Rule { name = "integer (100..900)" , pattern = - [ numberBetween 1 10 + [ Predicate $ numberBetween 1 10 , regex "ရာ" ] , prod = \tokens -> case tokens of @@ -114,7 +114,7 @@ ruleInteger7 :: Rule ruleInteger7 = Rule { name = "integer (1000..9000)" , pattern = - [ numberBetween 1 10 + [ Predicate $ numberBetween 1 10 , regex "ထောင်" ] , prod = \tokens -> case tokens of @@ -126,7 +126,7 @@ ruleInteger8 :: Rule ruleInteger8 = Rule { name = "integer (10000..90000)" , pattern = - [ numberBetween 1 10 + [ Predicate $ numberBetween 1 10 , regex "သောင်း" ] , prod = \tokens -> case tokens of @@ -147,7 +147,7 @@ ruleInteger4 :: Rule ruleInteger4 = Rule { name = "integer (10..90)" , pattern = - [ numberBetween 1 10 + [ Predicate $ numberBetween 1 10 , regex "ဆယ်" ] , prod = \tokens -> case tokens of diff --git a/Duckling/Numeral/NB/Rules.hs b/Duckling/Numeral/NB/Rules.hs index 70663b245..8f2fc71ba 100644 --- a/Duckling/Numeral/NB/Rules.hs +++ b/Duckling/Numeral/NB/Rules.hs @@ -107,7 +107,7 @@ ruleInteger3 = Rule { name = "integer 21..99" , pattern = [ oneOf [70, 20, 60, 50, 40, 90, 30, 80] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \case (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/NL/Rules.hs b/Duckling/Numeral/NL/Rules.hs index 76e1314a8..927447334 100644 --- a/Duckling/Numeral/NL/Rules.hs +++ b/Duckling/Numeral/NL/Rules.hs @@ -146,7 +146,7 @@ ruleNumeralsEn :: Rule ruleNumeralsEn = Rule { name = "numbers en" , pattern = - [ numberBetween 1 10 + [ Predicate $ numberBetween 1 10 , regex "-?en-?" , oneOf [20, 30 .. 90] ] diff --git a/Duckling/Numeral/PL/Rules.hs b/Duckling/Numeral/PL/Rules.hs index 74935e415..ac3321845 100644 --- a/Duckling/Numeral/PL/Rules.hs +++ b/Duckling/Numeral/PL/Rules.hs @@ -137,8 +137,8 @@ ruleSpecialCompositionForMissingHundredsLikeInOneTwentyTwo :: Rule ruleSpecialCompositionForMissingHundredsLikeInOneTwentyTwo = Rule { name = "special composition for missing hundreds like in one twenty two" , pattern = - [ numberBetween 1 10 - , numberBetween 10 100 + [ Predicate $ numberBetween 1 10 + , Predicate $ numberBetween 10 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -516,7 +516,7 @@ ruleInteger2 = Rule { name = "integer 21..99" , pattern = [ oneOf [20, 30 .. 90] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/PT/Rules.hs b/Duckling/Numeral/PT/Rules.hs index abcb72e1d..cf6906057 100644 --- a/Duckling/Numeral/PT/Rules.hs +++ b/Duckling/Numeral/PT/Rules.hs @@ -173,7 +173,7 @@ ruleCompositeTens = Rule { name = "integer 21..99" , pattern = [ oneOf [20,30..90] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = tens}: @@ -188,7 +188,7 @@ ruleDecsAnd = Rule , pattern = [ oneOf [20, 30..90] , regex "e" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -203,7 +203,7 @@ ruleCompositeCents = Rule { name = "integer 101..999" , pattern = [ oneOf [100, 200..900] - , numberBetween 1 100 + , Predicate $ numberBetween 1 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = hundreds}: @@ -218,7 +218,7 @@ ruleCentsAnd = Rule , pattern = [ oneOf [100, 200..900] , regex "e" - , numberBetween 1 100 + , Predicate $ numberBetween 1 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -232,8 +232,8 @@ ruleSkipHundreds :: Rule ruleSkipHundreds = Rule { name = "one twenty two" , pattern = - [ numberBetween 1 10 - , numberBetween 10 100 + [ Predicate $ numberBetween 1 10 + , Predicate $ numberBetween 10 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = hundreds}: diff --git a/Duckling/Numeral/RO/Rules.hs b/Duckling/Numeral/RO/Rules.hs index b93896bb0..9c2765565 100644 --- a/Duckling/Numeral/RO/Rules.hs +++ b/Duckling/Numeral/RO/Rules.hs @@ -69,7 +69,7 @@ ruleInteger3 = Rule { name = "integer 21..99" , pattern = [ oneOf [20, 30 .. 90] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \case (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/RU/Rules.hs b/Duckling/Numeral/RU/Rules.hs index d196f8357..ab516c9f1 100644 --- a/Duckling/Numeral/RU/Rules.hs +++ b/Duckling/Numeral/RU/Rules.hs @@ -179,7 +179,7 @@ ruleInteger7 = Rule { name = "integer 21..99" , pattern = [ oneOf [70, 20, 60, 50, 40, 90, 30, 80] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -193,7 +193,7 @@ ruleInteger8 = Rule { name = "integer 101..999" , pattern = [ oneOf [300, 600, 500, 100, 800, 200, 900, 700, 400] - , numberBetween 1 100 + , Predicate $ numberBetween 1 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/SK/Rules.hs b/Duckling/Numeral/SK/Rules.hs index 2e2068f2e..327234dfb 100644 --- a/Duckling/Numeral/SK/Rules.hs +++ b/Duckling/Numeral/SK/Rules.hs @@ -98,7 +98,7 @@ ruleIntegerCompositeTens = Rule { name = "integer 21..99" , pattern = [ oneOf [20, 30..90] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \case (Token Numeral NumeralData{TNumeral.value = tens}: diff --git a/Duckling/Numeral/SV/Rules.hs b/Duckling/Numeral/SV/Rules.hs index fc9612e6e..182ec7ba5 100644 --- a/Duckling/Numeral/SV/Rules.hs +++ b/Duckling/Numeral/SV/Rules.hs @@ -96,7 +96,7 @@ ruleInteger3 = Rule { name = "integer 21..99" , pattern = [ oneOf [70, 20, 60, 50, 40, 90, 30, 80] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/SW/Rules.hs b/Duckling/Numeral/SW/Rules.hs index 16f5df5ca..df533441a 100644 --- a/Duckling/Numeral/SW/Rules.hs +++ b/Duckling/Numeral/SW/Rules.hs @@ -87,7 +87,7 @@ ruleCompositeTens = Rule { name = "integer 11..19 21..29 .. 91..99" , pattern = [oneOf [20,30..90] , regex "-?na-?" - , numberBetween 1 10] + , Predicate $ numberBetween 1 10] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: Token Numeral NumeralData{TNumeral.value = v2}: diff --git a/Duckling/Numeral/TH/Rules.hs b/Duckling/Numeral/TH/Rules.hs index 0d8c14e1d..1c8c321ea 100644 --- a/Duckling/Numeral/TH/Rules.hs +++ b/Duckling/Numeral/TH/Rules.hs @@ -246,7 +246,7 @@ ruleCompositeTens = Rule , pattern = [ oneOf [20,30..90] , regex "[\\s\\-]+" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \case (Token Numeral NumeralData{TNumeral.value = tens}: diff --git a/Duckling/Numeral/TR/Rules.hs b/Duckling/Numeral/TR/Rules.hs index 8aa98ad3a..5bbf715bd 100644 --- a/Duckling/Numeral/TR/Rules.hs +++ b/Duckling/Numeral/TR/Rules.hs @@ -607,7 +607,7 @@ ruleInteger4 = Rule { name = "integer 11..99" , pattern = [ oneOf [70, 20, 60, 50, 40, 90, 30, 10, 80] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/UK/Rules.hs b/Duckling/Numeral/UK/Rules.hs index 03bbb3935..6bde60551 100644 --- a/Duckling/Numeral/UK/Rules.hs +++ b/Duckling/Numeral/UK/Rules.hs @@ -145,7 +145,7 @@ ruleInteger7 = Rule { name = "integer 21..99" , pattern = [ oneOf [70, 20, 60, 50, 40, 90, 30, 80] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: @@ -159,7 +159,7 @@ ruleInteger8 = Rule { name = "integer 101..999" , pattern = [ oneOf [300, 600, 500, 100, 800, 200, 900, 700, 400] - , numberBetween 1 100 + , Predicate $ numberBetween 1 100 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/VI/Rules.hs b/Duckling/Numeral/VI/Rules.hs index 9241261f6..e5fc154a1 100644 --- a/Duckling/Numeral/VI/Rules.hs +++ b/Duckling/Numeral/VI/Rules.hs @@ -101,7 +101,7 @@ ruleInteger3 = Rule { name = "integer 21..99" , pattern = [ oneOf [20, 30 .. 90] - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = v1}: diff --git a/Duckling/Numeral/ZH/Rules.hs b/Duckling/Numeral/ZH/Rules.hs index bffb23fe3..5d554d426 100644 --- a/Duckling/Numeral/ZH/Rules.hs +++ b/Duckling/Numeral/ZH/Rules.hs @@ -92,7 +92,7 @@ ruleCompositeTens = Rule , pattern = [ oneOf [20,30,40] , regex "[\\s\\-]+" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \tokens -> case tokens of (Token Numeral NumeralData{TNumeral.value = tens}: @@ -324,7 +324,7 @@ ruleHundredPrefix = Rule { name = "one hundred and (short form)" , pattern = [ regex "百|佰" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \case (_:Token Numeral NumeralData{TNumeral.value = v}:_) -> @@ -337,7 +337,7 @@ ruleThousandPrefix = Rule { name = "one thousand and (short form)" , pattern = [ regex "千|仟" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \case (_:Token Numeral NumeralData{TNumeral.value = v}:_) -> @@ -350,7 +350,7 @@ ruleTenThousandPrefix = Rule { name = "ten thousand and (short form)" , pattern = [ regex "万|萬" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 ] , prod = \case (_:Token Numeral NumeralData{TNumeral.value = v}:_) -> diff --git a/Duckling/Ordinal/RU/Corpus.hs b/Duckling/Ordinal/RU/Corpus.hs index 33e4d3000..fea86b12a 100644 --- a/Duckling/Ordinal/RU/Corpus.hs +++ b/Duckling/Ordinal/RU/Corpus.hs @@ -30,6 +30,7 @@ allExamples = concat , "первое" , "первой" , "первого" + , "первые" , "1ая" , "1-ая" , "1ый" @@ -40,6 +41,11 @@ allExamples = concat , "1-й" , "1го" , "1-го" + , "1-ого" + , "первой" + , "первым" + , "первому" + , "первым" ] , examples (OrdinalData 3) [ "третий" @@ -47,6 +53,7 @@ allExamples = concat , "третье" , "третьей" , "третьего" + , "третьи" , "3й" , "3ий" , "3я" @@ -61,6 +68,11 @@ allExamples = concat , "3-е" , "3-ье" , "3-го" + , "3-его" + , "третьей" + , "третьим" + , "третьему" + , "третьим" ] , examples (OrdinalData 4) [ "четвертый" @@ -68,6 +80,8 @@ allExamples = concat , "четвертое" , "четвертой" , "четвертого" + , "четвёртый" + , "четвертые" , "4й" , "4ый" , "4ая" @@ -80,39 +94,102 @@ allExamples = concat , "4-ое" , "4-ой" , "4-го" + , "4-ого" + , "четвертой" + , "четвертым" + , "четвёртому" + , "четвёртым" ] , examples (OrdinalData 15) [ "пятнадцатый" , "15й" , "15-й" + , "15-ый" + , "пятнадцатая" + , "15я" + , "15-я" + , "15-ая" + , "пятнадцатое" + , "15е" + , "15-е" + , "15-ое" + , "пятнадцатому" + , "пятнадцатые" + , "пятнадцатой" + , "пятнадцатым" + , "пятнадцатому" + , "пятнадцатым" + ] + , examples (OrdinalData 10) + [ "десятый" + , "10й" + , "10-й" + , "10-ый" + , "десятая" + , "десятой" ] , examples (OrdinalData 21) [ "21й" , "21-й" , "21-го" + , "21-ого" , "Двадцать первый" , "двадцать первый" , "двадцать первого" + , "двадцать первой" ] , examples (OrdinalData 23) [ "23й" , "23-й" , "двадцать третий" , "двадцать третьего" + , "двадцать третьей" + , "23-го" + , "23-его" ] , examples (OrdinalData 31) [ "31ый" , "31-ый" , "тридцать первый" ] + , examples (OrdinalData 30) + [ "30ый" + , "30-ый" + , "тридцатый" + ] , examples (OrdinalData 48) [ "48ое" , "48-ое" , "сорок восьмое" ] + , examples (OrdinalData 40) + [ "40ое" + , "40-ое" + , "сороковой" + , "сороковое" + , "сороковая" + ] , examples (OrdinalData 99) [ "99ый" , "99-й" + , "99-ый" , "девяносто девятый" + , "девяносто девятая" + ] + , examples (OrdinalData 90) + [ "90ый" + , "90-й" + , "90-ый" + , "девяностый" + , "девяностая" + ] + , examples (OrdinalData 100) + [ "сотое" + , "сотая" + , "сотый" + , "100-ая" + , "100-я" + , "100-й" + , "100-е" ] ] diff --git a/Duckling/Ordinal/RU/Rules.hs b/Duckling/Ordinal/RU/Rules.hs index 3a4f846dc..50594fd74 100644 --- a/Duckling/Ordinal/RU/Rules.hs +++ b/Duckling/Ordinal/RU/Rules.hs @@ -31,6 +31,7 @@ ordinalsFirstthMap = HashMap.fromList , ( "втор", 2 ) , ( "трет", 3 ) , ( "четверт", 4 ) + , ( "четвёрт", 4 ) , ( "пят", 5 ) , ( "шест", 6 ) , ( "седьм", 7 ) @@ -47,6 +48,14 @@ ordinalsFirstthMap = HashMap.fromList , ( "восемнадцат", 18 ) , ( "девятнадцат", 19 ) , ( "двадцат", 20 ) + , ( "тридцат", 30 ) + , ( "сороков", 40 ) + , ( "пятидесят", 50 ) + , ( "шестидесят", 60 ) + , ( "семидесят", 70 ) + , ( "восьмидесят", 80 ) + , ( "девяност", 90 ) + , ( "сот", 100 ) ] cardinalsMap :: HashMap Text.Text Int @@ -59,13 +68,14 @@ cardinalsMap = HashMap.fromList , ( "семьдесят", 70 ) , ( "восемьдесят", 80 ) , ( "девяносто", 90 ) + , ( "сто", 100 ) ] ruleOrdinalsFirstth :: Rule ruleOrdinalsFirstth = Rule - { name = "ordinals (first..19th)" + { name = "ordinals (first..20th, then 30th, 40th, ..., 100th)" , pattern = - [ regex "(перв|втор|трет|четверт|пят|шест|седьм|восьм|девят|десят|одиннадцат|двенадцат|тринадцат|четырнадцат|пятнадцат|шестнадцат|семнадцат|восемнадцат|девятнадцат|двадцат)(ье(го|й)?|ого|ый|ой|ий|ая|ое|ья)" + [ regex "(перв|втор|трет|четв[её]рт|пят|шест|седьм|восьм|девят|десят|одиннадцат|двенадцат|тринадцат|четырнадцат|пятнадцат|шестнадцат|семнадцат|восемнадцат|девятнадцат|двадцат|тридцат|сороков|пятидесят|шестидесят|семидесят|восьмидесят|девяност|сот)(ь(его|ему|ей|ем|им|их|и|е)|ого|ому|ый|ой|ий|ая|ое|ья|ом|ые|ым|ых)" ] , prod = \tokens -> case tokens of (Token RegexMatch (GroupMatch (match:_)):_) -> @@ -78,7 +88,7 @@ ruleOrdinal = Rule { name = "ordinal 21..99" , pattern = [ regex "(двадцать|тридцать|сорок|пятьдесят|шестьдесят|семьдесят|восемьдесят|девяносто)" - , regex "(перв|втор|трет|четверт|пят|шест|седьм|восьм|девят)(ье(го|й)?|ого|ый|ой|ий|ая|ое|ья)" + , regex "(перв|втор|трет|четв[её]рт|пят|шест|седьм|восьм|девят)(ье(го|й)?|ого|ому|ый|ой|ий|ая|ое|ья|ые|ым|ых)" ] , prod = \tokens -> case tokens of (Token RegexMatch (GroupMatch (m1:_)): @@ -94,7 +104,7 @@ ruleOrdinalDigits :: Rule ruleOrdinalDigits = Rule { name = "ordinal (digits)" , pattern = - [ regex "0*(\\d+)-?((ы|о|и|а|e|ь)?(ее|й|я|е|го))" + [ regex "0*(\\d+)-?((ы|о|и|а|е|ь)?(ее|й|я|е|го|му?))" ] , prod = \tokens -> case tokens of (Token RegexMatch (GroupMatch (match:_)):_) -> ordinal <$> parseInt match diff --git a/Duckling/Quantity/ZH/Rules.hs b/Duckling/Quantity/ZH/Rules.hs index f3ab2df91..e92182ced 100644 --- a/Duckling/Quantity/ZH/Rules.hs +++ b/Duckling/Quantity/ZH/Rules.hs @@ -72,7 +72,7 @@ ruleCattyTael = Rule , pattern = [ Predicate isPositive , regex "斤" - , numberBetween 1 10 + , Predicate $ numberBetween 1 10 , regex "两|兩" ] , prod = \case diff --git a/Duckling/Ranking/Classifiers/DA_XX.hs b/Duckling/Ranking/Classifiers/DA_XX.hs index 4ae6c932f..32a69377d 100644 --- a/Duckling/Ranking/Classifiers/DA_XX.hs +++ b/Duckling/Ranking/Classifiers/DA_XX.hs @@ -64,23 +64,18 @@ classifiers likelihoods = HashMap.fromList [], n = 0}}), ("