Skip to content

Commit d6d26c6

Browse files
authored
Merge pull request #3 from Oceania2018/master
merge newest code
2 parents cc8ad7a + 4d5698a commit d6d26c6

File tree

70 files changed

+809
-490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+809
-490
lines changed

.gitignore

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,21 +286,9 @@ __pycache__/
286286
*.btm.cs
287287
*.odx.cs
288288
*.xsd.cs
289-
/App_Data
290-
/Bot.WebStarter/App_Data/bot-rasa.db
291-
/Bot.WebStarter/App_Data/DbInitializer/Agents/Dialogflow/VirtualAssistant
292-
/BotSharp.WebStarter/App_Data/DbInitializer/Agents/Dialogflow/VirtualAssistant
293-
/BotSharp.UnitTest/App_Data/DbInitializer/Agents
294-
/BotSharp.UnitTest/App_Data/BotSharp.db
295289
/BotSharp.WebHost/App_Data/BotSharp.db
296290
/BotSharp.UI
297-
/BotSharp.WebHost/App_Data/ModelFiles
298-
/BotSharp.WebHost/App_Data/TrainingFiles
299-
/BotSharp.WebHost/App_Data/PredictFiles
300291
/BotSharp.WebHost/App_Data/Projects
301292
/BotSharp.WebHost/PublishOutput
302293
/Data
303-
/docs/build
304294
/docs/_build
305-
/BotSharp.WebHost/App_Data/AgentArchive/Smart Niraj.zip
306-
/BotSharp.NLP.UnitTest/wordvec_enu.bin

