Example #1
0
 public static void SDUsageSample()
 {
     try
     {
         MappingService scriptDetection = new MappingService(
             MappingAvailableServices.ScriptDetection);
         using (MappingPropertyBag bag =
                    scriptDetection.RecognizeText("This is English. АБВГД.", null))
         {
             MappingDataRange[] ranges = bag.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}",
                                   range.StartIndex, range.EndIndex, range.FormatData(formatter));
             }
         }
     }
     catch (LinguisticException exc)
     {
         Console.WriteLine("Error calling ELS: {0}, HResult: {1}",
                           exc.ResultState.ErrorMessage, exc.ResultState.HResult);
     }
 }
Example #2
0
 public static void SDUsageSample()
 {
     try
     {
         MappingService scriptDetection = new MappingService(
             MappingAvailableServices.ScriptDetection);
         using (MappingPropertyBag bag =
             scriptDetection.RecognizeText("This is English. АБВГД.", null))
         {
             MappingDataRange[] ranges = bag.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}",
                     range.StartIndex, range.EndIndex, range.FormatData(formatter));
             }
         }
     }
     catch (LinguisticException exc)
     {
         Console.WriteLine("Error calling ELS: {0}, HResult: {1}",
             exc.ResultState.ErrorMessage, exc.ResultState.HResult);
     }
 }
Example #3
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);
            }
        }
Example #4
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);
     }
 }