BotSharp/BotSharp.Core/Engines/SpaCy/SpacyFeaturizer.cs

51 lines
1.6 KiB
C#
Raw Normal View History

2018-06-13 22:17:35 +00:00
using System;
using System.Collections.Generic;
using System.Text;
2018-08-08 21:39:00 +00:00
using System.Threading.Tasks;
2018-06-14 15:03:01 +00:00
using BotSharp.Core.Abstractions;
2018-06-15 17:39:24 +00:00
using BotSharp.Core.Agents;
2018-07-11 15:36:27 +00:00
using EntityFrameworkCore.BootKit;
2018-06-13 22:17:35 +00:00
using Microsoft.Extensions.Configuration;
2018-06-14 15:03:01 +00:00
using Newtonsoft.Json.Linq;
2018-06-13 22:17:35 +00:00
using RestSharp;
namespace BotSharp.Core.Engines.SpaCy
{
2018-06-14 15:03:01 +00:00
public class SpacyFeaturizer : INlpPipeline
2018-06-13 22:17:35 +00:00
{
public IConfiguration Configuration { get; set; }
public PipeSettings Settings { get; set; }
2018-06-13 22:17:35 +00:00
public async Task<bool> Train(Agent agent, NlpDoc doc, PipeModel meta)
2018-06-13 22:17:35 +00:00
{
var client = new RestClient(Configuration.GetSection("SpaCyProvider:Url").Value);
var request = new RestRequest("featurize", Method.GET);
2018-07-11 15:36:27 +00:00
List<List<decimal>> vectors = new List<List<decimal>>();
Boolean res = true;
var dc = new DefaultDataContextLoader().GetDefaultDc();
/*var corpus = agent.GrabCorpus(dc);
2018-06-13 22:17:35 +00:00
2018-07-11 15:36:27 +00:00
corpus.UserSays.ForEach(usersay => {
request.AddParameter("text", usersay.Text);
var response = client.Execute<Result>(request);
vectors.Add(response.Data.Vectors);
res = res && response.IsSuccessful;
});*/
2018-06-14 15:03:01 +00:00
// data.Add("Features", JToken.FromObject(vectors));
2018-07-11 15:36:27 +00:00
return res;
2018-06-13 22:17:35 +00:00
}
public async Task<bool> Predict(Agent agent, NlpDoc doc, PipeModel meta)
2018-08-08 21:39:00 +00:00
{
return true;
}
2018-06-13 22:17:35 +00:00
public class Result
{
public List<decimal> Vectors { get; set; }
}
}
}