Пример #1
0
 public async Task <IActionResult> TrainSegmentAsync(string locatorType, string locator,
                                                     [FromBody] SegmentPairDto segmentPair)
 {
     if (!await _engineService.TrainSegmentAsync(GetLocatorType(locatorType), locator, segmentPair.SourceSegment,
                                                 segmentPair.TargetSegment))
     {
         return(NotFound());
     }
     return(Ok());
 }
Пример #2
0
 public void TryTrainSegment_LanguagePairDoesNotExist_ReturnsFalse()
 {
     using (var tempDir = new TempDirectory("EngineServiceTests"))
     {
         var service = new EngineService(CreateOptions(tempDir.Path), CreateSmtModelFactory(), CreateRuleEngineFactory());
         var pairDto = new SegmentPairDto
         {
             SourceSegment = "Esto es una prueba .".Split(),
             TargetSegment = "This is a test .".Split()
         };
         service.TryTrainSegment("es", "en", null, pairDto).Should().BeFalse();
     }
 }
Пример #3
0
        public async Task <IActionResult> TrainSegmentAsync(string locatorType, string locator,
                                                            [FromBody] SegmentPairDto segmentPair)
        {
            Engine engine = await _engines.GetByLocatorAsync(GetLocatorType(locatorType), locator);

            if (engine == null)
            {
                return(NotFound());
            }
            if (!await AuthorizeAsync(engine, Operations.Update))
            {
                return(StatusCode(StatusCodes.Status403Forbidden));
            }

            if (!await _engineService.TrainSegmentAsync(engine.Id, segmentPair.SourceSegment,
                                                        segmentPair.TargetSegment))
            {
                return(NotFound());
            }
            return(Ok());
        }
Пример #4
0
        public async Task TrainSegmentPairAsync(string projectId, IReadOnlyList <string> sourceSegment,
                                                IReadOnlyList <string> targetSegment)
        {
            string url     = $"translation/engines/project:{projectId}/actions/trainSegment";
            var    pairDto = new SegmentPairDto
            {
                SourceSegment = sourceSegment.ToArray(),
                TargetSegment = targetSegment.ToArray()
            };
            string       body     = JsonConvert.SerializeObject(pairDto, SerializerSettings);
            HttpResponse response = await HttpClient.SendAsync(HttpRequestMethod.Post, url, body, "application/json");

            if (!response.IsSuccess)
            {
                throw new HttpException("Error calling trainSegment action.")
                      {
                          StatusCode = response.StatusCode
                      }
            }
            ;
        }
Пример #5
0
        public bool TryTrainSegment(string sourceLanguageTag, string targetLanguageTag, string projectId, SegmentPairDto segmentPair)
        {
            Engine engine;

            if (TryGetEngine(sourceLanguageTag, targetLanguageTag, projectId, out engine))
            {
                lock (engine)
                {
                    if (engine.IsDisposed)
                    {
                        return(false);
                    }

                    engine.TrainSegmentPair(segmentPair.SourceSegment.Select(s => s.ToLowerInvariant()).ToArray(),
                                            segmentPair.TargetSegment.Select(s => s.ToLowerInvariant()).ToArray());
                    return(true);
                }
            }

            return(false);
        }
Пример #6
0
 public IActionResult TrainSegment(string sourceLanguageTag, string targetLanguageTag, string projectId, [FromBody] SegmentPairDto segmentPair)
 {
     if (_engineService.TryTrainSegment(sourceLanguageTag, targetLanguageTag, projectId, segmentPair))
     {
         return(Ok());
     }
     return(NotFound());
 }