Example #1
0
        /// <summary>
        /// Get text statistics
        /// </summary>
        /// <param name="textToQuery">text where calculate statistics</param>
        /// <returns>TextStatistic object  with calculated statistics</returns>
        public TextStatistics GetStatistics(string textToQuery)
        {
            IEngineCalculator currentEngine = DIService.ContainerService.ResolveNamed <IEngineCalculator>(TextConstants.DEFAULT_ENGINE);

            currentEngine.RegisterStatisticCalculator(DIService.ContainerService.ResolveKeyed <ICountingStatisticCalculator>(eStatistics.WordCount));
            currentEngine.RegisterStatisticCalculator(DIService.ContainerService.ResolveKeyed <ICountingStatisticCalculator>(eStatistics.HyphensCount));
            currentEngine.RegisterStatisticCalculator(DIService.ContainerService.ResolveKeyed <ICountingStatisticCalculator>(eStatistics.SpaceCount));

            return(currentEngine.Calculate(textToQuery));
        }
Example #2
0
        public ActionResult <EngineResult> Get(string id)
        {
            try
            {
                var arxivarRestConfiguration = new IO.Swagger.Client.Configuration()
                {
                    BasePath = _appSettingsService.ARXivarNextWebApiUrl,
                    ApiKey   = new Dictionary <string, string>()
                    {
                        { "Authorization", Request.Headers["Authorization"] }
                    },
                    ApiKeyPrefix = new Dictionary <string, string>()
                    {
                        { "Authorization", "" }
                    }
                };

                var usersApi = new IO.Swagger.Api.UsersApi(arxivarRestConfiguration);

                var userInfo = usersApi.UsersGetUserInfo();
                var userInfo_CompleteDescription = userInfo.CompleteDescription;
                var userInfo_CompleteName        = userInfo.CompleteName;
                var userInfo_UserId = userInfo.User;

                ClaimsIdentity claims       = (this.User.Identity as ClaimsIdentity);
                string         userIdString = claims.FindFirst("arx:user_id").Value;
                int            userIdNumber = System.Convert.ToInt32(userIdString);
                IO.Swagger.Model.UserInfoDTO userInfoDTO = usersApi.UsersGet(userIdNumber);

                EngineResult model;
                if (_cache.TryGetValue(id, out model))
                {
                    return(model);
                }

                var engineCount = _engineInfoService.GetCountById(id);
                if (engineCount == null)
                {
                    return(StatusCode(404));
                }
                if (engineCount.C < 1)
                {
                    return(StatusCode(404, string.Format("Id '{0}' not found.", id)));
                }
                if (engineCount.C > 1)
                {
                    return(StatusCode(403, string.Format("Id '{0}' found too many times {1}", id, engineCount.C)));
                }


                var engineInfo = _engineInfoService.GetDataById(id);
                if (engineInfo == null)
                {
                    return(StatusCode(404));
                }

                model = _engineCalculator.Calculate(id, engineInfo);

                _cache.Set(id, model, new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromMinutes(_appSettingsService.CacheMin)));

                return(model);
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
 /// <summary>
 /// Get text statistics
 /// </summary>
 /// <param name="textToQuery">text where calculate statistics</param>
 /// <returns>TextStatistic object  with calculated statistics</returns>
 public TextStatistics GetStatistics(string textToQuery)
 {
     return(engine.Calculate(textToQuery));
 }