83 строки
3.5 KiB
C#
83 строки
3.5 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")]
|
|
#pragma warning disable CA2227 // Collection properties should be read only (we can't change this without breaking binary compat)
|
|
public IDictionary<string, IntentScore> Intents { get; set; } = new Dictionary<string, IntentScore>();
|
|
#pragma warning restore CA2227 // Collection properties should be read only
|
|
|
|
/// <summary>
|
|
/// Gets or sets the recognized top-level entities.
|
|
/// </summary>
|
|
/// <value>
|
|
/// Object with each top-level recognized entity as a key.
|
|
/// </value>
|
|
[JsonProperty("entities")]
|
|
#pragma warning disable CA2227 // Collection properties should be read only (we can't change this without breaking binary compat)
|
|
public JObject Entities { get; set; } = new JObject();
|
|
#pragma warning restore CA2227 // Collection properties should be read only
|
|
|
|
/// <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)]
|
|
#pragma warning disable CA2227 // Collection properties should be read only (we can't change this without breaking binary compat)
|
|
public IDictionary<string, object> Properties { get; set; } = new Dictionary<string, object>();
|
|
#pragma warning restore CA2227 // Collection properties should be read only
|
|
|
|
/// <summary>
|
|
/// Convert recognizer result.
|
|
/// </summary>
|
|
/// <param name="result">Result to convert.</param>
|
|
public void Convert(dynamic result)
|
|
{
|
|
Text = result.Text;
|
|
AlteredText = result.AlteredText;
|
|
Intents = result.Intents;
|
|
Entities = result.Entities;
|
|
Properties = result.Properties;
|
|
}
|
|
}
|
|
}
|