botbuilder-dotnet/libraries/Microsoft.Bot.Builder/RecognizerResult.cs

74 строки
2.8 KiB
C#

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Microsoft.Bot.Builder
{
/// <summary>
/// Contains recognition results generated by an <see cref="IRecognizer"/>.
/// </summary>
/// <seealso cref="IRecognizer.RecognizeAsync(ITurnContext, System.Threading.CancellationToken)"/>
public class RecognizerResult : IRecognizerConvert
{
/// <summary>
/// Gets or sets the input text to recognize.
/// </summary>
/// <value>
/// Original text to recognizer.
/// </value>
[JsonProperty("text")]
public string Text { get; set; }
/// <summary>
/// Gets or sets the input text as modified by the recognizer, for example for spelling correction.
/// </summary>
/// <value>
/// Text modified by recognizer.
/// </value>
[JsonProperty("alteredText")]
public string AlteredText { get; set; }
/// <summary>
/// Gets or sets the recognized intents, with the intent as key and the confidence as value.
/// </summary>
/// <value>
/// Mapping from intent to information about the intent.
/// </value>
[JsonProperty("intents")]
public IDictionary<string, IntentScore> Intents { get; set; } = new Dictionary<string, IntentScore>();
/// <summary>
/// Gets or sets the recognized top-level entities.
/// </summary>
/// <value>
/// Object with each top-level recognized entity as a key.
/// </value>
[JsonProperty("entities")]
public JObject Entities { get; set; } = new JObject();
/// <summary>
/// Gets or sets properties that are not otherwise defined by the <see cref="RecognizerResult"/> type but that
/// might appear in the REST JSON object.
/// </summary>
/// <value>The extended properties for the object.</value>
/// <remarks>With this, properties not represented in the defined type are not dropped when
/// the JSON object is deserialized, but are instead stored in this property. Such properties
/// will be written to a JSON object when the instance is serialized.</remarks>
[JsonExtensionData(ReadData = true, WriteData = true)]
public IDictionary<string, object> Properties { get; set; } = new Dictionary<string, object>();
/// <inheritdoc />
public void Convert(dynamic result)
{
Text = result.Text;
AlteredText = result.AlteredText;
Intents = result.Intents;
Entities = result.Entities;
Properties = result.Properties;
}
}
}