/// <summary> /// Query the LUIS service using this request. /// </summary> /// <param name="service">LUIS service.</param> /// <param name="request">Query request.</param> /// <param name="token">Cancellation token.</param> /// <returns>LUIS result.</returns> public static async Task <LuisResult> QueryAsync(this ILuisService service, LuisRequest request, CancellationToken token) { service.ModifyRequest(request); var uri = service.BuildUri(request); return(await service.QueryAsync(uri, token)); }
/// <summary> /// Query the LUIS service using this text. /// </summary> /// <param name="service">LUIS service.</param> /// <param name="text">The query text.</param> /// <param name="token">The cancellation token.</param> /// <returns>The LUIS result.</returns> public static async Task <LuisResult> QueryAsync(this ILuisService service, string text, CancellationToken token) { var translated = Translate((service as LuisService).model, text); var uri = service.BuildUri(new LuisRequest(query: translated)); return(await service.QueryAsync(uri, token)); }
protected override async Task <string> PrepareAsync(IActivity item, CancellationToken token) { if (item.Type == ActivityTypes.Message) { string message = ((IMessageActivity)item).Text; try { LuisResult result = await luisService.QueryAsync(message, token); if (result.TopScoringIntent.Score > 0.8) { luisResults.Add(message, result); return(message); } } catch (Exception e) { logger.Error("Error occured querying LUIS", e); return(null); } } return(null); }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> item) { var message = await item; var paramValue = message.Text; var result = await service.QueryAsync(paramValue.ToString(), context.CancellationToken); var queryIntent = result.Intents.FirstOrDefault(); ReservationManagement management = new ReservationManagement(); List <string> roomNameList = management.GetAvailableReservation("1시"); if (roomNameList.Count > 0) { string meetingRoomName; //사용자의 입력에 meetingRooom entity가 존재하는지만 체크 var availableMeetingRoom = string.Join(", ", roomNameList.ToArray()); await context.PostAsync($"사용가능한 회의실은 {availableMeetingRoom} 입니다."); //context.Wait(this.MessageReceivedAsync); context.Done <object>(null); } else { await context.PostAsync($"해당 시간에 사용 가능한 회의실이 없습니다."); context.Done <object>(null); } }
public static async Task <QueryValueResult> QueryValueFromLuisAsync( ILuisService service, ILuisAction action, string paramName, object paramValue, CancellationToken token, Func <PropertyInfo, IEnumerable <EntityRecommendation>, EntityRecommendation> entityExtractor = null) { var originalValue = paramValue; if (service == null) { throw new ArgumentNullException(nameof(service)); } if (action == null) { throw new ArgumentNullException(nameof(action)); } if (string.IsNullOrWhiteSpace(paramName)) { throw new ArgumentNullException(nameof(paramName)); } if (paramValue == null) { throw new ArgumentNullException(nameof(paramValue)); } var result = await service.QueryAsync(paramValue.ToString(), token); var queryIntent = result.Intents.FirstOrDefault(); if (!Intents.None.Equals(queryIntent.Intent, StringComparison.InvariantCultureIgnoreCase)) { var newIntentName = default(string); var newAction = new LuisActionResolver(action.GetType().Assembly).ResolveActionFromLuisIntent(result, out newIntentName); if (newAction != null) { return(new QueryValueResult(false) { NewAction = newAction, NewIntent = newIntentName }); } } var properties = new List <PropertyInfo> { action.GetType().GetProperty(paramName, BindingFlags.Public | BindingFlags.Instance) }; if (!LuisActionResolver.AssignEntitiesToMembers(action, properties, result.Entities, entityExtractor)) { return(new QueryValueResult(AssignValue(action, properties.First(), originalValue))); } return(new QueryValueResult(true)); }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> item) { string month; var message = await item; var paramValue = message.Text; var result = await _service.QueryAsync(paramValue.ToString(), context.CancellationToken); var entity = result.Entities; string sat; var queryIntent = result.Intents.FirstOrDefault().Score < 0.6 ? "None" : result.Intents.FirstOrDefault().Intent; //None으로 잘 안떨어진다. 스코어가 0.4 이하인것들은 None으로 보겠다. if (!"None".Equals(queryIntent, StringComparison.InvariantCultureIgnoreCase) && !intent.Equals(queryIntent, StringComparison.InvariantCultureIgnoreCase)) { /* * Intent가 None값이라면.. 질의에 대한 대답으로 판단. * 새로운 Intent라면 시나리오 변경. */ PromptDialog.Confirm(context, this.ChangeIntentConfirm, "응? 휴가 안가실건가요?"); } else { if (!AssignEntities(result, out sat)) { await context.PostAsync(sat); context.Wait(this.MessageReceivedAsync); } else { //날짜 검증 /* * 1. 유효한 날짜인가 검증. * - 답변 : 날짜 입력 형식이 맞지 않습니다. ~ (##### 이렇게 입력하시오) */ string validateMessage; if (!ValidateDateFormat(day, out validateMessage)) { await context.PostAsync(validateMessage); context.Wait(this.MessageReceivedAsync); } else //유효한 날짜가 입력되었다 { //날짜를 넘겨주자. context.Done <Object>(null); } } } }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> item) { var message = await item; if (message != null) { //var message = await item; var paramValue = message.Text; var result = await _service.QueryAsync(paramValue.ToString(), context.CancellationToken); var queryIntent = result.Intents.FirstOrDefault(); if (!"None".Equals(queryIntent.Intent, StringComparison.InvariantCultureIgnoreCase)) { /* * Intent가 None값이라면.. 질의에 대한 대답으로 판단. * 새로운 Intent라면 시나리오 변경. */ PromptDialog.Confirm(context, this.ChangeIntentConfirm, "응? 휴가 안가실건가요?"); } else { //날짜 검증 /* * 1. 유효한 날짜인가 (자릿수, 숫자, 문자 등) * - 답변 : 날짜 입력 형식이 맞지 않습니다. ~ (##### 이렇게 입력하시오) */ if (!ValidateDateFormat(paramValue)) { await context.PostAsync("날짜 입력 형식이 맞지 않습니다. 다시 확인해주시겠어요?~^^ (예 : 2017년 10월 31일 출발인 경우 171031로 입력해주세요)"); context.Wait(this.MessageReceivedAsync); } else //유효한 날짜가 입력되었다. { //날짜를 넘겨주면 되겠다. 예약번호가 180402라고 치고 context.Done <Object>(null); } } } else { await context.PostAsync("탑승일 날짜를 입력해라. 이렇게 180402"); context.Wait(this.MessageReceivedAsync); } }
protected virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> item) { var message = await item; var luisRequest = new LuisRequest(query: message.Text, contextId: this.contextId); var result = await luisService.QueryAsync(luisService.BuildUri(luisService.ModifyRequest(luisRequest)), context.CancellationToken); if (result.Dialog.Status != DialogResponse.DialogStatus.Finished) { this.contextId = result.Dialog.ContextId; this.prompt = result.Dialog.Prompt; await context.PostAsync(this.prompt); context.Wait(MessageReceivedAsync); } else { context.Done(result); } }
/// <summary> /// Query the LUIS service using this text. /// </summary> /// <param name="service">LUIS service.</param> /// <param name="text">The query text.</param> /// <param name="token">The cancellation token.</param> /// <returns>The LUIS result.</returns> public static async Task <LuisResult> QueryAsync(this ILuisService service, string text, CancellationToken token) { var luisRequest = service.ModifyRequest(new LuisRequest(query: text)); return(await service.QueryAsync(luisRequest, token)); }
/// <summary> /// Query the LUIS service using this text. /// </summary> /// <param name="service">LUIS service.</param> /// <param name="text">The query text.</param> /// <param name="token">The cancellation token.</param> /// <returns>The LUIS result.</returns> public static async Task <LuisResult> QueryAsync(this ILuisService service, string text, CancellationToken token) { var uri = service.BuildUri(new LuisRequest(query: text)); return(await service.QueryAsync(uri, token)); }
/// <summary> /// Query the LUIS service using this text. /// </summary> /// <param name="service">LUIS service.</param> /// <param name="text">The query text.</param> /// <returns>The LUIS result.</returns> public static async Task <LuisResult> QueryAsync(this ILuisService service, string text) { var uri = service.BuildUri(text); return(await service.QueryAsync(uri)); }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> item) { var message = await item; var paramValue = message.Text; var result = await service.QueryAsync(paramValue.ToString(), context.CancellationToken); var queryIntent = result.Intents.FirstOrDefault(); if (!"None".Equals(queryIntent.Intent, StringComparison.InvariantCultureIgnoreCase) && !"MS.MeetingRoom.Book".Equals(queryIntent.Intent, StringComparison.InvariantCultureIgnoreCase)) { /* * Intent가 None값이라면.. 질의에 대한 대답으로 판단. * 새로운 Intent라면 시나리오 변경. */ QueryResult queryResult = new QueryResult(false) { NewIntent = queryIntent.Intent }; await context.PostAsync("진행중인 회의실 예약을 취소합니다."); context.Done <object>(message); } else { //회의실정보 있나 확인 if (meetingRoom.Hour == null) { // Entity에서 Hour값 가져온다. 있다면.. if (!AskHour(context, result)) { //시간정보가 없다 받아야 한다. await context.PostAsync("몇시부터 사용하실 건가요?"); context.Wait(this.MessageReceivedAsync); } } if (meetingRoom.Hour != null) { //먼저 가능한 회의실을 찾아서 알려준다. ReservationManagement management = new ReservationManagement(); List <string> roomNameList = management.GetAvailableReservation(meetingRoom.Hour); if (roomNameList.Count > 0) { string meetingRoomName; //사용자의 입력에 meetingRooom entity가 존재하는지만 체크 if (!GetUserInputMeetingRoomEntity(context, result, out meetingRoomName)) { //회의실정보를 입력하지 않았다...받아야 한다. var availableMeetingRoom = string.Join(", ", roomNameList.ToArray()); await context.PostAsync($"사용가능한 회의실은 {availableMeetingRoom} 입니다. 어떤 회의실을 예약할까요?"); context.Wait(this.MessageReceivedAsync); } else if (roomNameList.Contains(meetingRoomName)) { meetingRoom.MeetingRoomName = meetingRoomName; } } else { meetingRoom.Hour = null; await context.PostAsync("사용가능한 회의실이 없습니다. 다른 시간을 입력해주세요."); context.Wait(this.MessageReceivedAsync); } } //회의실정보 있나 확인 if (meetingRoom.Hour != null && meetingRoom.MeetingRoomName != null) { //회의실 예약 ReservationManagement management = new ReservationManagement(); management.SaveMeetingRoom(meetingRoom.Hour, meetingRoom.MeetingRoomName); await context.PostAsync($"{meetingRoom.MeetingRoomName} 회의실 {meetingRoom.Hour}에 예약 되었습니다."); context.Done <object>(meetingRoom); } } }