Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LuisNLUTrainClient"/> class.
 /// </summary>
 /// <param name="luisConfiguration">LUIS configuration.</param>
 /// <param name="luisSettings">LUIS settings.</param>
 /// <param name="luisClient">LUIS client.</param>
 public LuisNLUTrainClient(ILuisConfiguration luisConfiguration, LuisSettings luisSettings, ILuisTrainClient luisClient)
 {
     this.LuisConfiguration = luisConfiguration ?? throw new ArgumentNullException(nameof(luisConfiguration));
     this.LuisSettings      = luisSettings ?? throw new ArgumentNullException(nameof(luisSettings));
     this.LuisClient        = luisClient ?? throw new ArgumentNullException(nameof(luisClient));
     this.LuisAppId         = luisConfiguration.AppId;
 }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LuisNLUService"/> class.
        /// </summary>
        /// <param name="appName">App name.</param>
        /// <param name="appId">App ID.</param>
        /// <param name="versionId">Version ID.</param>
        /// <param name="luisSettings">LUIS settings.</param>
        /// <param name="luisClient">LUIS client.</param>
        public LuisNLUService(string appName, string appId, string versionId, LuisSettings luisSettings, ILuisClient luisClient)
        {
            this.LuisAppId     = appId;
            this.LuisVersionId = versionId ?? "0.1.1";
            this.LuisSettings  = luisSettings ?? throw new ArgumentNullException(nameof(luisSettings));
            this.LuisClient    = luisClient ?? throw new ArgumentNullException(nameof(luisClient));

            this.AppName = appName ?? ((appId == null && luisSettings.AppTemplate.Name == null)
                ? throw new ArgumentNullException(nameof(appName), $"Must supply one of '{nameof(appName)}', '{nameof(appId)}', or '{nameof(Luis.LuisSettings)}.{nameof(Luis.LuisSettings.AppTemplate)}'.")
                : appName);
        }
Exemple #3
0
        /// <inheritdoc/>
        public INLUTestClient CreateTestInstance(IConfiguration configuration, string settingsPath)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var luisSettings = settingsPath != null
                ? LuisSettings.FromJson(JObject.Parse(File.ReadAllText(settingsPath)))
                : new LuisSettings();

            var luisConfiguration = new TestLuisConfiguration(configuration);
            var luisClient        = new LuisTestClient(luisConfiguration);

            return(new LuisNLUTestClient(luisSettings, luisClient));
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LuisNLUTestClient"/> class.
 /// </summary>
 /// <param name="luisSettings">LUIS settings.</param>
 /// <param name="luisClient">LUIS test client.</param>
 public LuisNLUTestClient(LuisSettings luisSettings, ILuisTestClient luisClient)
 {
     this.LuisSettings = luisSettings ?? throw new ArgumentNullException(nameof(luisSettings));
     this.LuisClient   = luisClient ?? throw new ArgumentNullException(nameof(luisClient));
 }
        public static JSONUtterance ToJSONUtterance(this Models.LabeledUtterance utterance, LuisSettings luisSettings)
        {
            JSONEntity toJSONEntity(Entity entity)
            {
                var startPos = entity.StartCharIndexInText(utterance.Text);
                var endPos   = startPos + entity.MatchText.Length - 1;

                if (luisSettings.Roles.TryGetValue(entity.EntityType, out var entityType))
                {
                    return(new JSONEntityWithRole(startPos, endPos, entityType, entity.EntityType));
                }

                entityType = luisSettings.PrebuiltEntityTypes.TryGetValue(entity.EntityType, out var builtinType)
                    ? builtinType
                    : entity.EntityType;
                return(new JSONEntity(startPos, endPos, entityType));
            }

            return(new JSONUtterance(
                       utterance.Text,
                       utterance.Intent,
                       utterance.Entities?.Select(toJSONEntity).ToArray() ?? Array.Empty <JSONEntity>()));
        }