Repository navigation
Expand file tree
/
Copy pathBotSharpTagger.cs
More file actions
70 lines (57 loc) · 1.75 KB
/
Copy pathBotSharpTagger.cs
File metadata and controls
70 lines (57 loc) · 1.75 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using BotSharp.Core.Abstractions;
using BotSharp.NLP;
using BotSharp.NLP.Corpus;
using BotSharp.NLP.Tag;
using BotSharp.NLP.Tokenize;
using BotSharp.Platform.Models;
using BotSharp.Platform.Models.MachineLearning;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace BotSharp.Core.Engines.BotSharp
{
public class BotSharpTagger : INlpTrain, INlpPredict
{
public IConfiguration Configuration { get; set; }
public PipeSettings Settings { get; set; }
private TaggerFactory _tagger;
public BotSharpTagger()
{
}
public async Task<bool> Predict(AgentBase agent, NlpDoc doc, PipeModel meta)
{
Init();
doc.Sentences.ForEach(x => _tagger.Tag(new Sentence
{
Words = x.Tokens,
Text = x.Text
}));
return true;
}
public async Task<bool> Train(AgentBase agent, NlpDoc doc, PipeModel meta)
{
Init();
doc.Sentences.ForEach(x => _tagger.Tag(new Sentence
{
Words = x.Tokens,
Text = x.Text
}));
return true;
}
private void Init()
{
if (_tagger == null)
{
_tagger = new TaggerFactory(new TagOptions
{
CorpusDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Corpus")
}, SupportedLanguage.English);
string tokenizerName = Configuration.GetValue<String>($"tagger");
_tagger.GetTagger(tokenizerName);
}
}
}
}