public void WithInvalidCulture_AlwaysUseEnglish() { var recognizer = new NumberRecognizer(); var testedModel = recognizer.GetNumberModel(InvalidCulture); TestNumber(testedModel, controlModel, TestInput); }
public void WithoutTargetCultureAndWithoutCulture_FallbackToEnglishCulture() { var recognizer = new NumberRecognizer(); var testedModel = recognizer.GetNumberModel(); TestNumber(testedModel, controlModel, TestInput); }
public void WithInvalidCulture_UseTargetCulture() { var recognizer = new NumberRecognizer(EnglishCulture); var testedModel = recognizer.GetNumberModel(InvalidCulture); TestNumber(testedModel, controlModel, TestInput); }
public void WithOtherCulture_NotUseTargetCulture() { var recognizer = new NumberRecognizer(SpanishCulture); var testedModel = recognizer.GetNumberModel(EnglishCulture); TestNumber(testedModel, controlModel, TestInput); }
public static void CheckOnNumber(this Message message, out List <ModelResult> modelResult) { var recognizer = new NumberRecognizer(Culture.Dutch); var model = recognizer.GetNumberModel(); modelResult = model.Parse(message.Text); }
public void TestCompareModel() { var model = NumberRecognizer.GetNumberModel(Culture.Chinese); var wmodel = GetWithoutWhiteListNumberModel(); MultiTest(model, "一看", 0); MultiTest(wmodel, "一看", 1); MultiTest(model, "一美元", 0); MultiTest(wmodel, "一美元", 1); MultiTest(model, "两美刀", 0); MultiTest(wmodel, "两美刀", 1); MultiTest(model, "四川", 0); MultiTest(wmodel, "四川", 1); MultiTest(model, "陆地", 0); MultiTest(wmodel, "陆地", 1); MultiTest(model, "十", 1); MultiTest(wmodel, "十", 1); }
public void TestFractionModel() { var model = NumberRecognizer.GetNumberModel(Culture.Chinese); BasicTest(model, "五 分之 一", (1.0 / 5).ToString()); BasicTest(model, "三 百 五 又 三 分之 一", (350 + 1.0 / 3).ToString()); BasicTest(model, "4 6/3", (4 + (double)6 / 3).ToString()); BasicTest(model, "-3/2", "-1.5"); BasicTest(model, "五分之一", "0.2"); BasicTest(model, "一百万又五十万分之二十五", (1000000 + (double)25 / 500000).ToString()); BasicTest(model, "一百分之二", "0.02"); BasicTest(model, "四千二分之三", ((double)3 / 4200).ToString()); BasicTest(model, "一百分之2", "0.02"); BasicTest(model, "五百分之2333", ((double)2333 / 500).ToString()); BasicTest(model, "3又一千分之23", (3 + (double)23 / 1000).ToString()); BasicTest(model, "3/5", "0.6"); BasicTest(model, "1 3/5", "1.6"); BasicTest(model, "16/5", "3.2"); BasicTest(model, "16分之5", ((double)5 / 16).ToString()); BasicTest(model, "16分之2225", ((double)2225 / 16).ToString()); BasicTest(model, "负一又二分之一", "-1.5"); BasicTest(model, "二分之一", "0.5"); BasicTest(model, "三百 五又三分之一", (350 + (double)1 / 3).ToString()); BasicTest(model, "三百五十又3分之1", (350 + (double)1 / 3).ToString()); BasicTest(model, "3分之一百五十七", ((double)157 / 3).ToString()); BasicTest(model, "负3分之负一百五十七", ((double)157 / 3).ToString()); MultiTest(model, @"一百四十四。一百五十万五千二百四十五,二千零四十五个,三千零五个,和四千万零五十,一百五十四点零,四百亿点零五零,二十五分之一百四十四,十一又十四分之一,1个", 10); MultiTest(model, @"1 4/3的美梦,1/2的努力", 2); BasicTest(model, "二分 之一", "0.5"); BasicTest(model, "三百 五 又 三分 之一", (350 + (double)1 / 3).ToString()); BasicTest(model, "三百五十 又 3分 之1", (350 + (double)1 / 3).ToString()); BasicTest(model, "3 分 之 一百五十七", ((double)157 / 3).ToString()); BasicTest(model, "负3 分 之 负一百五十七", ((double)157 / 3).ToString()); BasicTest(model, "五 分之 壹", (1.0 / 5).ToString()); BasicTest(model, "三 百 五 又 三 分之 壹", (350 + 1.0 / 3).ToString()); BasicTest(model, "4 6/3", (4 + (double)6 / 3).ToString()); BasicTest(model, "-3/2", "-1.5"); BasicTest(model, "五分之壹", "0.2"); BasicTest(model, "壹百萬又五十萬分之二十五", (1000000 + (double)25 / 500000).ToString()); BasicTest(model, "壹百分之二", "0.02"); BasicTest(model, "四千二分之三", ((double)3 / 4200).ToString()); BasicTest(model, "壹百分之2", "0.02"); BasicTest(model, "五百分之2333", ((double)2333 / 500).ToString()); BasicTest(model, "3又壹千分之23", (3 + (double)23 / 1000).ToString()); BasicTest(model, "3/5", "0.6"); BasicTest(model, "1 3/5", "1.6"); BasicTest(model, "16/5", "3.2"); BasicTest(model, "16分之5", ((double)5 / 16).ToString()); BasicTest(model, "16分之2225", ((double)2225 / 16).ToString()); BasicTest(model, "負壹又二分之壹", "-1.5"); BasicTest(model, "二分之壹", "0.5"); BasicTest(model, "三百 五又三分之壹", (350 + (double)1 / 3).ToString()); BasicTest(model, "三百五十又3分之1", (350 + (double)1 / 3).ToString()); BasicTest(model, "3分之壹百五十七", ((double)157 / 3).ToString()); BasicTest(model, "負3分之負壹百五十七", ((double)157 / 3).ToString()); MultiTest(model, @"壹百四十四。壹百五十萬五千二百四十五,二千零四十五個,三千零五個,和四千萬零五十,壹百五十四點零,四百億點零五零,二十五分之壹百四十四,十壹又十四分之壹,1個", 10); MultiTest(model, @"1 4/3的美夢,1/2的努力", 2); BasicTest(model, "二分 之壹", "0.5"); BasicTest(model, "三百 五 又 三分 之壹", (350 + (double)1 / 3).ToString()); BasicTest(model, "三百五十 又 3分 之1", (350 + (double)1 / 3).ToString()); BasicTest(model, "3 分 之 壹百五十七", ((double)157 / 3).ToString()); BasicTest(model, "負3 分 之 負壹百五十七", ((double)157 / 3).ToString()); }
public void TestFractionModel() { var ci = new SpanishNumberParserConfiguration().CultureInfo; var model = NumberRecognizer.GetNumberModel(Culture.Spanish); BasicTest(model, "un quinto", "0,2"); BasicTest(model, "un billonesimo", "1E-12"); BasicTest(model, "cien mil billonesima", "1E-07"); BasicTest(model, "tres quintos", "0,6"); BasicTest(model, "veinte quintos", "4"); BasicTest(model, "veintitres quintas", "4,6"); BasicTest(model, "tres con un quinto", "3,2"); BasicTest(model, "veintiun quintos", "4,2"); BasicTest(model, "un veintiunavo", ((double)1 / 21).ToString(ci)); BasicTest(model, "ciento treinta y tres veintiunavos", ((double)133 / 21).ToString(ci)); BasicTest(model, "ciento treinta con tres veintiunavos", (130 + (double)3 / 21).ToString(ci)); BasicTest(model, "veintidos treintavos", ((double)22 / 30).ToString(ci)); BasicTest(model, "un veinticincoavo", ((double)1 / 25).ToString(ci)); BasicTest(model, "veinte veinticincoavos", "0,8"); BasicTest(model, "tres veintiunavos", ((double)3 / 21).ToString(ci)); BasicTest(model, "tres veinteavos", ((double)3 / 20).ToString(ci)); BasicTest(model, "tres doscientosavos", ((double)3 / 200).ToString(ci)); BasicTest(model, "tres dosmilesimos", ((double)3 / 2000).ToString(ci)); BasicTest(model, "tres veintemilesimos", ((double)3 / 20000).ToString(ci)); BasicTest(model, "tres doscientosmilesimos", ((double)3 / 200000).ToString(ci)); BasicTest(model, "tres dosmillonesimos", ((double)3 / 2000000).ToString(ci)); // act like Google BasicTest(model, "ciento treinta quintos", ((double)130 / 5).ToString(ci)); BasicTest(model, "cien treintaicincoavos", ((double)100 / 35).ToString(ci)); // this is spanish can be interpreted as 130 + 2/5 or 132 / 5 - in this case go for 2nd option for simplicity BasicTest(model, "ciento treinta y dos cincoavos", ((double)132 / 5).ToString(ci)); // and we go for the first option if the user writes it using 'con' BasicTest(model, "ciento treinta con dos cincoavos", (130 + (double)2 / 5).ToString(ci)); BasicTest(model, "ciento treinta y dos quintos", ((double)132 / 5).ToString(ci)); BasicTest(model, "ciento treinta con dos quintos", (130 + (double)2 / 5).ToString(ci)); BasicTest(model, "un cientocincoavos", ((double)1 / 105).ToString(ci)); BasicTest(model, "cien milcincoavos", ((double)100 / 1005).ToString(ci)); BasicTest(model, "uno sobre tres", ((double)1 / 3).ToString(ci)); BasicTest(model, "1 sobre 21", ((double)1 / 21).ToString(ci)); BasicTest(model, "1 sobre tres", ((double)1 / 3).ToString(ci)); BasicTest(model, "1 sobre 3", ((double)1 / 3).ToString(ci)); BasicTest(model, "uno sobre 3", ((double)1 / 3).ToString(ci)); BasicTest(model, "uno sobre 20", ((double)1 / 20).ToString(ci)); BasicTest(model, "uno sobre veinte", ((double)1 / 20).ToString(ci)); BasicTest(model, "uno sobre cien", ((double)1 / 100).ToString(ci)); BasicTest(model, "1 sobre ciento veintiuno", ((double)1 / 121).ToString(ci)); BasicTest(model, "uno sobre ciento treinta y cinco", ((double)1 / 135).ToString(ci)); BasicTest(model, "cinco medios", ((double)5 / 2).ToString(ci)); BasicTest(model, "tres cuartos", ((double)3 / 4).ToString(ci)); BasicTest(model, "dos tercios", ((double)2 / 3).ToString(ci)); BasicTest(model, "ciento treinta y cinco medios", ((double)135 / 2).ToString(ci)); // not supported should be written as integer + decimal part => once con uno y medio //BasicTest(model, "diez con tres medios", (10 + (double)3 / 2).ToString(ci)); BasicTest(model, "once con uno y medio", (10 + (double)3 / 2).ToString(ci)); BasicTest(model, "diez con un medio", (10 + (double)1 / 2).ToString(ci)); BasicTest(model, "diez con un cuarto", (10 + (double)1 / 4).ToString(ci)); }
public void TestNumberModel() { var ci = new SpanishNumberParserConfiguration().CultureInfo; var model = NumberRecognizer.GetNumberModel(Culture.Spanish); #region Integer numbers BasicTest(model, "2 mil millones", "2000000000"); BasicTest(model, " 123456789101231", "123456789101231"); BasicTest(model, "-123456789101231", "-123456789101231"); BasicTest(model, " -123456789101231", "-123456789101231"); BasicTest(model, " -1", "-1"); BasicTest(model, "1.234.567", "1234567"); BasicTest(model, "3 docenas", "36"); BasicTest(model, "dos mil millones", "2000000000"); BasicTest(model, "una docena", "12"); BasicTest(model, "quince docenas", "180"); BasicTest(model, "dos mil y cuatro docenas", "2048"); BasicTest(model, "siete", "7"); BasicTest(model, "cuarenta y siete", "47"); BasicTest(model, "trescientos cuarenta y siete", "347"); BasicTest(model, "dos mil trescientos cuarenta y siete", "2347"); BasicTest(model, "cincuenta y dos mil trescientos cuarenta y siete", "52347"); BasicTest(model, "cuatrocientos cincuenta y dos mil trescientos cuarenta y siete", "452347"); BasicTest(model, "tres millones", "3000000"); BasicTest(model, "tres millones siete", "3000007"); BasicTest(model, "tres millones cuarenta y siete", "3000047"); BasicTest(model, "tres millones trescientos cuarenta y siete", "3000347"); BasicTest(model, "tres millones dos mil trescientos cuarenta y siete", "3002347"); BasicTest(model, "tres millones cincuenta y dos mil trescientos cuarenta y siete", "3052347"); BasicTest(model, "tres millones cuatrocientos cincuenta y dos mil trescientos cuarenta y siete", "3452347"); BasicTest(model, "trece millones cuatrocientos cincuenta y dos mil trescientos cuarenta y siete", "13452347"); BasicTest(model, "quinientos trece millones cuatrocientos cincuenta y dos mil trescientos cuarenta y siete", "513452347"); BasicTest(model, "quinientos trece millones cuatrocientos cincuenta y dos mil trescientos cuarenta", "513452340"); BasicTest(model, "quinientos trece millones cuatrocientos cincuenta y dos mil trescientos", "513452300"); BasicTest(model, "quinientos trece millones cuatrocientos cincuenta y dos mil", "513452000"); BasicTest(model, "quinientos trece millones cuatrocientos cincuenta mil", "513450000"); BasicTest(model, "quinientos trece millones cuatrocientos mil", "513400000"); BasicTest(model, "quinientos trece millones", "513000000"); BasicTest(model, "quinientos diez millones", "510000000"); BasicTest(model, "quinientos millones", "500000000"); BasicTest(model, "mil quinientos veintitres", "1523"); // a little number :p BasicTest(model, "tres billones cuatrocientos cincuenta y cinco mil doscientos veintiocho millones quinientos cincuenta y seis mil ochocientos treinta y dos", "3455228556832"); BasicTest(model, "tres billones cuatrocientos cincuenta y cinco mil doscientos veintiocho millones quinientos cincuenta y seis mil", "3455228556000"); BasicTest(model, "tres billones cuatrocientos cincuenta y cinco mil doscientos veintiocho millones", "3455228000000"); BasicTest(model, "tres billones cuatrocientos cincuenta y cinco mil millones", "3455000000000"); BasicTest(model, "tres billones", "3000000000000"); // super number :p - supported by extractor but not by parser //BasicTest(GetOrdinalModel(), "ciento sesenta y tres septillones quinientos ochenta y dos mil ochocientos setenta y un sextillones ciento dieciocho mil novecientos trece quintillones quinientos ochenta y cinco mil trescientos cuarenta y seis cuatrillones novecientos noventa y siete mil doscientos setenta y tres trillones cuatrocientos treinta y cuatro mil trescientos veinticinco billones quinientos cincuenta y cinco mil ochocientos veintiún millones novecientos cincuenta y tres mil seiscientos setenta y cinco", "163582871118913585346997273434325555821953675"); // numbers within sentences BasicTest(model, "dame un mil", "1000", "un mil"); BasicTest(model, "tirate un paso", "1", "un"); BasicTest(model, "voy a comprar solo una vaca", "1", "una"); BasicTest(model, "voy a comprar doscientas vacas", "200", "doscientas"); BasicTest(model, "tengo solamente mil cien pesos", "1100", "mil cien"); BasicTest(model, "tengo solamente siete mil doscientos treinta y cinco pesos", "7235", "siete mil doscientos treinta y cinco"); BasicTest(model, "no mucho, creo que voy a gastar algo asi como trece millones cuatrocientos cincuenta y dos mil trescientos cuarenta y siete bolivares en todo el proyecto", "13452347", "trece millones cuatrocientos cincuenta y dos mil trescientos cuarenta y siete"); #endregion #region Double numbers BasicTest(model, " 101231,2353", "101231,2353"); BasicTest(model, "-101231,4323", "-101231,4323"); BasicTest(model, " -89101231,5127", "-89101231,5127"); BasicTest(model, " -1,1234567", "-1,1234567"); BasicTest(model, "1.234.567,51274", "1234567,51274"); BasicTest(model, "192,", "192", "192"); BasicTest(model, ",23456000", "0,23456"); BasicTest(model, "4,800", "4,8"); BasicTest(model, ",08", "0,08"); BasicTest(model, "9,2321312", "9,2321312"); BasicTest(model, " -9,2321312", "-9,2321312"); BasicTest(model, "1e10", "10000000000"); BasicTest(model, "1,1^23", "8,95430243255239"); BasicTest(model, "siete con cincuenta", "7,5"); BasicTest(model, "cuarenta y siete coma veintiocho", "47,28"); BasicTest(model, "trescientos cuarenta y siete con quinientos doce", "347,512"); BasicTest(model, "dos mil trescientos cuarenta y siete coma mil quinientos setenta y ocho", "2347,1578"); BasicTest(model, "cincuenta y dos mil trescientos cuarenta y siete con doscientos", "52347,2"); BasicTest(model, "cuatrocientos cincuenta y dos mil trescientos cuarenta y siete coma veintidos", "452347,22"); BasicTest(model, "1,1^+23", "8,95430243255239"); BasicTest(model, "2,5^-1", "0,4"); BasicTest(model, "-2500^-1", "-0,0004"); BasicTest(model, "-1,1^+23", "-8,95430243255239"); BasicTest(model, "-2,5^-1", "-0,4"); BasicTest(model, "-1,1^--23", "-8,95430243255239"); BasicTest(model, "-127,32e13", "-1,2732E+15"); BasicTest(model, "12,32e+14", "1,232E+15"); BasicTest(model, "-12e-1", "-1,2"); #endregion #region Translated numbers from english BasicTest(model, "192.", "192", "192"); // '.' is group separator in spanish - so not understood as IP MultiTest(model, "192.168.1.2", 3); //this will be supported for the NumberWithUnitModel MultiTest(model, "son 180,25ml liquidos", 0); MultiTest(model, "son 180ml liquidos", 0); MultiTest(model, " 29km caminando ", 0); MultiTest(model, " subamos al 4to piso ", 0); MultiTest(model, "son ,25ml liquidos", 0); BasicTest(model, ",08", "0,08"); MultiTest(model, "uno", 1); MultiTest(model, "un", 1); BasicTest(model, ",23456000", "0,23456"); BasicTest(model, "4,800", "4,8"); BasicTest(model, "ciento tres con dos tercios", (103 + (double)2 / 3).ToString(ci)); BasicTest(model, "dieciseis", "16"); BasicTest(model, "dos tercios", ((double)2 / 3).ToString(ci)); BasicTest(model, "ciento dieciseis", "116"); BasicTest(model, "ciento seis", "106"); BasicTest(model, "ciento sesenta y un", "161"); BasicTest(model, "un billonesimo", "1E-12"); BasicTest(model, "cien billonesimos", "1E-10"); BasicTest(model, " media docena ", "6"); BasicTest(model, " 3 docenas", "36"); BasicTest(model, "una docena", "12"); BasicTest(model, " tres docenas ", "36"); BasicTest(model, "1.234.567", "1234567"); MultiTest(model, "1. 234. 567", 3); BasicTest(model, "9,2321312", "9,2321312"); BasicTest(model, " -9,2321312", "-9,2321312"); BasicTest(model, " -1", "-1"); BasicTest(model, "-4/5", "-0,8"); BasicTest(model, "- 1 4/5", "-1,8"); BasicTest(model, "tres", "3"); BasicTest(model, " 123456789101231", "123456789101231"); BasicTest(model, "-123456789101231", "-123456789101231"); BasicTest(model, " -123456789101231", "-123456789101231"); BasicTest(model, "1", "1"); BasicTest(model, "10k", "10000"); BasicTest(model, "10G", "10000000000"); BasicTest(model, "- 10 k", "-10000"); BasicTest(model, "2 millones", "2000000"); BasicTest(model, "1 billon", "1000000000000"); BasicTest(model, " tres ", "3"); BasicTest(model, "un billon", "1000000000000"); BasicTest(model, "veintiun billones", "21000000000000"); BasicTest(model, "veintiun billones trescientos", "21000000000300"); BasicTest(model, "cincuenta y dos", "52"); BasicTest(model, "trescientos treinta y uno", "331"); BasicTest(model, "doscientos dos mil", "202000"); BasicTest(model, "dos mil doscientos", "2200"); BasicTest(model, " 2,33 k", "2330"); BasicTest(model, " doscientos coma cero tres", "200,03"); BasicTest(model, " doscientos con setenta y uno", "200,71"); BasicTest(model, "1e10", "10000000000"); BasicTest(model, "1,1^23", "8,95430243255239"); BasicTest(model, " 322 millones ", "322000000"); BasicTest(model, "setenta", "70"); BasicTest(model, "cincuenta y dos", "52"); BasicTest(model, "2 1/4", "2,25"); BasicTest(model, "3/4", "0,75"); BasicTest(model, "un octavo", "0,125"); BasicTest(model, "cinco octavos", "0,625"); BasicTest(model, "un medio", "0,5"); BasicTest(model, "tres cuartos", "0,75"); BasicTest(model, "veinte con tres quintos", "20,6"); BasicTest(model, "veintitres quintos", "4,6"); BasicTest(model, "veintitres con tres quintos", "23,6"); BasicTest(model, "un millon dos mil doscientos tres quintos", "200440,6"); BasicTest(model, "uno con un medio", "1,5"); BasicTest(model, "uno con un cuarto", "1,25"); BasicTest(model, "cinco con un cuarto", "5,25"); BasicTest(model, "cien con tres cuartos", "100,75"); BasicTest(model, "un centesimo", "0,01"); #endregion }
public void InitializationNonLazy_CanGetModel() { var recognizer = new NumberRecognizer(EnglishCulture, NumberOptions.None, lazyInitialization: false); Assert.AreEqual(recognizer.GetNumberModel(), recognizer.GetNumberModel(EnglishCulture)); }
public void WithoutTargetCultureAndWithoutCulture_FallbackToEnglishCulture() { var recognizer = new NumberRecognizer(); Assert.AreEqual(recognizer.GetNumberModel(), recognizer.GetNumberModel(EnglishCulture)); }
public void WithInvalidCultureAsTargetAndWithoutFallback_ThrowError() { var recognizer = new NumberRecognizer(InvalidCulture); Assert.ThrowsException <ArgumentException>(() => recognizer.GetNumberModel(fallbackToDefaultCulture: false)); }
public void TestNumberModel() { var model = NumberRecognizer.GetNumberModel(Culture.English); WrappedTest(model, "192.", "192", "192"); MultiTest(model, "192.168.1.2", 4); MultiTest(model, "the 180.25ml liquid", 0); MultiTest(model, "the 180ml liquid", 0); MultiTest(model, " 29km Road ", 0); MultiTest(model, " the May 4th ", 0); MultiTest(model, "the .25ml liquid", 0); BasicTest(model, ".08", "0.08"); MultiTest(model, "an", 0); MultiTest(model, "a", 0); BasicTest(model, ".23456000", "0.23456"); BasicTest(model, "4.800", "4.8"); BasicTest(model, "one hundred and three and two thirds", (103 + (double)2 / 3).ToString()); BasicTest(model, "sixteen", "16"); BasicTest(model, "two thirds", ((double)2 / 3).ToString()); BasicTest(model, "one hundred and sixteen", "116"); BasicTest(model, "one hundred and six", "106"); BasicTest(model, "one hundred and sixty-one", "161"); BasicTest(model, "a trillionth", "1E-12"); BasicTest(model, "a hundred trillionths", "1E-10"); BasicTest(model, " half a dozen", "6"); BasicTest(model, " 3 dozens", "36"); BasicTest(model, "a dozen", "12"); BasicTest(model, " three dozens ", "36"); BasicTest(model, " three hundred and two dozens", "324"); BasicTest(model, "1,234,567", "1234567"); MultiTest(model, "1, 234, 567", 3); BasicTest(model, "9.2321312", "9.2321312"); BasicTest(model, " -9.2321312", "-9.2321312"); BasicTest(model, " -1", "-1"); BasicTest(model, "-4/5", "-0.8"); BasicTest(model, "- 1 4/5", "-1.8"); BasicTest(model, "three", "3"); BasicTest(model, " 123456789101231", "123456789101231"); BasicTest(model, "-123456789101231", "-123456789101231"); BasicTest(model, " -123456789101231", "-123456789101231"); BasicTest(model, "1", "1"); BasicTest(model, "10k", "10000"); BasicTest(model, "10G", "10000000000"); BasicTest(model, "- 10 k", "-10000"); BasicTest(model, "2 million", "2000000"); BasicTest(model, "1 trillion", "1000000000000"); BasicTest(model, " three ", "3"); BasicTest(model, "one trillion", "1000000000000"); BasicTest(model, "twenty-one trillion", "21000000000000"); BasicTest(model, "twenty-one trillion three hundred", "21000000000300"); BasicTest(model, "twenty-one trillion and three hundred", "21000000000300"); BasicTest(model, "fifty - two", "52"); BasicTest(model, "fifty two", "52"); BasicTest(model, "Three hundred and thirty one", "331"); BasicTest(model, "two hundred and two thousand", "202000"); BasicTest(model, "two thousand and two hundred", "2200"); BasicTest(model, " 2.33 k", "2330"); BasicTest(model, " two hundred point zero three", "200.03"); BasicTest(model, " two hundred point seventy-one", "200.71"); BasicTest(model, "1e10", "10000000000"); BasicTest(model, "1.1^23", "8.95430243255239"); BasicTest(model, " 322 hundred ", "32200"); BasicTest(model, "three", "3"); BasicTest(model, "seventy", "70"); BasicTest(model, "fifty-two", "52"); BasicTest(model, "2 1/4", "2.25"); BasicTest(model, "3/4", "0.75"); BasicTest(model, "one eighth", "0.125"); BasicTest(model, "five eighths", "0.625"); BasicTest(model, "a half", "0.5"); BasicTest(model, "three quarters", "0.75"); BasicTest(model, "twenty and three fifths", "20.6"); BasicTest(model, "twenty-three fifths", "4.6"); BasicTest(model, "twenty and three and three fifths", "23.6"); BasicTest(model, "one million two thousand two hundred three fifths", "200440.6"); BasicTest(model, "one and a half", "1.5"); BasicTest(model, "one and a fourth", "1.25"); BasicTest(model, "five and a quarter", "5.25"); BasicTest(model, "one hundred and three quarters", "100.75"); BasicTest(model, "a hundredth", "0.01"); BasicTest(model, "1.1^+23", "8.95430243255239"); BasicTest(model, "2.5^-1", "0.4"); BasicTest(model, "-2500^-1", "-0.0004"); BasicTest(model, "-1.1^+23", "-8.95430243255239"); BasicTest(model, "-2.5^-1", "-0.4"); BasicTest(model, "-1.1^--23", "-8.95430243255239"); BasicTest(model, "-127.32e13", "-1.2732E+15"); BasicTest(model, "12.32e+14", "1.232E+15"); BasicTest(model, "-12e-1", "-1.2"); BasicTest(model, "1.2b", "1200000000"); }
public void WithOtherCulture_NotUseTargetCulture() { var recognizer = new NumberRecognizer(EnglishCulture); Assert.AreNotEqual(recognizer.GetNumberModel(SpanishCulture), recognizer.GetNumberModel()); }
public void WithInvalidCulture_UseTargetCulture() { var recognizer = new NumberRecognizer(EnglishCulture); Assert.AreEqual(recognizer.GetNumberModel(InvalidCulture), recognizer.GetNumberModel()); }
public void TestNumberModel() { var model = NumberRecognizer.GetNumberModel(Culture.Chinese); #region Integer numbers BasicTest(model, "肆佰陸拾", "460"); BasicTest(model, "十 余 万", "100000"); BasicTest(model, "一百五十二", "152"); BasicTest(model, "壹佰伍拾", "150"); BasicTest(model, "两千四百五", "2450"); BasicTest(model, "负三十二", "-32"); MultiTest(model, "万", 0); MultiTest(model, "万万", 0); BasicTest(model, "二", "2"); BasicTest(model, "10万万", "1000000000"); BasicTest(model, "4.78万亿", "4780000000000"); BasicTest(model, "7 万5 千4 百", "75400"); BasicTest(model, "40k", "40000"); BasicTest(model, "二十 億", "2000000000"); BasicTest(model, "4,565", "4565"); BasicTest(model, "四百五十", "450"); BasicTest(model, "四百五", "450"); BasicTest(model, "一千零一", "1001"); BasicTest(model, "一百零一万一千", "1011000"); BasicTest(model, "一千两百三十四万", "12340000"); BasicTest(model, "五亿零六", "500000006"); BasicTest(model, "七十八万五佰零六", "780506"); BasicTest(model, "肆拾肆", "44"); BasicTest(model, "倆千两百贰拾二", "2222"); BasicTest(model, "5万4千6百", "54600"); BasicTest(model, "5亿1万4千6百", "500014600"); BasicTest(model, "-10000", "-10000"); BasicTest(model, "一打", "12"); BasicTest(model, "拾万零五十六", "100056"); BasicTest(model, "十", "10"); BasicTest(model, "十五", "15"); BasicTest(model, "一百", "100"); BasicTest(model, "九百九十九", "999"); BasicTest(model, "九百九", "990"); BasicTest(model, "二百五十", "250"); BasicTest(model, "一千零五十", "1050"); BasicTest(model, "一千零五", "1005"); BasicTest(model, "一千陆", "1600"); BasicTest(model, "一万三", "13000"); BasicTest(model, "一万二百五十", "10250"); BasicTest(model, "一万零二百五十", "10250"); BasicTest(model, "九万四", "94000"); BasicTest(model, "九十二万四", "924000"); BasicTest(model, "九万零四百", "90400"); BasicTest(model, "九百万零四百", "9000400"); BasicTest(model, "四千零五万", "40050000"); BasicTest(model, "四千万", "40000000"); BasicTest(model, "四千万零六千", "40006000"); BasicTest(model, "四亿", "400000000"); BasicTest(model, "四亿五千六百四十二万零一十五", "456420015"); BasicTest(model, "四万五千六百二十二", "45622"); BasicTest(model, "五兆六十二亿四万五千二", "5006200045200"); BasicTest(model, "五十五兆一十二亿四万五千二", "55001200045200"); BasicTest(model, "十万柒仟捌佰伍拾肆", "107854"); BasicTest(model, "半百", "50"); BasicTest(model, "拾万零五十六", "100056"); BasicTest(model, "拾六万零五百零六", "160506"); BasicTest(model, "拾亿零六万零五百零六", "1000060506"); BasicTest(model, "一百万零四", "1000004"); BasicTest(model, "四十万", "400000"); BasicTest(model, "四千零四万", "40040000"); BasicTest(model, "四十五亿四千零四万", "4540040000"); BasicTest(model, "负四十五亿零四百零四万", "-4504040000"); BasicTest(model, "负四百零五亿零四百零四万", "-40504040000"); BasicTest(model, "四万万", "400000000"); BasicTest(model, "五十打", "600"); BasicTest(model, "百三", "130"); MultiTest(model, "1, 234, 567", 3); MultiTest(model, "二百五, 二百五, 还有二百五。", 3); MultiTest(model, "1502222, 二百五, 还有二分之。", 3); MultiTest(model, "199个", 1); BasicTest(model, "1,050,000,000", "1050000000"); BasicTest(model, "两千三百五", "2350"); BasicTest(model, "一百 五 十 二", "152"); BasicTest(model, "两千 四 百 五", "2450"); BasicTest(model, "7万 5千 4百", "75400"); BasicTest(model, "三千 八百 九十六 万 四千 九百 六十五", "38964965"); BasicTest(model, "三千 九百 六十五 ", "3965"); BasicTest(model, "五百 余万", "5000000"); BasicTest(model, "一千多万", "10000000"); BasicTest(model, "十多万", "100000"); BasicTest(model, "二十几万", "200000"); BasicTest(model, "一百零几万", "1000000"); BasicTest(model, "一千五百零几万", "15000000"); BasicTest(model, "一百 二 十 几亿", "12000000000"); BasicTest(model, "三双", "6"); BasicTest(model, "一百对", "200"); BasicTest(model, "十双", "20"); BasicTest(model, "一百五十对", "300"); MultiOneTest(model, "十打苹果", 1, "120"); MultiTest(model, "1991年1月16日晚巴黎时间20点:法国总统密特朗发表电视讲话,宣布和平解决海湾危机已经让位于战争,法国已经作好一切战斗准备。", 4); BasicTest(model, "500余万", "5000000"); BasicTest(model, "八千 三百 八十五 万 二千 三百 二十六 点三三", "83852326.33"); BasicTest(model, "2^5", "32"); BasicTest(model, "2e5", "200000"); MultiOneTest(model, "四百多", 1, "400"); BasicTest(model, "两双", "4"); BasicTest(model, "一百五 ", "150"); BasicTest(model, "十 余 萬", "100000"); BasicTest(model, "壹百五十二", "152"); BasicTest(model, "壹佰伍拾", "150"); BasicTest(model, "兩千四百五", "2450"); BasicTest(model, "負三十二", "-32"); MultiTest(model, "萬", 0); MultiTest(model, "萬萬", 0); BasicTest(model, "二", "2"); BasicTest(model, "10萬萬", "1000000000"); BasicTest(model, "4.78萬億", "4780000000000"); BasicTest(model, "7 萬5 千4 百", "75400"); BasicTest(model, "40k", "40000"); BasicTest(model, "二十 億", "2000000000"); BasicTest(model, "4,565", "4565"); BasicTest(model, "四百五十", "450"); BasicTest(model, "四百五", "450"); BasicTest(model, "壹千零壹", "1001"); BasicTest(model, "壹百零壹萬壹千", "1011000"); BasicTest(model, "壹千兩百三十四萬", "12340000"); BasicTest(model, "五億零六", "500000006"); BasicTest(model, "七十八萬五佰零六", "780506"); BasicTest(model, "肆拾肆", "44"); BasicTest(model, "兩千兩百貳拾二", "2222"); BasicTest(model, "5萬4千6百", "54600"); BasicTest(model, "5億1萬4千6百", "500014600"); BasicTest(model, "-10000", "-10000"); BasicTest(model, "壹打", "12"); BasicTest(model, "拾萬零五十六", "100056"); BasicTest(model, "十", "10"); BasicTest(model, "十五", "15"); BasicTest(model, "壹百", "100"); BasicTest(model, "九百九十九", "999"); BasicTest(model, "九百九", "990"); BasicTest(model, "二百五十", "250"); BasicTest(model, "壹千零五十", "1050"); BasicTest(model, "壹千零五", "1005"); BasicTest(model, "壹千六", "1600"); BasicTest(model, "壹萬三", "13000"); BasicTest(model, "壹萬二百五十", "10250"); BasicTest(model, "壹萬零二百五十", "10250"); BasicTest(model, "九萬四", "94000"); BasicTest(model, "九十二萬四", "924000"); BasicTest(model, "九萬零四百", "90400"); BasicTest(model, "九百萬零四百", "9000400"); BasicTest(model, "四千零五萬", "40050000"); BasicTest(model, "四千萬", "40000000"); BasicTest(model, "四千萬零六千", "40006000"); BasicTest(model, "四億", "400000000"); BasicTest(model, "四億五千六百四十二萬零壹十五", "456420015"); BasicTest(model, "四萬五千六百二十二", "45622"); BasicTest(model, "五兆六十二億四萬五千二", "5006200045200"); BasicTest(model, "五十五兆壹十二億四萬五千二", "55001200045200"); BasicTest(model, "十萬柒仟捌佰伍拾肆", "107854"); BasicTest(model, "半百", "50"); BasicTest(model, "拾萬零五十六", "100056"); BasicTest(model, "拾六萬零五百零六", "160506"); BasicTest(model, "拾億零六萬零五百零六", "1000060506"); BasicTest(model, "壹百萬零四", "1000004"); BasicTest(model, "四十萬", "400000"); BasicTest(model, "四千零四萬", "40040000"); BasicTest(model, "四十五億四千零四萬", "4540040000"); BasicTest(model, "負四十五億零四百零四萬", "-4504040000"); BasicTest(model, "負四百零五億零四百零四萬", "-40504040000"); BasicTest(model, "四萬萬", "400000000"); BasicTest(model, "五十打", "600"); BasicTest(model, "百三", "130"); BasicTest(model, "5,236", "5236"); MultiTest(model, "1, 234, 567", 3); MultiTest(model, "二百五, 二百五, 還有二百五。", 3); MultiTest(model, "1502222, 二百五, 還有二分之。", 3); MultiTest(model, "199個", 1); BasicTest(model, "1,050,000,000", "1050000000"); BasicTest(model, "兩千三百五", "2350"); BasicTest(model, "壹百 五 十 二", "152"); BasicTest(model, "兩千 四 百 五", "2450"); BasicTest(model, "7萬 5千 4百", "75400"); BasicTest(model, "三千 八百 九十六 萬 四千 九百 六十五", "38964965"); BasicTest(model, "三千 九百 六十五 ", "3965"); BasicTest(model, "五百 余萬", "5000000"); BasicTest(model, "壹千多萬", "10000000"); BasicTest(model, "十多萬", "100000"); BasicTest(model, "二十幾萬", "200000"); BasicTest(model, "壹百零幾萬", "1000000"); BasicTest(model, "壹千五百零幾萬", "15000000"); BasicTest(model, "壹百 二 十 幾億", "12000000000"); BasicTest(model, "三雙", "6"); BasicTest(model, "壹百對", "200"); BasicTest(model, "十雙", "20"); BasicTest(model, "壹百五十對", "300"); MultiOneTest(model, "十打蘋果", 1, "120"); MultiTest(model, "1991年1月16日晚巴黎時間20點:法國總統密特朗發表電視講話,宣布和平解抉海灣危機已經讓位於戰爭,法國已經作好壹切戰鬥準備。", 4); BasicTest(model, "500余萬", "5000000"); BasicTest(model, "八千 三百 八十五 萬 二千 三百 二十六 點三三", "83852326.33"); BasicTest(model, "2^5", "32"); BasicTest(model, "2e5", "200000"); MultiOneTest(model, "四百多", 1, "400"); BasicTest(model, "兩雙", "4"); BasicTest(model, "壹百五 ", "150"); #endregion #region Double numbers MultiTest(model, "百分之五十五点五七九", 0); MultiTest(model, "百分之十万零六百五十一", 0); MultiTest(model, "六千零五十一个百分点", 0); MultiTest(model, "六百一十一点二五五个百分点", 0); BasicTest(model, "负六点六", "-6.6"); BasicTest(model, "十五点七", "15.7"); BasicTest(model, "11.92亿", "1192000000"); BasicTest(model, "2.2", "2.2"); BasicTest(model, "2.2亿", "220000000"); BasicTest(model, "1000 万", "10000000"); BasicTest(model, "21.2E0", "21.2"); BasicTest(model, "2^-1", "0.5"); BasicTest(model, "四百 点 五", "400.5"); BasicTest(model, "零点五", "0.5"); BasicTest(model, "10.233", "10.233"); BasicTest(model, "-1e1", "-10"); BasicTest(model, "-2.5 M", "-2500000"); BasicTest(model, "二点五", "2.5"); BasicTest(model, "十点二三三", "10.233"); BasicTest(model, "两千万点五五四四", "20000000.5544"); BasicTest(model, "两千点零", "2000"); BasicTest(model, "两千三点一", "2300.1"); BasicTest(model, "10.233", "10.233"); BasicTest(model, "10,000.233", "10000.233"); BasicTest(model, ".23456000", "0.23456"); BasicTest(model, "4.800", "4.8"); BasicTest(model, "2.7890", "2.789"); BasicTest(model, "2.3", "2.3"); BasicTest(model, "2.3万", "23000"); BasicTest(model, "2.7890e-1", "0.2789"); BasicTest(model, ".5", "0.5"); BasicTest(model, "-.5", "-0.5"); MultiTest(model, "1, 234, 567.3", 3); MultiTest(model, "1, 244, 667.123 五点八", 4); MultiTest(model, "二百三十三,五百七十七,一千六点五。", 3); MultiTest(model, "2222.2222.22222.222", 4); MultiOneTest(model, "...9", 1, "9"); MultiOneTest(model, "--9", 1, "9"); BasicTest(model, "1.1^+23", "8.95430243255239"); BasicTest(model, "2.5^-1", "0.4"); BasicTest(model, "-1.1^+23", "-8.95430243255239"); BasicTest(model, "-2.5^-1", "-0.4"); BasicTest(model, "-1.1^--23", "-8.95430243255239"); BasicTest(model, "-127.32e13", "-1.2732E+15"); BasicTest(model, "12.32e+14", "1.232E+15"); BasicTest(model, "-12e-1", "-1.2"); #endregion }
public void TestFractionModel() { var model = NumberRecognizer.GetNumberModel(Culture.English); BasicTest(model, "a fifth", "0.2"); BasicTest(model, "a trillionth", "1E-12"); BasicTest(model, "a hundred thousand trillionths", "1E-07"); BasicTest(model, "one fifth", "0.2"); BasicTest(model, "three fifths", "0.6"); BasicTest(model, "twenty fifths", "4"); BasicTest(model, "twenty-three fifths", "4.6"); BasicTest(model, "three and a fifth", "3.2"); BasicTest(model, "twenty one fifths", "4.2"); BasicTest(model, "a twenty-first", ((double)1 / 21).ToString()); BasicTest(model, "one twenty-fifth", ((double)1 / 25).ToString()); BasicTest(model, "three twenty-firsts", ((double)3 / 21).ToString()); BasicTest(model, "three twenty firsts", ((double)3 / 21).ToString()); BasicTest(model, "twenty twenty fifths", "0.8"); // act like Google BasicTest(model, "one hundred and thirty fifths", ((double)130 / 5).ToString()); BasicTest(model, "one hundred thirty fifths", ((double)100 / 35).ToString()); BasicTest(model, "one hundred thirty two fifths", ((double)132 / 5).ToString()); BasicTest(model, "one hundred thirty-two fifths", ((double)132 / 5).ToString()); BasicTest(model, "one hundred and thirty-two fifths", ((double)132 / 5).ToString()); BasicTest(model, "one hundred and thirty and two fifths", (130 + (double)2 / 5).ToString()); BasicTest(model, "one hundred thirty-fifths", ((double)100 / 35).ToString()); BasicTest(model, "one one hundred fifth", ((double)1 / 105).ToString()); BasicTest(model, "one one hundred and fifth", ((double)1 / 105).ToString()); BasicTest(model, "one hundred one thousand fifths", ((double)100 / 1005).ToString()); BasicTest(model, "one over three", ((double)1 / 3).ToString()); BasicTest(model, "1 over twenty-one", ((double)1 / 21).ToString()); BasicTest(model, "1 over one hundred and twenty one", ((double)1 / 121).ToString()); BasicTest(model, "1 over three", ((double)1 / 3).ToString()); BasicTest(model, "1 over 3", ((double)1 / 3).ToString()); BasicTest(model, "one over 3", ((double)1 / 3).ToString()); BasicTest(model, "one over 20", ((double)1 / 20).ToString()); BasicTest(model, "one over twenty", ((double)1 / 20).ToString()); BasicTest(model, "one over one hundred", ((double)1 / 100).ToString()); BasicTest(model, "one over one hundred and twenty five", ((double)1 / 125).ToString()); BasicTest(model, "ninety - five hundred fifths", ((double)9500 / 5).ToString()); }