Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recognise Swiss thousand separator in Numerals #706

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Duckling/Numeral/DE/Corpus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,7 @@ allExamples = concat
, examples (NumeralValue 2771090092000000.0)
[ "zwei billiarden siebenhunderteinundsiebzig billionen neunzig milliarden zweiundneunzig millionen"
]
, examples (NumeralValue 100000.0)
[ "100'000"
]
]
29 changes: 28 additions & 1 deletion Duckling/Numeral/DE/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ ruleFew = Rule
, prod = \_ -> integer 3
}

ruleDecimalWithSwissThousandsSeparator :: Rule
ruleDecimalWithSwissThousandsSeparator = Rule
{ name = "decimal with thousands separator"
, pattern =
[ regex "(\\d+(\\'\\d\\d\\d)+\\,\\d+)"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):
_) -> let fmt = Text.replace "," "." $ Text.replace "." Text.empty match
in parseDouble fmt >>= double
_ -> Nothing
}

ruleDecimalWithThousandsSeparator :: Rule
ruleDecimalWithThousandsSeparator = Rule
{ name = "decimal with thousands separator"
Expand Down Expand Up @@ -203,6 +216,18 @@ ruleNumeralDotNumeral = Rule
_ -> Nothing
}

ruleIntegerWithSwissThousandsSeparator :: Rule
ruleIntegerWithSwissThousandsSeparator = Rule
{ name = "integer with thousands separator ."
, pattern =
[ regex "(\\d{1,3}(\\'\\d\\d\\d){1,5})"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) ->
parseDouble (Text.replace "'" Text.empty match) >>= double
_ -> Nothing
}

ruleIntegerWithThousandsSeparator :: Rule
ruleIntegerWithThousandsSeparator = Rule
{ name = "integer with thousands separator ."
Expand Down Expand Up @@ -231,9 +256,11 @@ rules =
[ ruleCouple
, ruleDecimalNumeral
, ruleDecimalWithThousandsSeparator
, ruleDecimalWithSwissThousandsSeparator
, ruleDozen
, ruleFew
, ruleIntegerWithThousandsSeparator
, ruleIntegerWithSwissThousandsSeparator
, ruleIntersect
, ruleMultiply
, ruleNumeralDotNumeral
Expand All @@ -243,4 +270,4 @@ rules =
, rulePowersOfTen
, ruleZero
, ruleAllNumeralWords
]
]