Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Threading;
- using System.Threading.Tasks;
- using Microsoft.Bot.Builder.Scorables.Internals;
- using Microsoft.Bot.Connector;
- using Microsoft.Bot.Builder.Internals.Fibers;
- using Microsoft.Bot.Builder.Dialogs.Internals;
- using System;
- using Bayteq.BotServer.Core.Conversation.Dialogs;
- using Microsoft.Bot.Builder.Dialogs;
- using Bayteq.Infrastructure.SpellCheck;
- namespace Bayteq.BotServer.Core.Conversation.Scorables
- {
- [Serializable]
- class SpellCheckScorable : ScorableBase<IActivity, string, double>
- {
- private readonly IDialogTask task;
- private string original;
- public SpellCheckScorable(IMessageActivity activity)
- {
- SetField.NotNull(out this.task, nameof(task), task);
- }
- protected override Task DoneAsync(IActivity item, string correction, CancellationToken token)
- {
- return Task.CompletedTask;
- }
- protected override double GetScore(IActivity item, string correction)
- {
- return original != correction ? 1 : 0;
- }
- protected override bool HasScore(IActivity item, string correction)
- {
- return original != correction;
- }
- protected override async Task PostAsync(IActivity item, string correction, CancellationToken token)
- {
- var spellCheckDialog = new SpellCheckDialog(original, correction);
- var interruption = spellCheckDialog.Void<string, IMessageActivity>();
- task.Call(interruption, null);
- await task.PollAsync(token);
- }
- protected override async Task<string> PrepareAsync(IActivity item, CancellationToken token)
- {
- original = item.AsMessageActivity().Text;
- return await SpellCheck.SpellCheckAsync(item.AsMessageActivity().Text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement