Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit a4f9cef

Browse files
authored
Add name extraction for onboarding (#2120)
* add name extraction for onboarding * Add name extraction for onboarding * Rename some files * move onboarding model into general model * fix a problem * rename OnboardingState to AssistantState * make the changes in Template * fix some format * fix format * remove old file * update format
1 parent 7da3c47 commit a4f9cef

File tree

19 files changed

+274
-14
lines changed

19 files changed

+274
-14
lines changed

templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Deployment/Resources/LU/de/General.lu

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@
104104
- Sprechen Sie mit einem Menschen
105105

106106

107+
## ExtractName
108+
- rufen Sie mich steve !
109+
- ich bin anna
110+
- ich bin john jackson.
111+
- ich bin Lily
112+
- es ist jackson .
113+
- es ist alice anderson!
114+
- mein Name ist bill jones
115+
- dies ist john w.smith .
116+
- ([Sie können]| [bitte]) Ruf mich an {PersonName.Any} [.]
117+
- mein Name ist {PersonName.Any} [.]
118+
- (i'm|i am) {PersonName.Any} [.]
119+
- (es ist|es ist|dies ist) {PersonName.Any} [.]
120+
121+
107122
## FinishTask
108123
- Alles fertig
109124
- Alles gesetzt
@@ -514,6 +529,7 @@ $PREBUILT:number
514529

515530
$PREBUILT:ordinal
516531

532+
$PREBUILT:personName
517533

518534
> # Phrase list definitions
519535

templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Deployment/Resources/LU/en/General.lu

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@
104104
- talk to a human
105105

106106

107+
## ExtractName
108+
- call me steve !
109+
- i am anna
110+
- i'm john jackson.
111+
- i'm lily
112+
- it is jackson .
113+
- it's alice anderson!
114+
- my name is bill jones
115+
- this is john w.smith .
116+
- ([you can]|[please]) call me {PersonName.Any}[.]
117+
- my name is {PersonName.Any}[.]
118+
- (i'm|i am) {PersonName.Any}[.]
119+
- (it's|it is|this is) {PersonName.Any}[.]
120+
121+
107122
## FinishTask
108123
- all finished
109124
- all set
@@ -516,6 +531,8 @@ $PREBUILT:number
516531

517532
$PREBUILT:ordinal
518533

534+
$PREBUILT:personName
535+
519536

520537
> # Phrase list definitions
521538

templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Deployment/Resources/LU/es/General.lu

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@
104104
- hablar con un humano
105105

106106

107+
## ExtractName
108+
- llámame steve !
109+
- Soy anna
110+
- Soy John Jackson.
111+
- Soy lirio
112+
- es Jackson .
113+
- es Alice Anderson!
114+
- mi nombre es Bill Jones
115+
- este es John w.smith .
116+
- ([se puede] [por favor]) Llámame {PersonName.Any} [.]
117+
- Mi nombre es {PersonName.Any} [.]
118+
- (Soy yo) {PersonName.Any} [.]
119+
- (es esto) {PersonName.Any} [.]
120+
121+
107122
## FinishTask
108123
- todo terminado
109124
- Todo listo
@@ -514,6 +529,8 @@ $PREBUILT:number
514529

515530
$PREBUILT:ordinal
516531

532+
$PREBUILT:personName
533+
517534

518535
> # Phrase list definitions
519536

templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Deployment/Resources/LU/fr/General.lu

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@
104104
- parler à un humain
105105

106106

107+
## ExtractName
108+
- appelez-moi steve !
109+
- je suis anna
110+
- Je suis John Jackson.
111+
- Je suis lys
112+
- c'est jackson .
113+
- c'est Alice anderson!
114+
- mon nom est bill jones
115+
- c'est john w.smith .
116+
- ([vous pouvez] [s'il vous plaît]) Appelle-moi {PersonName.Any} [.]
117+
- mon nom est {PersonName.Any} [.]
118+
- (je suis) {PersonName.Any} [.]
119+
- (c'est c'est ça) {PersonName.Any} [.]
120+
121+
107122
## FinishTask
108123
- tous finis
109124
- tous ensemble
@@ -514,6 +529,7 @@ $PREBUILT:number
514529

515530
$PREBUILT:ordinal
516531

532+
$PREBUILT:personName
517533

518534
> # Phrase list definitions
519535

templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Deployment/Resources/LU/it/General.lu

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@
104104
- parlare con un umano
105105

106106

107+
## ExtractName
108+
- chiamami steve !
109+
- Io sono anna
110+
- Sono John Jackson.
111+
- Sono giglio
112+
- è jackson .
113+
- è Alice Anderson!
114+
- il mio nome è Bill Jones
115+
- questo è john w.smith .
116+
- ([si può] [per favore]) Chiamami {PersonName.Any} [.]
117+
- mi chiamo {PersonName.Any} [.]
118+
- (Io sono) {PersonName.Any} [.]
119+
- (è, è, questo è) {PersonName.Any} [.]
120+
121+
107122
## FinishTask
108123
- Tutto finito
109124
- tutti insieme
@@ -514,6 +529,7 @@ $PREBUILT:number
514529

515530
$PREBUILT:ordinal
516531

532+
$PREBUILT:personName
517533

518534
> # Phrase list definitions
519535

templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Deployment/Resources/LU/zh/General.lu

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@
8787
- 是的
8888

8989

90+
## ExtractName
91+
- 叫我史蒂夫!
92+
- 我是安娜
93+
- 我是约翰·杰克逊!
94+
- 我是莉莉
95+
- 请叫我杰克逊。
96+
- 可以叫我爱丽丝·安德森!
97+
- 我的名字是比尔·琼斯
98+
- 我是约翰·史密斯。
99+
- [你]([可以][请])叫我{PersonName.Any} [吧][.]
100+
- 我的名字是{PersonName.Any} [.]
101+
- 我是{PersonName.Any} [.]
102+
103+
90104
## Escalate
91105
- 我能和一个人交谈吗?
92106
- 联系支持
@@ -514,6 +528,7 @@ $PREBUILT:number
514528

515529
$PREBUILT:ordinal
516530

531+
$PREBUILT:personName
517532

518533
> # Phrase list definitions
519534

templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Dialogs/MainDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

44
using System;

templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Dialogs/OnboardingDialog.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

44
using System;
55
using System.Globalization;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Luis;
89
using Microsoft.Bot.Builder;
910
using Microsoft.Bot.Builder.Dialogs;
1011
using Microsoft.Bot.Builder.Solutions.Extensions;
1112
using Microsoft.Bot.Builder.Solutions.Responses;
1213
using Microsoft.Extensions.DependencyInjection;
1314
using VirtualAssistantSample.Models;
15+
using VirtualAssistantSample.Services;
1416

1517
namespace VirtualAssistantSample.Dialogs
1618
{
1719
// Example onboarding dialog to initial user profile information.
1820
public class OnboardingDialog : ComponentDialog
1921
{
22+
private BotServices _services;
2023
private LocaleTemplateEngineManager _templateEngine;
2124
private IStatePropertyAccessor<UserProfileState> _accessor;
2225

@@ -29,6 +32,7 @@ public OnboardingDialog(
2932

3033
var userState = serviceProvider.GetService<UserState>();
3134
_accessor = userState.CreateProperty<UserProfileState>(nameof(UserProfileState));
35+
_services = serviceProvider.GetService<BotServices>();
3236

3337
var onboarding = new WaterfallStep[]
3438
{
@@ -64,6 +68,27 @@ public async Task<DialogTurnResult> FinishOnboardingDialog(WaterfallStepContext
6468
{
6569
var userProfile = await _accessor.GetAsync(sc.Context, () => new UserProfileState());
6670
var name = (string)sc.Result;
71+
72+
var generalResult = sc.Context.TurnState.Get<GeneralLuis>(StateProperties.GeneralResult);
73+
if (generalResult == null)
74+
{
75+
var locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
76+
var localizedServices = _services.CognitiveModelSets[locale];
77+
generalResult = await localizedServices.LuisServices["General"].RecognizeAsync<GeneralLuis>(sc.Context, cancellationToken);
78+
}
79+
80+
(var generalIntent, var generalScore) = generalResult.TopIntent();
81+
if (generalIntent == GeneralLuis.Intent.ExtractName && generalScore > 0.5)
82+
{
83+
if (generalResult.Entities.PersonName_Any != null)
84+
{
85+
name = generalResult.Entities.PersonName_Any[0];
86+
}
87+
else if (generalResult.Entities.personName != null)
88+
{
89+
name = generalResult.Entities.personName[0];
90+
}
91+
}
6792

6893
// Captialize name
6994
userProfile.Name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(name.ToLower());
@@ -82,5 +107,10 @@ private class DialogIds
82107
{
83108
public const string NamePrompt = "namePrompt";
84109
}
110+
111+
private class StateProperties
112+
{
113+
public const string GeneralResult = "generalResult";
114+
}
85115
}
86116
}

templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Services/GeneralLuis.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public enum Intent
1919
Cancel,
2020
Confirm,
2121
Escalate,
22+
ExtractName,
2223
FinishTask,
2324
GoBack,
2425
Help,
@@ -45,13 +46,19 @@ public class _Entities
4546
// Built-in entities
4647
public double[] number;
4748
public double[] ordinal;
49+
public string[] personName;
50+
51+
// Pattern.any
52+
public string[] PersonName_Any;
4853

4954
// Instance
5055
public class _Instance
5156
{
5257
public InstanceData[] DirectionalReference;
5358
public InstanceData[] number;
5459
public InstanceData[] ordinal;
60+
public InstanceData[] personName;
61+
public InstanceData[] PersonName_Any;
5562
}
5663
[JsonProperty("$instance")]
5764
public _Instance _instance;

templates/Virtual-Assistant-Template/csharp/Template/VA/Deployment/Resources/LU/de/general.lu

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@
104104
- Sprechen Sie mit einem Menschen
105105

106106

107+
## ExtractName
108+
- rufen Sie mich steve !
109+
- ich bin anna
110+
- ich bin john jackson.
111+
- ich bin Lily
112+
- es ist jackson .
113+
- es ist alice anderson!
114+
- mein Name ist bill jones
115+
- dies ist john w.smith .
116+
- ([Sie können]| [bitte]) Ruf mich an {PersonName.Any} [.]
117+
- mein Name ist {PersonName.Any} [.]
118+
- (i'm|i am) {PersonName.Any} [.]
119+
- (es ist|es ist|dies ist) {PersonName.Any} [.]
120+
121+
107122
## FinishTask
108123
- Alles fertig
109124
- Alles gesetzt
@@ -514,6 +529,7 @@ $PREBUILT:number
514529

515530
$PREBUILT:ordinal
516531

532+
$PREBUILT:personName
517533

518534
> # Phrase list definitions
519535

0 commit comments

Comments
 (0)