Skip to content

Commit

Permalink
Added Training Status Enum, AddBatchExamples, BatchExample Model, fla…
Browse files Browse the repository at this point in the history
…g for Delete Intent Utterances, TrainAndGetCompletedStatus. Updated Publish Model
  • Loading branch information
Prema Arya committed May 3, 2018
1 parent 2a22790 commit 106f172
Show file tree
Hide file tree
Showing 19 changed files with 1,147 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<None Remove="ExampleTests.cs.orig" />
<None Remove="IntentTests.cs.orig" />
<None Remove="PublishTests.cs.orig" />
<None Remove="TrainingTests.cs.orig" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
Expand Down
108 changes: 108 additions & 0 deletions Cognitive.LUIS.Programmatic.Tests/ExampleTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Cognitive.LUIS.Programmatic.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Cognitive.LUIS.Programmatic.Tests
Expand Down Expand Up @@ -43,6 +44,113 @@ public async Task ShouldAddExample()

Assert.IsNotNull(utterance);
}
[TestMethod]
public async Task ShouldAddLabelledExample()
{
var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);

// Add simple entity name if not already exists
if (await client.GetEntityByNameAsync("name", _appId, "1.0") == null)
await client.AddEntityAsync("name", _appId, "1.0");

if (await client.GetIntentByNameAsync("IntentTest", _appId, "1.0") == null)
await client.AddIntentAsync("IntentTest", _appId, "1.0");

var labeledExample = new Example()
{
Text = "Who is Test User!",
IntentName = "IntentTest",
EntityLabels = new List<EntityLabel>
{
new EntityLabel
{
EntityName = "name",
StartCharIndex = 7,
EndCharIndex = 15
}
}
};

var utterance = await client.AddExampleAsync(_appId, "1.0", labeledExample);

Assert.IsNotNull(utterance);
}

[TestMethod]
public async Task ShoulAddBatchExample()
{
var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);

if (await client.GetIntentByNameAsync("IntentTest", _appId, "1.0") == null)
await client.AddIntentAsync("IntentTest", _appId, "1.0");

List<Example> examples = new List<Example>();
examples.Add(new Example
{
Text = "Hello World!",
IntentName = "IntentTest"
});

examples.Add(new Example
{
Text = "This is a test Utterance",
IntentName = "IntentTest"
});

var addExamples = await client.AddBatchExampleAsync(_appId, "1.0", examples.ToArray());

Assert.AreEqual<int>(2, addExamples.Length);
}


[TestMethod]
public async Task ShoulAddBatchLbeledExample()
{
var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);
// Add simple entity name if not already exists
if (await client.GetEntityByNameAsync("name", _appId, "1.0") == null)
await client.AddEntityAsync("name", _appId, "1.0");

// Add simple intent name if not already exists
if (await client.GetIntentByNameAsync("IntentTest", _appId, "1.0") == null)
await client.AddIntentAsync("IntentTest", _appId, "1.0");

List<Example> examples = new List<Example>();
examples.Add(new Example()
{
Text = "Who is Bill?",
IntentName = "IntentTest",
EntityLabels = new List<EntityLabel>
{
new EntityLabel
{
EntityName = "name",
StartCharIndex = 7,
EndCharIndex = 10
}
}
});

examples.Add(new Example()
{
Text = "Who is Christopher?",
IntentName = "IntentTest",
EntityLabels = new List<EntityLabel>
{
new EntityLabel
{
EntityName = "name",
StartCharIndex = 7,
EndCharIndex = 17
}
}
});

var addExamples = await client.AddBatchExampleAsync(_appId, "1.0", examples.ToArray());

Assert.AreEqual<bool>(false, addExamples[0].hasError);
Assert.AreEqual<bool>(false, addExamples[1].hasError);
}

[TestMethod]
public async Task ShouldThrowExceptionOnAddExampleWhenIntentTestNotExists()
Expand Down
67 changes: 67 additions & 0 deletions Cognitive.LUIS.Programmatic.Tests/ExampleTests.cs.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Cognitive.LUIS.Programmatic.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading.Tasks;

namespace Cognitive.LUIS.Programmatic.Tests
{
[TestClass]
public class ExampleTests
{
private const string SUBSCRIPTION_KEY = "{YourSubscriptionKey}";
private const Location LOCATION = Location.WestUS;
private readonly string _appId;

public ExampleTests()
{
var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);
var app = client.GetAppByNameAsync("SDKTest").Result;
if (app != null)
_appId = app.Id;
else
_appId = client.AddAppAsync("SDKTest", "Description test", "en-us", "SDKTest", string.Empty, "1.0").Result;
}

[TestMethod]
public async Task ShouldAddExample()
{
var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);
string intentTestId = null;
var intentTest = await client.GetIntentByNameAsync("IntentTest", _appId, "1.0");
if (intentTest != null)
intentTestId = intentTest.Id;
else
intentTestId = await client.AddIntentAsync("IntentTest", _appId, "1.0");

var example = new Example
{
Text = "Hello World!",
IntentName = "IntentTest"
};

var utterance = await client.AddExampleAsync(_appId, "1.0", example);

Assert.IsNotNull(utterance);
}

[TestMethod]
public async Task ShouldThrowExceptionOnAddExampleWhenIntentTestNotExists()
{
var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);
var intentTest = await client.GetIntentByNameAsync("IntentTest", _appId, "1.0");
if (intentTest != null)
await client.DeleteIntentAsync(intentTest.Id, _appId, "1.0");

var example = new Example
{
Text = "Hello World!",
IntentName = "IntentTest"
};

var ex = await Assert.ThrowsExceptionAsync<Exception>(() =>
client.AddExampleAsync(_appId, "1.0", example));

Assert.AreEqual(ex.Message, "The intent classifier IntentTest does not exist in the selected application");
}
}
}
27 changes: 27 additions & 0 deletions Cognitive.LUIS.Programmatic.Tests/IntentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,33 @@ public async Task ShouldDeleteIntentTest()
Assert.IsNull(intent);
}

[TestMethod]
public async Task ShouldDeleteIntentAndUtterancesTest()
{
var client = new LuisProgClient(SUBSCRIPTION_KEY, LOCATION);
if (await client.GetIntentByNameAsync("IntentTest", _appId, "1.0") == null)
await client.AddIntentAsync("IntentTest", _appId, "1.0");

// Add example for the intent
var exampleAdded = await client.AddExampleAsync(_appId, "1.0", new Example()
{
IntentName = "IntentTest",
Text = "This is sample utterance"
});

if (!string.IsNullOrEmpty(exampleAdded?.UtteranceText))
{

var intent = await client.GetIntentByNameAsync("IntentTest", _appId, "1.0");
await client.DeleteIntentAsync(intent.Id, _appId, "1.0", true);

// TODO : once the get exampleById available, get the exmaple and assert for null
intent = await client.GetIntentByIdAsync(intent.Id, _appId, "1.0");

Assert.IsNull(intent);
}
}

[TestMethod]
public async Task ShouldThrowExceptionOnDeleteIntentTestWhenNotExists()
{
Expand Down
Loading

0 comments on commit 106f172

Please sign in to comment.