BotSharp/BotSharp.Core/Engines/SpaCy/SpaCyProvider.cs

44 lines
1.3 KiB
C#
Raw Normal View History

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-06-14 15:03:01 +00:00
using Microsoft.Extensions.Configuration;
2018-08-08 21:39:00 +00:00
using Newtonsoft.Json;
2018-06-14 15:03:01 +00:00
using Newtonsoft.Json.Linq;
2018-06-13 22:17:35 +00:00
using RestSharp;
2018-06-13 12:23:03 +00:00
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
2018-08-08 21:39:00 +00:00
using System.Threading.Tasks;
2018-06-13 12:23:03 +00:00
namespace BotSharp.Core.Engines.SpaCy
{
public class SpaCyProvider : INlpProvider
2018-06-13 12:23:03 +00:00
{
2018-06-13 22:17:35 +00:00
public IConfiguration Configuration { get; set; }
public PipeSettings Settings { get; set; }
public async Task<bool> Load(Agent agent, PipeModel meta)
2018-06-13 12:23:03 +00:00
{
2018-06-13 22:17:35 +00:00
var client = new RestClient(Configuration.GetSection("SpaCyProvider:Url").Value);
var request = new RestRequest("load", Method.GET);
2018-08-08 21:39:00 +00:00
var response = client.Execute<Result>(request);
meta.Meta = JObject.FromObject(response.Data);
2018-08-12 04:52:38 +00:00
meta.Meta.Remove("models");
meta.Model = response.Data.Models;
2018-06-13 22:17:35 +00:00
return response.IsSuccessful;
2018-06-13 12:23:03 +00:00
}
2018-08-08 21:39:00 +00:00
private class Result
{
[JsonProperty("spaCy ver")]
public string Version { get; set; }
[JsonProperty("models")]
public string Models { get; set; }
[JsonProperty("python ver")]
public string Python { get; set; }
}
2018-06-13 12:23:03 +00:00
}
}