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
|
|
|
|
|
|
{
|
2018-08-13 04:14:02 +00:00
|
|
|
|
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; }
|
2018-08-09 21:54:52 +00:00
|
|
|
|
public PipeSettings Settings { get; set; }
|
|
|
|
|
|
|
2018-08-13 04:14:02 +00:00
|
|
|
|
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");
|
2018-08-09 20:22:53 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|