Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. using System.Threading;
  2. using System.Threading.Tasks;
  3. using Microsoft.Bot.Builder.Scorables.Internals;
  4. using Microsoft.Bot.Connector;
  5. using Microsoft.Bot.Builder.Internals.Fibers;
  6. using Microsoft.Bot.Builder.Dialogs.Internals;
  7. using System;
  8. using Bayteq.BotServer.Core.Conversation.Dialogs;
  9. using Microsoft.Bot.Builder.Dialogs;
  10. using Bayteq.Infrastructure.SpellCheck;
  11.  
  12. namespace Bayteq.BotServer.Core.Conversation.Scorables
  13. {
  14. [Serializable]
  15. class SpellCheckScorable : ScorableBase<IActivity, string, double>
  16. {
  17. private readonly IDialogTask task;
  18. private string original;
  19.  
  20. public SpellCheckScorable(IMessageActivity activity)
  21. {
  22. SetField.NotNull(out this.task, nameof(task), task);
  23. }
  24.  
  25. protected override Task DoneAsync(IActivity item, string correction, CancellationToken token)
  26. {
  27. return Task.CompletedTask;
  28. }
  29.  
  30. protected override double GetScore(IActivity item, string correction)
  31. {
  32. return original != correction ? 1 : 0;
  33. }
  34.  
  35. protected override bool HasScore(IActivity item, string correction)
  36. {
  37. return original != correction;
  38. }
  39.  
  40. protected override async Task PostAsync(IActivity item, string correction, CancellationToken token)
  41. {
  42. var spellCheckDialog = new SpellCheckDialog(original, correction);
  43. var interruption = spellCheckDialog.Void<string, IMessageActivity>();
  44. task.Call(interruption, null);
  45. await task.PollAsync(token);
  46. }
  47.  
  48.  
  49. protected override async Task<string> PrepareAsync(IActivity item, CancellationToken token)
  50. {
  51. original = item.AsMessageActivity().Text;
  52. return await SpellCheck.SpellCheckAsync(item.AsMessageActivity().Text);
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement