-
Notifications
You must be signed in to change notification settings - Fork 4
/
IntentClassificator.cs
56 lines (40 loc) · 1.78 KB
/
IntentClassificator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json.Linq;
using Starlight.MLCore;
namespace Starlight {
public class IntentClassificator {
static readonly string datasetPath = Path.Combine(Environment.CurrentDirectory, "Dataset");
static List<string> _intentList;
List<BinaryClassificator> _binaryClassificators;
public IntentClassificator(string datasetpath = null, bool debug = false) {
_binaryClassificators = new List<BinaryClassificator>();
if (debug)
Console.WriteLine("=============== Starlight Build ===============\n");
foreach (var intentName in GetIntentList())
_binaryClassificators.Add(new BinaryClassificator(intentName, datasetpath, false, debug));
}
public JObject Cognize(string query, bool debug = false) {
Utterance utterance = new Utterance();
utterance.Query = query;
for (int i = 0; i < _intentList.Count; i++)
utterance.Intents.Add(_binaryClassificators[i].Classify(query, debug));
if (utterance.TopScoringIntent.Score < 0.8) {
utterance.Intents.Add(new Intent("none", (float) 0.8));
}
EntityExtractors.EntityExtractorController.Fetch(utterance);
return utterance.GetResponse();
}
static List<string> GetIntentList() {
DirectoryInfo d = new DirectoryInfo(datasetPath);
FileInfo[] files = d.GetFiles("*.txt");
_intentList = new List<string>();
foreach (FileInfo file in files) {
_intentList.Add(file.Name.Replace(".txt", string.Empty));
}
return _intentList;
}
}
}