Skip to content

Commit

Permalink
[LG/Expression] merge master (#1466)
Browse files Browse the repository at this point in the history
* add Activityfactory (#1401)

* add activityfactory

* retrigger CI

* fix comments

* remove unused code

* modify text

* add some comments

* fix param type

* fix template additional newline bug (#1419)

* fix conflict

* Update README.MD (#1463)

* merge master

* revert lock file
  • Loading branch information
Danieladu committed Dec 4, 2019
1 parent 32d8059 commit 95aeb56
Show file tree
Hide file tree
Showing 129 changed files with 4,449 additions and 2,447 deletions.
1 change: 1 addition & 0 deletions libraries/botbuilder-dialogs-adaptive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@types/node-fetch": "^2.5.3",
"botbuilder-core": "~4.1.6",
"botbuilder-dialogs": "~4.1.6",
"botbuilder-lg": "~4.1.6",
"botframework-expressions": "~4.1.6",
"botframework-connector": "~4.1.6",
"botframework-schema": "~4.1.6",
Expand Down
8 changes: 8 additions & 0 deletions libraries/botbuilder-dialogs-adaptive/src/stringTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ export function compile(template: string): (dc: DialogContext) => string {
buffer = '';
}
inSlot = true;
} else if (chr === '@' && i < template.length - 1 && template[i+1] === '{') {
// support @{}
if (buffer.length > 0) {
chunks.push(textLiteral(buffer));
buffer = '';
}
i++;
inSlot = true;
} else {
buffer += chr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "Hello {user.name}, nice to talk to you!"
"activity": "Hello @{user.name}, nice to talk to you!"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "Hello, your age is {user.age}!"
"activity": "Hello, your age is @{user.age}!"
},
{
"$type": "Microsoft.FloatInput",
Expand All @@ -25,13 +25,13 @@
"actions": [
{
"$type": "Microsoft.SendActivity",
"activity": "2 * 2.2 equals {user.result}, that's right!"
"activity": "2 * 2.2 equals @{user.result}, that's right!"
}
],
"elseActions": [
{
"$type": "Microsoft.SendActivity",
"activity": "2 * 2.2 equals {user.result}, that's wrong!"
"activity": "2 * 2.2 equals @{user.result}, that's wrong!"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "Hello {user.name}, nice to talk to you!"
"activity": "Hello @{user.name}, nice to talk to you!"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "Hello {user.name}, nice to talk to you!"
"activity": "Hello @{user.name}, nice to talk to you!"
}
],
"rules": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "Hello {user.name}, nice to talk to you!"
"activity": "Hello @{user.name}, nice to talk to you!"
}
],
"rules": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "Hello {user.name}, nice to talk to you!"
"activity": "Hello @{user.name}, nice to talk to you!"
}
],
"rules": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
"$type": "Microsoft.TextInput",
"pattern": "\\w{3,50}",
"property": "user.name",
"prompt": "[Greeting.Name.initialPrompt]",
"retryPrompt": "[Greeting.Name.retryPrompt]",
"invalidPrompt": "[Greeting.Name.notMatched]"
"prompt": "@{Greeting.Name.initialPrompt()}",
"retryPrompt": "@{Greeting.Name.retryPrompt()}",
"invalidPrompt": "@{Greeting.Name.notMatched()}"
}
]
},
{
"$type": "Microsoft.SendActivity",
"activity": "[Greeting.GreetUser]"
"activity": "@{Greeting.GreetUser()}"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"actions": [
{
"$type": "Microsoft.SendActivity",
"activity": "[welcome]"
"activity": "@{welcome}"
},
"ExternalLanguage.Greeting"
],
Expand Down Expand Up @@ -46,7 +46,7 @@
"actions": [
{
"$type": "Microsoft.SendActivity",
"activity": "[help]"
"activity": "@{help()}"
}
]
},
Expand All @@ -55,7 +55,7 @@
"actions": [
{
"$type": "Microsoft.SendActivity",
"activity": "[help]"
"activity": "@{help()}"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
```

# welcome-user
- Hello {user.name}, nice talking to you!
- Howdy {user.name}!
- Hello @{user.name}, nice talking to you!
- Howdy @{user.name}!

# prompt-name
- What's your name?
Expand All @@ -22,14 +22,14 @@
- I would like to know you better, what's your name?

# Greeting.Name.retryPrompt
- [Greeting.Name.initialPrompt]
- @{Greeting.Name.initialPrompt()}

# Greeting.Name.notMatched
- That didn't match what I'm looking for, your name needs to be between 3 and 50 characters.
- Oh no, I'm silly and confused again.

# Greeting.GreetUser
- Hello {user.name}, nice to talk to you!
- Hi {user.name}, you seem nice!
- Whassup {user.name}?
- Hello @{user.name}, nice to talk to you!
- Hi @{user.name}, you seem nice!
- Whassup @{user.name}?

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "Hello {user.name}, nice to talk to you!"
"activity": "Hello @{user.name}, nice to talk to you!"
},
{
"$type": "Microsoft.SendActivity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "You select: {user.style.Value}"
"activity": "You select: @{user.style.Value}"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "Great! Your pet's name is {dialog.petname}"
"activity": "Great! Your pet's name is @{dialog.petname}"
},
{
"$type": "Microsoft.TextInput",
Expand All @@ -27,12 +27,12 @@
},
"body": {

"id": "{dialog.petid}",
"id": "@{dialog.petid}",
"category": {
"id": 0,
"name": "string"
},
"name": "{dialog.petname}",
"name": "@{dialog.petname}",
"photoUrls": [ "string" ],
"tags": [
{
Expand All @@ -46,7 +46,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "Done! You have added a pet named \"{dialog.postResponse.name}\" with id \"{dialog.postResponse.id}\""
"activity": "Done! You have added a pet named \"@{dialog.postResponse.name}\" with id \"@{dialog.postResponse.id}\""
},
{
"$type": "Microsoft.TextInput",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "[Show]"
"activity": "@{Show()}"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "Your age is: {user.age}"
"activity": "Your age is: @{user.age}"
},
{
"$type": "Testbot.JavascriptAction",
Expand All @@ -19,7 +19,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "Your age in dog years is: {user.dogyears}"
"activity": "Your age in dog years is: @{user.dogyears}"
},
{
"$type": "Testbot.CSharpAction",
Expand All @@ -28,7 +28,7 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "Your age in cat years is: {user.catyears}"
"activity": "Your age in cat years is: @{user.catyears}"
},
{
"$type": "Testbot.CalculateDogYears",
Expand All @@ -37,11 +37,11 @@
},
{
"$type": "Microsoft.SendActivity",
"activity": "A dog that is {conversation.dog} years old is the same age as you"
"activity": "A dog that is @{conversation.dog} years old is the same age as you"
},
{
"$type": "Microsoft.SendActivity",
"activity": "A cat that is {conversation.cat} years old is the same age as you"
"activity": "A cat that is @{conversation.cat} years old is the same age as you"
},
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"$type":"Microsoft.SendActivity",
"activity": "Hello {user.name}, nice to meet you!"
"activity": "Hello @{user.name}, nice to meet you!"
},
{
"$type":"Microsoft.EndTurn"
Expand Down
70 changes: 28 additions & 42 deletions libraries/botbuilder-lg/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,26 @@ You can use language generation to:
- achieve a coherent personality, tone of voice for your bot
- separate business logic from presentation
- include variations and sophisticated composition based resolution for any of your bot's replies
- construct speak .vs. display adaptations
- construct cards, suggested actions and attachments.
- structured LG

## Speak .vs. display adaptation

By design, the .lg file format does not explicitly support the ability to provide speak .vs. display adaptation. The file format supports simple constructs that are composable and supports resolution on multi-line text and so you can have syntax and semantics for speak .vs. display adaptation, cards, suggested actions etc that can be interpreted as simple text and transformed into the Bot Framework [activity][1] by a layer above language generation.
## structured LG
The type of LG output could be string or object, string is by default. But LG could generate a json object by Structured LG feature.

Bot Builder SDK supports a short hand notation that can parse and transform a piece of text separated by `displayText`||`spokenText` into speak and display text.

```markdown
# greetingTemplate
- hi || hi there
- hello || hello, what can I help with today
```

You can use the `TextMessageActivityGenerator.CreateActityFromText` method to transform the command into a Bot Framework activity to post back to the user.

## Using Chatdown style cards

[Chatdown][6] introduced a simple markdown based way to write mock conversations. Also introduced as part of the [.chat][7] file format was the ability to express different [message commands][9] via simple text representation. Message commands include [cards][10], [Attachments][11] and suggested actions.

You can include message commands via multi-line text in the .lg file format and use the `TextMessageActivityGenerator.CreateActityFromText` method to transform the command into a Bot Framework activity to post back to the user.

See [here][8] for examples of how different card types are represented in .chat file format.

Here is an example of a card definition.
Example here:

```markdown
# HeroCardTemplate(buttonsCollection)
- ```
[Herocard
title=@{TitleText())}
subtitle=@{SubText())}
text=@{DescriptionText())}
images=@{CardImages())}
buttons=@{join(buttonsCollection, '|')]
```
buttons=@{buttonsCollection}
]

# TitleText
- Here are some [TitleSuffix]
- Here are some @{TitleSuffix()}

# TitleSuffix
- cool photos
Expand All @@ -82,6 +62,25 @@ Here is an example of a card definition.
- https://picsum.photos/200/200?image=400
```

the result could be:
```json
{
"lgType": "Herocard",
"title": "Here are some pictures",
"text": "This is description for the hero card",
"images": "https://picsum.photos/200/200?image=100",
"buttons": [
"click to see",
"back"
]
}
```
the structured name would be placed into property 'lgType'.
See more tests here : [structured LG test][4]

By this, You can use the `ActivityFactory.createActivity(lgResult)` method to transform the lg output into a Bot Framework activity to post back to the user.

see more samples here: [Structured LG to Activity][5]

## Language Generation in action

Expand Down Expand Up @@ -114,22 +113,9 @@ If your template needs specific entity values to be passed for resolution/ expan
await turnContext.sendActivity(lgEngine.evaluateTemplate("WordGameReply", { GameName = "MarcoPolo" } ));
```
## Multi-lingual generation and language fallback policy
Quite often your bot might target more than one spoken/ display language. To help with resource management as well as implement a default language fall back policy, you can either use `MultiLanguageGenerator` or `ResourceMultiLanguageGenerator`. See [here][25] for an example.
## Grammar check and correction
The current library does not include any capabilities for grammar check or correction.
[1]:https://github.com/Microsoft/BotBuilder/blob/master/specs/botframework-activity/botframework-activity.md
[2]:https://github.com/microsoft/BotBuilder-Samples/blob/master/experimental/language-generation/docs/api-reference.md
[3]:https://github.com/microsoft/BotBuilder-Samples/blob/master/experimental/language-generation/docs/lg-file-format.md
[6]:https://github.com/Microsoft/botbuilder-tools/tree/master/packages/Chatdown
[7]:https://github.com/Microsoft/botbuilder-tools/tree/master/packages/Chatdown#chat-file-format
[8]:https://github.com/Microsoft/botbuilder-tools/blob/master/packages/Chatdown/Examples/CardExamples.chat
[9]:https://github.com/Microsoft/botbuilder-tools/tree/master/packages/Chatdown#message-commands
[10]:https://github.com/Microsoft/botbuilder-tools/tree/master/packages/Chatdown#message-cards
[11]:https://github.com/Microsoft/botbuilder-tools/tree/master/packages/Chatdown#message-attachments
[25]:https://github.com/microsoft/botbuilder-dotnet/blob/d953d1b7fe548cdb1800f1c2e85fe35c34edf75c/tests/Microsoft.Bot.Builder.LanguageGeneration.Renderer.Tests/LGGeneratorTests.cs#L78
[4]:https://github.com/microsoft/botbuilder-js/blob/master/libraries/botbuilder-lg/tests/testData/examples/StructuredTemplate.lg
[5]:https://github.com/microsoft/botbuilder-js/blob/master/libraries/botbuilder-lg/tests/testData/examples/NormalStructuredLG.lg
Loading

0 comments on commit 95aeb56

Please sign in to comment.