static void Main(string[] args) { // authoring Key found in LUIS portal under user settings var cogServicesAllInOneKey = "<YOUR-AUTHORING-KEY>"; var credentials = new ApiKeyServiceClientCredentials(cogServicesAllInOneKey); // set parameters for app var resourceRegion = "westus"; var culture = "en-us"; var appName = "myEnglishApp"; var description = "app made with .Net SDK"; var versionId = "0.1"; // create client object var authoringClient = new LUISAuthoringClient(credentials, new System.Net.Http.DelegatingHandler[] { }); authoringClient.Endpoint = "https://westus.api.cognitive.microsoft.com/"; // create app var appId = CreateApp(authoringClient, resourceRegion, appName, versionId, culture, description); // create intent var intent = "FindForm"; var intentID = CreateIntent(authoringClient, resourceRegion, appId, versionId, intent); // create entity `HRF-number regular express var entityRegEx = "hrf-[0-9]{6}"; var entityName = "HRF-number"; var regularExpressEntity = new RegexModelCreateObject(entityRegEx, entityName); var entityId = CreateRegularExpressionEntity(authoringClient, resourceRegion, appId, versionId, regularExpressEntity); // add example utterance with 1 entity to intent var entity = "HRF-number"; var utterance = "When was hrf-123456 published?"; var taggedEntity = new EntityLabelObject(entity, 9, 18); var exampleUtteranceId = AddExampleUtterance(authoringClient, appId, versionId, intent, utterance, taggedEntity); }
static Guid CreateRegularExpressionEntity(LUISAuthoringClient client, string resourceRegion, Guid appId, string versionId, RegexModelCreateObject entity) { try { // create model for regular expression entity // custom headers is null var response = client.Model.CreateRegexEntityModelWithHttpMessagesAsync(appId, versionId, entity, null, CancellationToken.None).Result; // get entityId from `Location` header - trim away URL part var newEntityId = response.Response.Headers.Location.ToString(); newEntityId = newEntityId.Replace(String.Format("https://{0}.api.cognitive.microsoft.com/luis/api/v2.0/apps/{1}/versions/{2}/regexentities/", resourceRegion, appId, versionId), ""); return(new Guid(newEntityId)); } catch (Exception ex) { Console.WriteLine(ex.InnerException); throw ex; } }