BotSharp.Algorithm/Bayes/MultinomiaNaiveBayes.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,16 @@ public double CalPosteriorProb(string Y, double[] features, double priorProb, Di
8888
{
8989
int featureCount = features.Length;
9090

91-
double postProb = priorProb;
91+
double postProb = Math.Log(priorProb);
9292

9393
// loop features
9494
for (int x = 0; x < featureCount; x++)
9595
{
9696
string key = $"{Y} f{x} {features[x]}";
97-
postProb += condProbDictionary[key];
97+
if(features[x] == 1)
98+
{
99+
postProb += condProbDictionary[key];
100+
}
98101
}
99102

100103
return Math.Pow(2, postProb);

BotSharp.Core.UnitTest/BotSharp.Core.UnitTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22+
<ProjectReference Include="..\BotSharp.Algorithm\BotSharp.Algorithm.csproj" />
2223
<ProjectReference Include="..\BotSharp.Core\BotSharp.Core.csproj" />
2324
</ItemGroup>
2425

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using BotSharp.Core.Agents;
2+
using BotSharp.Core.Engines;
3+
using BotSharp.Core.Engines.BotSharp;
4+
using BotSharp.Core.Models;
5+
using Microsoft.VisualStudio.TestTools.UnitTesting;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Linq;
10+
using System.Text;
11+
using BotSharp.Algorithm.Extensions;
12+
13+
namespace BotSharp.Core.UnitTest.Performance
14+
{
15+
[TestClass]
16+
public class Spotify : TestEssential
17+
{
18+
private List<Tuple<AIRequest, string>> Samples;
19+
private IBotPlatform _platform;
20+
21+
[TestMethod]
22+
public void IntentAccuracy()
23+
{
24+
int correct = 0;
25+
List<Tuple<string, string>> errors = new List<Tuple<string, string>>();
26+
27+
var agent = LoadAgent();
28+
29+
for (int i = 0; i < Samples.Count; i++)
30+
{
31+
var aIResponse = _platform.TextRequest(Samples[i].Item1);
32+
if (aIResponse.Result.Metadata.IntentName == Samples[i].Item2)
33+
{
34+
correct++;
35+
}
36+
else
37+
{
38+
errors.Add(new Tuple<string, string>(Samples[i].Item2, Samples[i].Item1.Query[0]));
39+
}
40+
}
41+
42+
double accuracy = correct / (Samples.Count + 0.0);
43+
}
44+
45+
private Agent LoadAgent()
46+
{
47+
_platform = new BotSharpAi();
48+
49+
// Load agent
50+
var projectPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", "Spotify");
51+
string model = Directory.GetDirectories(projectPath).Where(x => x.Contains("model_")).Last().Split(Path.DirectorySeparatorChar).Last();
52+
var modelPath = Path.Combine(projectPath, model);
53+
var agent = _platform.LoadAgentFromFile(modelPath);
54+
55+
// Init samples
56+
Samples = new List<Tuple<AIRequest, string>>();
57+
/*agent.Corpus.UserSays = new List<TrainingIntentExpression<TrainingIntentExpressionPart>>
58+
{
59+
new TrainingIntentExpression<TrainingIntentExpressionPart>{ Intent = "music.play", Text = "play the 50 Great Beatles Songs playlist in Prime Music"},
60+
new TrainingIntentExpression<TrainingIntentExpressionPart>{ Intent = "music.play", Text = "reproduce a the track Monster by Rihanna ft Eminem"},
61+
new TrainingIntentExpression<TrainingIntentExpressionPart>{ Intent = "music_player_control.add_favorite", Text = "add this song to my favourites"}
62+
};*/
63+
agent.Corpus.UserSays.ForEach(intent =>
64+
{
65+
Samples.Add(new Tuple<AIRequest, string>(new AIRequest
66+
{
67+
AgentDir = projectPath,
68+
Model = model,
69+
Query = new String[]
70+
{
71+
intent.Text
72+
}
73+
}, intent.Intent));
74+
});
75+
76+
//Samples.Shuffle();
77+
78+
var samples = String.Join("\r\n", Samples.Select(x => $"__label__{x.Item2} {x.Item1.Query[0]}").ToList());
79+
80+
return agent;
81+
}
82+
}
83+
}

BotSharp.Core.UnitTest/TestEssential.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public abstract class TestEssential
1818
public TestEssential()
1919
{
2020
contentRoot = $"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}BotSharp.WebHost{Path.DirectorySeparatorChar}";
21-
21+
contentRoot = Path.GetFullPath(contentRoot);
2222
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
23-
var settings = Directory.GetFiles(contentRoot + $"Settings{Path.DirectorySeparatorChar}", "*.json");
23+
var settings = Directory.GetFiles(contentRoot + $"..{Path.DirectorySeparatorChar}Settings{Path.DirectorySeparatorChar}", "*.json");
2424
settings.ToList().ForEach(setting =>
2525
{
2626
configurationBuilder.AddJsonFile(setting, optional: false, reloadOnChange: true);

BotSharp.Core/BotSharp.Core.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ If you feel that this project is helpful to you, please Star on the project, we
6666

6767
<ItemGroup>
6868
<Compile Remove="Accounts\**" />
69+
<Compile Remove="Engines\CoreNlp\**" />
6970
<EmbeddedResource Remove="Accounts\**" />
71+
<EmbeddedResource Remove="Engines\CoreNlp\**" />
7072
<None Remove="Accounts\**" />
73+
<None Remove="Engines\CoreNlp\**" />
7174
</ItemGroup>
7275

7376
<ItemGroup>
@@ -80,10 +83,6 @@ If you feel that this project is helpful to you, please Star on the project, we
8083
<PackageReference Include="RestSharp" Version="106.3.1" />
8184
</ItemGroup>
8285

83-
<ItemGroup>
84-
<Folder Include="Engines\CoreNlp\" />
85-
</ItemGroup>
86-
8786
<ItemGroup>
8887
<ProjectReference Include="..\BotSharp.NLP\BotSharp.NLP.csproj" />
8988
</ItemGroup>

BotSharp.Core/Engines/BotEngineBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public AIResponse TextRequest(AIRequest request)
4646
{
4747
doc.Sentences[0].Entities = new List<NlpEntity>();
4848
}
49-
doc.Sentences[0].Entities.ForEach(x => parameters.Add(x.Entity, x.Value));
49+
doc.Sentences[0].Entities.ForEach(x => parameters[x.Entity] = x.Value);
5050

5151
return new AIResponse
5252
{

BotSharp.Core/Engines/BotSharp/BotSharpCBOWClassifier.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ public async Task<bool> Train(Agent agent, NlpDoc doc, PipeModel meta)
5858
var output = CmdHelper.Run(Path.Combine(Settings.AlgorithmDir, "fasttext"), $"supervised -input \"{parsedTrainingDataFileName}\" -output \"{modelFileName}\"", false);
5959

6060
Console.WriteLine($"Saved model to {modelFileName}");
61-
meta.Meta = new JObject();
62-
meta.Meta["compiled at"] = "Aug 3, 2018";
63-
6461

6562
return true;
6663
}

0 commit comments

Comments
 (0)