66using System . Globalization ;
77using System . Linq ;
88using System . Text ;
9+ using System . Text . RegularExpressions ;
910using Microsoft . Recognizers . Text ;
1011using Microsoft . Recognizers . Text . Choice ;
1112using Microsoft . Recognizers . Text . DateTime ;
@@ -28,8 +29,19 @@ public static void Main(string[] args)
2829
2930 ShowIntro ( ) ;
3031
32+ Console . InputEncoding = Encoding . UTF8 ;
33+ Console . OutputEncoding = Encoding . UTF8 ;
34+ string culture = DefaultCulture ;
35+ bool cultureSet = false ;
36+
3137 while ( true )
3238 {
39+ if ( ! cultureSet )
40+ {
41+ culture = SetCulture ( ) ;
42+ cultureSet = true ;
43+ }
44+
3345 // Read the text to recognize
3446 Console . WriteLine ( "Enter the text to recognize:" ) ;
3547 var input = Console . ReadLine ( ) ? . Trim ( ) ;
@@ -41,11 +53,17 @@ public static void Main(string[] args)
4153 break ;
4254 }
4355
56+ if ( input ? . ToLower ( CultureInfo . InvariantCulture ) == "switch" )
57+ {
58+ cultureSet = false ;
59+ continue ;
60+ }
61+
4462 // Validate input
4563 if ( input ? . Length > 0 )
4664 {
4765 // Retrieve all the parsers and call 'Parse' to recognize all the values from the user input
48- var results = ParseAll ( input , DefaultCulture ) ;
66+ var results = ParseAll ( input , culture ) ;
4967
5068 // Write output
5169 Console . WriteLine ( results . Any ( ) ? $ "I found the following entities ({ results . Count ( ) : d} ):" : "I found no entities." ) ;
@@ -55,6 +73,34 @@ public static void Main(string[] args)
5573 }
5674 }
5775
76+ private static string SetCulture ( )
77+ {
78+ string supportedCultures = string . Empty ;
79+ for ( int i = 0 ; i < Culture . SupportedCultures . Length ; i ++ )
80+ {
81+ supportedCultures += ( i + 1 ) + ": " + Culture . SupportedCultures [ i ] . CultureName +
82+ ( ( i == Culture . SupportedCultures . Length - 1 ) ? string . Empty : Environment . NewLine ) ;
83+ }
84+
85+ Console . WriteLine ( supportedCultures + Environment . NewLine + "Please select language: " ) ;
86+ string culture = string . Empty ;
87+ if ( int . TryParse ( Console . ReadLine ( ) ? . Trim ( ) , out int num ) && num >= 1 && num <= Culture . SupportedCultures . Length )
88+ {
89+ culture = Culture . SupportedCultures [ num - 1 ] . CultureCode ;
90+ }
91+ else
92+ {
93+ culture = DefaultCulture ;
94+ }
95+
96+ var cultureName = Culture . SupportedCultures
97+ . Where ( c => c . CultureCode == culture )
98+ . Select ( c => c . CultureName )
99+ . FirstOrDefault ( ) ;
100+ Console . WriteLine ( "Culture {0},{1} is set." , cultureName , culture ) ;
101+ return culture ;
102+ }
103+
58104 /// <summary>
59105 /// Parse query with all recognizers.
60106 /// </summary>
0 commit comments