From 7692ba3c4f91c26f15deaa44b37875c8cc4b709b Mon Sep 17 00:00:00 2001 From: Marek Antoniak Date: Mon, 11 Jan 2016 21:32:29 +0100 Subject: [PATCH] Added Chinese --- .../NumeralConverterProperties.cs | 18 +- Numsense.UnitTests.CSharp/NumeralTests.cs | 64 ++++- Numsense.UnitTests/NumeralProperties.fs | 64 +++++ Numsense.UnitTests/Numsense.UnitTests.fsproj | 6 +- .../SimplifiedChineseExamples.fs | 225 ++++++++++++++++++ .../SimplifiedFinancialChineseExamples.fs | 225 ++++++++++++++++++ .../TraditionalChineseExamples.fs | 225 ++++++++++++++++++ .../TraditionalFinancialChineseExamples.fs | 225 ++++++++++++++++++ Numsense/Chinese.fs | 194 +++++++++++++++ Numsense/Numeral.fs | 24 +- Numsense/Numsense.fsproj | 3 +- Numsense/ObjectOriented.fs | 42 +++- 12 files changed, 1305 insertions(+), 10 deletions(-) create mode 100644 Numsense.UnitTests/SimplifiedChineseExamples.fs create mode 100644 Numsense.UnitTests/SimplifiedFinancialChineseExamples.fs create mode 100644 Numsense.UnitTests/TraditionalChineseExamples.fs create mode 100644 Numsense.UnitTests/TraditionalFinancialChineseExamples.fs create mode 100644 Numsense/Chinese.fs diff --git a/Numsense.UnitTests.CSharp/NumeralConverterProperties.cs b/Numsense.UnitTests.CSharp/NumeralConverterProperties.cs index 1bc6a7c..0a9756d 100644 --- a/Numsense.UnitTests.CSharp/NumeralConverterProperties.cs +++ b/Numsense.UnitTests.CSharp/NumeralConverterProperties.cs @@ -87,7 +87,23 @@ public static Arbitrary Converter() new ConverterPropertyGroup( new RussianNumeralConverter(), NumeralModule.toRussian, - NumeralModule.tryParseRussian) + NumeralModule.tryParseRussian), + new ConverterPropertyGroup( + new TraditionalChineseNumeralConverter(), + NumeralModule.toTraditionalChinese, + NumeralModule.tryParseTraditionalChinese), + new ConverterPropertyGroup( + new TraditionalFinancialChineseNumeralConverter(), + NumeralModule.toTraditionalFinancialChinese, + NumeralModule.tryParseTraditionalFinancialChinese), + new ConverterPropertyGroup( + new SimplifiedChineseNumeralConverter(), + NumeralModule.toSimplifiedChinese, + NumeralModule.tryParseSimplifiedChinese), + new ConverterPropertyGroup( + new SimplifiedFinancialChineseNumeralConverter(), + NumeralModule.toSimplifiedFinancialChinese, + NumeralModule.tryParseSimplifiedFinancialChinese) ) .ToArbitrary(); } diff --git a/Numsense.UnitTests.CSharp/NumeralTests.cs b/Numsense.UnitTests.CSharp/NumeralTests.cs index c881bfe..4a56a99 100644 --- a/Numsense.UnitTests.CSharp/NumeralTests.cs +++ b/Numsense.UnitTests.CSharp/NumeralTests.cs @@ -78,6 +78,68 @@ public void RussianIsSingleton() var expected = Numeral.Russian; var actual = Numeral.Russian; Assert.Same(expected, actual); - } + } + + [Fact] + public void TraditionalChineseIsCorrect() + { + var actual = Numeral.TraditionalChinese; + Assert.IsAssignableFrom(actual); + } + + [Fact] + public void TraditionalChineseIsSingleton() + { + var expected = Numeral.TraditionalChinese; + var actual = Numeral.TraditionalChinese; + Assert.Same(expected, actual); + } + + [Fact] + public void TraditionalFinancialChineseIsCorrect() + { + var actual = Numeral.TraditionalFinancialChinese; + Assert.IsAssignableFrom + (actual); + } + + [Fact] + public void TraditionalFinancialChineseIsSingleton() + { + var expected = Numeral.TraditionalFinancialChinese; + var actual = Numeral.TraditionalFinancialChinese; + Assert.Same(expected, actual); + } + + [Fact] + public void SimplifiedChineseIsCorrect() + { + var actual = Numeral.SimplifiedChinese; + Assert.IsAssignableFrom(actual); + } + + [Fact] + public void SimplifiedChineseIsSingleton() + { + var expected = Numeral.SimplifiedChinese; + var actual = Numeral.SimplifiedChinese; + Assert.Same(expected, actual); + } + + [Fact] + public void SimplifiedFinancialChineseIsCorrect() + { + var actual = Numeral.SimplifiedFinancialChinese; + Assert.IsAssignableFrom + (actual); + } + + [Fact] + public void SimplifiedFinancialChineseIsSingleton() + { + var expected = Numeral.SimplifiedFinancialChinese; + var actual = Numeral.SimplifiedFinancialChinese; + Assert.Same(expected, actual); + } } } diff --git a/Numsense.UnitTests/NumeralProperties.fs b/Numsense.UnitTests/NumeralProperties.fs index 8e0320d..451d755 100644 --- a/Numsense.UnitTests/NumeralProperties.fs +++ b/Numsense.UnitTests/NumeralProperties.fs @@ -77,4 +77,68 @@ let ``negative Russian is the inverse of positive Russian`` x = let actualInteger = Numeral.tryParseRussian actualRussian sprintf "минус %s" (Numeral.toRussian x) =! actualRussian + Some -x =! actualInteger + +[] +let ``tryParseTraditionalChinese is the inverse of toTraditionalChinese`` x = + test <@ Some x = (x |> Numeral.toTraditionalChinese + |> Numeral.tryParseTraditionalChinese) @> + +[] +let ``negative TraditionalChinese is the inverse of positive TraditionalChinese`` x = + x <> 0 ==> lazy + let x = abs x + + let actualChinese = Numeral.toTraditionalChinese -x + let actualInteger = Numeral.tryParseTraditionalChinese actualChinese + + sprintf "負%s" (Numeral.toTraditionalChinese x) =! actualChinese + Some -x =! actualInteger + +[] +let ``tryParseTraditionalFinancialChinese is the inverse of toTraditionalFinancialChinese`` x = + test <@ Some x = (x |> Numeral.toTraditionalFinancialChinese + |> Numeral.tryParseTraditionalFinancialChinese) @> + +[] +let ``negative TraditionalFinancialChinese is the inverse of positive TraditionalFinancialChinese`` x = + x <> 0 ==> lazy + let x = abs x + + let actualChinese = Numeral.toTraditionalFinancialChinese -x + let actualInteger = Numeral.tryParseTraditionalFinancialChinese actualChinese + + sprintf "負%s" (Numeral.toTraditionalFinancialChinese x) =! actualChinese + Some -x =! actualInteger + +[] +let ``tryParseSimplifiedChinese is the inverse of toSimplifiedChinese`` x = + test <@ Some x = (x |> Numeral.toSimplifiedChinese + |> Numeral.tryParseSimplifiedChinese) @> + +[] +let ``negative SimplifiedChinese is the inverse of positive SimplifiedChinese`` x = + x <> 0 ==> lazy + let x = abs x + + let actualChinese = Numeral.toSimplifiedChinese -x + let actualInteger = Numeral.tryParseSimplifiedChinese actualChinese + + sprintf "负%s" (Numeral.toSimplifiedChinese x) =! actualChinese + Some -x =! actualInteger + +[] +let ``tryParseSimplifiedFinancialChinese is the inverse of toSimplifiedFinancialChinese`` x = + test <@ Some x = (x |> Numeral.toSimplifiedFinancialChinese + |> Numeral.tryParseSimplifiedFinancialChinese) @> + +[] +let ``negative SimplifiedFinancialChinese is the inverse of positive SimplifiedFinancialChinese`` x = + x <> 0 ==> lazy + let x = abs x + + let actualChinese = Numeral.toSimplifiedFinancialChinese -x + let actualInteger = Numeral.tryParseSimplifiedFinancialChinese actualChinese + + sprintf "负%s" (Numeral.toSimplifiedFinancialChinese x) =! actualChinese Some -x =! actualInteger \ No newline at end of file diff --git a/Numsense.UnitTests/Numsense.UnitTests.fsproj b/Numsense.UnitTests/Numsense.UnitTests.fsproj index 174c9b5..105ef3b 100644 --- a/Numsense.UnitTests/Numsense.UnitTests.fsproj +++ b/Numsense.UnitTests/Numsense.UnitTests.fsproj @@ -57,7 +57,11 @@ - + + + + + diff --git a/Numsense.UnitTests/SimplifiedChineseExamples.fs b/Numsense.UnitTests/SimplifiedChineseExamples.fs new file mode 100644 index 0000000..9c302de --- /dev/null +++ b/Numsense.UnitTests/SimplifiedChineseExamples.fs @@ -0,0 +1,225 @@ +module Ploeh.Numsense.SimplifiedChineseExamples + +open Xunit +open Swensen.Unquote + +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +let ``tryOfSimplifiedChinese returns correct result`` (chinese, expected) = + let actual = Numeral.tryParseSimplifiedChinese chinese + Some expected =! actual + +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +let ``toSimplifiedChinese returns correct result`` (i, expected) = + let actual = Numeral.toSimplifiedChinese i + expected =! actual \ No newline at end of file diff --git a/Numsense.UnitTests/SimplifiedFinancialChineseExamples.fs b/Numsense.UnitTests/SimplifiedFinancialChineseExamples.fs new file mode 100644 index 0000000..e0bdbc4 --- /dev/null +++ b/Numsense.UnitTests/SimplifiedFinancialChineseExamples.fs @@ -0,0 +1,225 @@ +module Ploeh.Numsense.SimplifiedFinancialChineseExamples + +open Xunit +open Swensen.Unquote + +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +let ``tryOfSimplifiedFinancialChinese returns correct result`` (chinese, expected) = + let actual = Numeral.tryParseSimplifiedFinancialChinese chinese + Some expected =! actual + +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +let ``toSimplifiedFinancialChinese returns correct result`` (i, expected) = + let actual = Numeral.toSimplifiedFinancialChinese i + expected =! actual \ No newline at end of file diff --git a/Numsense.UnitTests/TraditionalChineseExamples.fs b/Numsense.UnitTests/TraditionalChineseExamples.fs new file mode 100644 index 0000000..b58d142 --- /dev/null +++ b/Numsense.UnitTests/TraditionalChineseExamples.fs @@ -0,0 +1,225 @@ +module Ploeh.Numsense.TraditionalChineseExamples + +open Xunit +open Swensen.Unquote + +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +let ``tryOfTraditionalChinese returns correct result`` (chinese, expected) = + let actual = Numeral.tryParseTraditionalChinese chinese + Some expected =! actual + +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +let ``toTraditionalChinese returns correct result`` (i, expected) = + let actual = Numeral.toTraditionalChinese i + expected =! actual \ No newline at end of file diff --git a/Numsense.UnitTests/TraditionalFinancialChineseExamples.fs b/Numsense.UnitTests/TraditionalFinancialChineseExamples.fs new file mode 100644 index 0000000..a110989 --- /dev/null +++ b/Numsense.UnitTests/TraditionalFinancialChineseExamples.fs @@ -0,0 +1,225 @@ +module Ploeh.Numsense.TraditionalFinancialChineseExamples + +open Xunit +open Swensen.Unquote + +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +let ``tryOfTraditionalFinancialChinese returns correct result`` (chinese, expected) = + let actual = Numeral.tryParseTraditionalFinancialChinese chinese + Some expected =! actual + +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +[] +let ``toTraditionalFinancialChinese returns correct result`` (i, expected) = + let actual = Numeral.toTraditionalFinancialChinese i + expected =! actual \ No newline at end of file diff --git a/Numsense/Chinese.fs b/Numsense/Chinese.fs new file mode 100644 index 0000000..dc11f29 --- /dev/null +++ b/Numsense/Chinese.fs @@ -0,0 +1,194 @@ +module internal Ploeh.Numsense.Chinese + +open Ploeh.Numsense.InternalDsl + +type CharacterSet = + { + negative: string; + zero: string; + one: string; + two: string; + alternativeTwo: string; + three: string; + four: string; + five: string; + six: string; + seven: string; + eight: string; + nine: string; + ten: string; + hundred: string; + thousand: string; + tenThousands: string; + hundredMillions: string + } + +let internal TraditionalCharacterSet = + { + negative = "負"; + zero = "零"; + one = "一"; + two = "二"; + alternativeTwo = "兩"; + three = "三"; + four = "四"; + five = "五"; + six = "六"; + seven = "七"; + eight = "八"; + nine = "九"; + ten = "十"; + hundred = "百"; + thousand = "千"; + tenThousands = "萬"; + hundredMillions = "億" + } + +let internal TraditionalFinancialCharacterSet = + { + negative = "負"; + zero = "零"; + one = "壹"; + two = "貳"; + alternativeTwo = "兩"; + three = "叄"; + four = "肆"; + five = "伍"; + six = "陸"; + seven = "柒"; + eight = "捌"; + nine = "玖"; + ten = "拾"; + hundred = "佰"; + thousand = "仟"; + tenThousands = "萬"; + hundredMillions = "億" + } + +let internal SimplifiedCharacterSet = + { + negative = "负"; + zero = "零"; + one = "一"; + two = "二"; + alternativeTwo = "两"; + three = "三"; + four = "四"; + five = "五"; + six = "六"; + seven = "七"; + eight = "八"; + nine = "九"; + ten = "十"; + hundred = "百"; + thousand = "千"; + tenThousands = "万"; + hundredMillions = "亿" + } + +let internal SimplifiedFinancialCharacterSet = + { + negative = "负"; + zero = "零"; + one = "壹"; + two = "贰"; + alternativeTwo = "两"; + three = "叁"; + four = "肆"; + five = "伍"; + six = "陆"; + seven = "柒"; + eight = "捌"; + nine = "玖"; + ten = "拾"; + hundred = "佰"; + thousand = "仟"; + tenThousands = "万"; + hundredMillions = "亿" + } + +let rec internal toChineseImp characterSet x = + + let getCharacter useAlternativeTwo x = + match x with + | 0 -> characterSet.zero + | 1 -> characterSet.one + | 2 -> if useAlternativeTwo then characterSet.alternativeTwo else characterSet.two + | 3 -> characterSet.three + | 4 -> characterSet.four + | 5 -> characterSet.five + | 6 -> characterSet.six + | 7 -> characterSet.seven + | 8 -> characterSet.eight + | 9 -> characterSet.nine + | _ -> "" + + let formatTenThousand suffix previousValue x = + let formatInternal suffix mayOutputZero isQuantity x = + if x = 0 + then if mayOutputZero + then sprintf "%s" (getCharacter isQuantity x) + else "" + else sprintf "%s%s" (getCharacter isQuantity x) suffix + + let thousands = (x / 1000) % 10 + let hundreds = (x / 100) % 10 + let tens = (x / 10) % 10 + let units = x % 10 + + sprintf + "%s%s%s%s%s" + (formatInternal characterSet.thousand (previousValue <> 0 && hundreds <> 0) true thousands) + (formatInternal characterSet.hundred ((previousValue <> 0 || thousands <> 0) && tens <> 0) true hundreds) + (formatInternal characterSet.ten ((previousValue <> 0 || hundreds <> 0 || thousands <> 0) && units <> 0) false tens) + (formatInternal "" false false units) + (if thousands <> 0 || hundreds <> 0 || tens <> 0 || units <> 0 then suffix else "") + + let format x = + let hundredMillions = (x / 100000000) % 10000 + let tenThousands = (x / 10000) % 10000 + let units = x % 10000 + + sprintf + "%s%s%s" + (formatTenThousand characterSet.hundredMillions 0 hundredMillions) + (formatTenThousand characterSet.tenThousands (x / 100000000) tenThousands) + (formatTenThousand "" (x / 10000) units) + + match x with + | x when x < 0 -> sprintf "%s%s" characterSet.negative (toChineseImp characterSet -x) + | Between 0 10 x -> getCharacter true x + | 10 -> characterSet.ten + | Between 11 20 x -> sprintf "%s%s" characterSet.ten (getCharacter false (x % 10)) + | _ -> format x + +let internal tryParseChineseImp characterSet (x : string) = + let rec conv acc candidate = + match candidate with + | "" -> Some acc + | StartsWith characterSet.zero t -> + if t.StartsWith characterSet.ten + then conv (1 + acc) t + else conv (0 + acc) t + | StartsWith characterSet.one t -> conv (1 + acc) t + | StartsWith characterSet.two t + | StartsWith characterSet.alternativeTwo t -> conv (2 + acc) t + | StartsWith characterSet.three t -> conv (3 + acc) t + | StartsWith characterSet.four t -> conv (4 + acc) t + | StartsWith characterSet.five t -> conv (5 + acc) t + | StartsWith characterSet.six t -> conv (6 + acc) t + | StartsWith characterSet.seven t -> conv (7 + acc) t + | StartsWith characterSet.eight t -> conv (8 + acc) t + | StartsWith characterSet.nine t -> conv (9 + acc) t + | StartsWith characterSet.ten t -> + conv (if acc = 0 then 10 else 10 %* acc) t + | StartsWith characterSet.hundred t -> conv (100 %* acc) t + | StartsWith characterSet.thousand t -> conv (1000 %* acc) t + | StartsWith characterSet.tenThousands t -> conv (10000 %* acc) t + | StartsWith characterSet.hundredMillions t -> conv (100000000 %* acc) t + | _ -> None + + let canonicalized = x.Trim() + match canonicalized with + | StartsWith characterSet.negative t -> conv 0 (t.Trim ()) |> Option.map ((*)-1) + | _ -> conv 0 canonicalized \ No newline at end of file diff --git a/Numsense/Numeral.fs b/Numsense/Numeral.fs index 8680901..924a78c 100644 --- a/Numsense/Numeral.fs +++ b/Numsense/Numeral.fs @@ -11,7 +11,27 @@ let toPolish = Polish.toPolishImp let tryParsePolish = Polish.tryParsePolishImp let toDutch = Dutch.toDutchImp -let tryParseDutch = Dutch.tryParseDutchImp +let tryParseDutch = Dutch.tryParseDutchImp let toRussian = Russian.toRussianImp Russian.Masculine -let tryParseRussian = Russian.tryParseRussianImp \ No newline at end of file +let tryParseRussian = Russian.tryParseRussianImp + +let toTraditionalChinese = + Chinese.toChineseImp Chinese.TraditionalCharacterSet +let tryParseTraditionalChinese = + Chinese.tryParseChineseImp Chinese.TraditionalCharacterSet + +let toTraditionalFinancialChinese = + Chinese.toChineseImp Chinese.TraditionalFinancialCharacterSet +let tryParseTraditionalFinancialChinese = + Chinese.tryParseChineseImp Chinese.TraditionalFinancialCharacterSet + +let toSimplifiedChinese = + Chinese.toChineseImp Chinese.SimplifiedCharacterSet +let tryParseSimplifiedChinese = + Chinese.tryParseChineseImp Chinese.SimplifiedCharacterSet + +let toSimplifiedFinancialChinese = + Chinese.toChineseImp Chinese.SimplifiedFinancialCharacterSet +let tryParseSimplifiedFinancialChinese = + Chinese.tryParseChineseImp Chinese.SimplifiedFinancialCharacterSet diff --git a/Numsense/Numsense.fsproj b/Numsense/Numsense.fsproj index d7eefe5..861cfa0 100644 --- a/Numsense/Numsense.fsproj +++ b/Numsense/Numsense.fsproj @@ -58,7 +58,8 @@ - + + diff --git a/Numsense/ObjectOriented.fs b/Numsense/ObjectOriented.fs index e74a402..619842d 100644 --- a/Numsense/ObjectOriented.fs +++ b/Numsense/ObjectOriented.fs @@ -43,10 +43,44 @@ type RussianNumeralConverter () = member this.ToNumeral number = Numeral.toRussian number member this.TryParse (s, result) = Helper.tryParse Numeral.tryParseRussian (s, &result) - + +type TraditionalChineseNumeralConverter () = + interface INumeralConverter with + member this.ToNumeral number = Numeral.toTraditionalChinese number + member this.TryParse (s, result) = + Helper.tryParse Numeral.tryParseTraditionalChinese (s, &result) + +type TraditionalFinancialChineseNumeralConverter () = + interface INumeralConverter with + member this.ToNumeral number = + Numeral.toTraditionalFinancialChinese number + member this.TryParse (s, result) = + Helper.tryParse Numeral.tryParseTraditionalFinancialChinese (s, &result) + +type SimplifiedChineseNumeralConverter () = + interface INumeralConverter with + member this.ToNumeral number = Numeral.toSimplifiedChinese number + member this.TryParse (s, result) = + Helper.tryParse Numeral.tryParseSimplifiedChinese (s, &result) + +type SimplifiedFinancialChineseNumeralConverter () = + interface INumeralConverter with + member this.ToNumeral number = + Numeral.toSimplifiedFinancialChinese number + member this.TryParse (s, result) = + Helper.tryParse Numeral.tryParseSimplifiedFinancialChinese (s, &result) + type Numeral private () = static member val English = EnglishNumeralConverter () :> INumeralConverter static member val Danish = DanishNumeralConverter () :> INumeralConverter - static member val Polish = PolishNumeralConverter () :> INumeralConverter - static member val Dutch = DutchNumeralConverter () :> INumeralConverter - static member val Russian = RussianNumeralConverter () :> INumeralConverter \ No newline at end of file + static member val Polish = PolishNumeralConverter () :> INumeralConverter + static member val Dutch = DutchNumeralConverter () :> INumeralConverter + static member val Russian = RussianNumeralConverter () :> INumeralConverter + static member val TraditionalChinese = + TraditionalChineseNumeralConverter () :> INumeralConverter + static member val TraditionalFinancialChinese = + TraditionalFinancialChineseNumeralConverter () :> INumeralConverter + static member val SimplifiedChinese = + SimplifiedChineseNumeralConverter () :> INumeralConverter + static member val SimplifiedFinancialChinese = + SimplifiedFinancialChineseNumeralConverter () :> INumeralConverter \ No newline at end of file