This commit is contained in:
Hongyang Du (hond) 2019-12-04 10:37:19 +08:00 коммит произвёл GitHub
Родитель ca1bf61b4c
Коммит 0535ebbfef
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 28 добавлений и 42 удалений

Просмотреть файл

@ -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
@ -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
@ -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