public async Task AnalysisDocuments()
        {
            DocumentParsing parsing = new DocumentParsing(new ApiClientFactory(wrapper.Client, wrapper.Client.BaseAddress));

            byte[] data = await File.ReadAllBytesAsync(Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "Research.pdf")).ConfigureAwait(false);

            var result = await parsing.Extract(
                new FileRequest
            {
                FileData = new FileData
                {
                    Data = data,
                    Name = "Market.pdf",
                },
                Header =
                    new RequestHeader
                {
                    Domain = "Market"
                }
            },
                CancellationToken.None).ConfigureAwait(false);

            var analysis = new SupervisedAnalysis(new ApiClientFactory(wrapper.Client, wrapper.Client.BaseAddress));
            DocumentAnomalyData anomalyData = new DocumentAnomalyData();

            anomalyData.Name     = "Test";
            anomalyData.Negative = result.Take(2).Concat(result.Skip(30)).ToArray();
            anomalyData.Positive = result.Skip(2).Take(29).ToArray();
            await analysis.Reset("Test", CancellationToken.None).ConfigureAwait(false);

            await analysis.Add(anomalyData, CancellationToken.None).ConfigureAwait(false);

            await analysis.Train("Test", CancellationToken.None).ConfigureAwait(false);

            Assert.ThrowsAsync <ServiceException>(async() => await analysis.Resolve("xxx", result, CancellationToken.None).ConfigureAwait(false));
            Assert.ThrowsAsync <ServiceException>(async() => await analysis.Resolve("xxx", result[0], CancellationToken.None).ConfigureAwait(false));
            var anomaly = await analysis.Resolve("Test", result, CancellationToken.None).ConfigureAwait(false);

            Assert.AreEqual(31, anomaly.Positive.Length);
            Assert.AreEqual(4, anomaly.Negative.Length);

            var sentence = await analysis.Resolve("Test", result[3], CancellationToken.None).ConfigureAwait(false);

            Assert.AreEqual(16, sentence.Positive.Length);
            Assert.AreEqual(5, sentence.Negative.Length);
        }
        public void Add(DocumentAnomalyData anomalyData)
        {
            if (anomalyData == null)
            {
                throw new ArgumentNullException(nameof(anomalyData));
            }

            IModelStorage model = modelStorageFactory.Construct(anomalyData.Name);

            if (anomalyData.Positive?.Length > 0)
            {
                model.Add(DataType.Positive, anomalyData.Positive.Select(item => new ProcessingTextBlock(item.Sentences.ToArray())).ToArray());
            }

            if (anomalyData.Negative?.Length > 0)
            {
                model.Add(DataType.Negative, anomalyData.Negative.Select(item => new ProcessingTextBlock(item.Sentences.ToArray())).ToArray());
            }

            modelStorageFactory.Save(anomalyData.Name, model);
        }
예제 #3
0
 public ActionResult Add([FromBody] DocumentAnomalyData anomalyData)
 {
     anomalyDetection.Add(anomalyData);
     return(Ok("Added"));
 }
예제 #4
0
 public Task Add(DocumentAnomalyData anomalyData, CancellationToken token)
 {
     return(client.PostRequest <DocumentAnomalyData, RawResponse <string> >("api/supervised/add", anomalyData, token).ProcessResult());
 }