Exemple #1
0
        public static void SDSampleCallback(IAsyncResult iAsyncResult)
        {
            MappingRecognizeAsyncResult asyncResult =
                (MappingRecognizeAsyncResult)iAsyncResult;

            if (asyncResult.Succeeded)
            {
                try
                {
                    MappingDataRange[] ranges = asyncResult.PropertyBag.GetResultRanges();
                    Console.WriteLine("Recognized {0} script ranges", ranges.Length);
                    NullTerminatedStringFormatter formatter = new NullTerminatedStringFormatter();
                    foreach (MappingDataRange range in ranges)
                    {
                        Console.WriteLine("Range from {0} to {1}, script {2}, text \"{3}\"",
                                          range.StartIndex, range.EndIndex, range.FormatData(formatter),
                                          asyncResult.Text.Substring((int)range.StartIndex,
                                                                     (int)(range.EndIndex - range.StartIndex + 1)));
                    }
                }
                finally
                {
                    asyncResult.PropertyBag.Dispose();
                }
            }
            else
            {
                Console.WriteLine("Error calling ELS: {0}, HResult: {1}",
                                  asyncResult.ResultState.ErrorMessage, asyncResult.ResultState.HResult);
            }
        }
Exemple #2
0
 public static void SDUsageSampleAsync()
 {
     try
     {
         MappingService scriptDetection = new MappingService(
             MappingAvailableServices.ScriptDetection);
         MappingRecognizeAsyncResult asyncResult = scriptDetection.BeginRecognizeText(
             "This is English. АБВГД.", null, SDSampleCallback, null);
         MappingService.EndRecognizeText(asyncResult);
     }
     catch (LinguisticException exc)
     {
         Console.WriteLine("Error calling ELS: {0}, HResult: {1}",
                           exc.ResultState.ErrorMessage, exc.ResultState.HResult);
     }
 }