2018-09-29 04:21:44 +00:00
|
|
|
|
using Bigtree.Algorithm.Extensions;
|
2018-09-13 12:37:26 +00:00
|
|
|
|
using BotSharp.Core.Engines;
|
2018-10-03 14:13:32 +00:00
|
|
|
|
using BotSharp.Platform.Abstraction;
|
2018-10-03 06:00:07 +00:00
|
|
|
|
using BotSharp.Platform.Models;
|
2018-09-13 12:37:26 +00:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.Core.UnitTest.Performance
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestClass]
|
|
|
|
|
|
public class Spotify : TestEssential
|
|
|
|
|
|
{
|
2018-10-03 01:44:11 +00:00
|
|
|
|
//private List<Tuple<AIRequest, string>> Samples;
|
2018-10-03 14:13:32 +00:00
|
|
|
|
private IBotEngine _platform;
|
2018-09-13 12:37:26 +00:00
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void IntentAccuracy()
|
|
|
|
|
|
{
|
|
|
|
|
|
int correct = 0;
|
2018-09-13 20:01:40 +00:00
|
|
|
|
List<Tuple<string, string>> errors = new List<Tuple<string, string>>();
|
|
|
|
|
|
|
2018-10-27 15:37:59 +00:00
|
|
|
|
// var agent = LoadAgent();
|
2018-09-13 12:37:26 +00:00
|
|
|
|
|
2018-10-03 01:44:11 +00:00
|
|
|
|
/*for (int i = 0; i < Samples.Count; i++)
|
2018-09-13 12:37:26 +00:00
|
|
|
|
{
|
2018-09-13 20:01:40 +00:00
|
|
|
|
var aIResponse = _platform.TextRequest(Samples[i].Item1);
|
|
|
|
|
|
if (aIResponse.Result.Metadata.IntentName == Samples[i].Item2)
|
2018-09-13 12:37:26 +00:00
|
|
|
|
{
|
2018-09-13 20:01:40 +00:00
|
|
|
|
correct++;
|
2018-09-13 12:37:26 +00:00
|
|
|
|
}
|
2018-09-13 20:01:40 +00:00
|
|
|
|
else
|
2018-09-13 12:37:26 +00:00
|
|
|
|
{
|
2018-09-13 20:01:40 +00:00
|
|
|
|
errors.Add(new Tuple<string, string>(Samples[i].Item2, Samples[i].Item1.Query[0]));
|
2018-09-13 12:37:26 +00:00
|
|
|
|
}
|
2018-10-03 01:44:11 +00:00
|
|
|
|
}*/
|
2018-09-13 12:37:26 +00:00
|
|
|
|
|
2018-10-03 01:44:11 +00:00
|
|
|
|
//double accuracy = correct / (Samples.Count + 0.0);
|
2018-09-13 12:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-03 06:00:07 +00:00
|
|
|
|
private AgentBase LoadAgent()
|
2018-09-13 12:37:26 +00:00
|
|
|
|
{
|
2018-10-03 01:44:11 +00:00
|
|
|
|
//_platform = new BotSharpAi();
|
2018-09-13 12:37:26 +00:00
|
|
|
|
|
|
|
|
|
|
// Load agent
|
|
|
|
|
|
var projectPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", "Spotify");
|
|
|
|
|
|
string model = Directory.GetDirectories(projectPath).Where(x => x.Contains("model_")).Last().Split(Path.DirectorySeparatorChar).Last();
|
|
|
|
|
|
var modelPath = Path.Combine(projectPath, model);
|
2018-10-03 01:44:11 +00:00
|
|
|
|
/*var agent = _platform.LoadAgentFromFile(modelPath);
|
2018-09-13 12:37:26 +00:00
|
|
|
|
|
|
|
|
|
|
// Init samples
|
|
|
|
|
|
Samples = new List<Tuple<AIRequest, string>>();
|
|
|
|
|
|
agent.Corpus.UserSays.ForEach(intent =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Samples.Add(new Tuple<AIRequest, string>(new AIRequest
|
|
|
|
|
|
{
|
|
|
|
|
|
AgentDir = projectPath,
|
|
|
|
|
|
Model = model,
|
|
|
|
|
|
Query = new String[]
|
|
|
|
|
|
{
|
|
|
|
|
|
intent.Text
|
|
|
|
|
|
}
|
|
|
|
|
|
}, intent.Intent));
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2018-10-03 01:44:11 +00:00
|
|
|
|
Samples.Shuffle();*/
|
2018-09-13 12:37:26 +00:00
|
|
|
|
|
2018-10-03 01:44:11 +00:00
|
|
|
|
//var samples = String.Join("\r\n", Samples.Select(x => $"__label__{x.Item2} {x.Item1.Query[0]}").ToList());
|
2018-09-13 12:37:26 +00:00
|
|
|
|
|
2018-10-03 01:44:11 +00:00
|
|
|
|
return null;
|
2018-09-13 12:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|