Beispiel #1
0
                                                   TimeSpan.FromDays(365 * 10)); //10 years

            private static byte[] getRawStemsFromServer(KeyAndId smlouvaKeyId)
            {
                Smlouva s = Smlouva.Load(smlouvaKeyId.ValueForData);

                if (s == null)
                {
                    return(null);
                }

                var settings = new JsonSerializerSettings();

                settings.ContractResolver = new HlidacStatu.Util.FirstCaseLowercaseContractResolver();

                string stemmerResponse = CallEndpoint("stemmer",
                                                      JsonConvert.SerializeObject(s, settings),
                                                      s.Id,
                                                      1000 * 60 * 30);

                try
                {
                    var jtoken = JToken.Parse(stemmerResponse);
                }
                catch (JsonReaderException e)
                {
                    Util.Consts.Logger.Error($"Stemmer returned incomplete json for {smlouvaKeyId.ValueForData}", e);
                    throw;
                }

                return(Encoding.UTF8.GetBytes(stemmerResponse));
            }
Beispiel #2
0
            /// <summary>
            /// Gets classification
            /// </summary>
            /// <param name="idSmlouvy"></param>
            /// <returns>Classification json</returns>
            public static string GetClassificationExplanation(string idSmlouvy)
            {
                if (string.IsNullOrWhiteSpace(idSmlouvy))
                {
                    return(null);
                }

                Smlouva s = Smlouva.Load(idSmlouvy);

                if (s == null)
                {
                    return(null);
                }

                var settings = new JsonSerializerSettings();

                settings.ContractResolver = new Util.FirstCaseLowercaseContractResolver();

                var response = CallEndpoint("explain_json",
                                            JsonConvert.SerializeObject(s, settings),
                                            idSmlouvy,
                                            1000 * 60 * 10);

                return(System.Text.RegularExpressions.Regex.Unescape(response));
            }
                                                   TimeSpan.FromDays(365 * 10)); //10 years

            private static byte[] getRawStemsFromServer(KeyAndId smlouvaKeyId)
            {
                Smlouva s = Smlouva.Load(smlouvaKeyId.ValueForData);

                if (s == null)
                {
                    return(null);
                }

                var settings = new JsonSerializerSettings();

                settings.ContractResolver = new HlidacStatu.Util.FirstCaseLowercaseContractResolver();


                using (Devmasters.Net.Web.URLContent stem = new Devmasters.Net.Web.URLContent(classificationBaseUrl() + "/stemmer"))
                {
                    stem.Method = Devmasters.Net.Web.MethodEnum.POST;
                    stem.Tries  = 3;
                    stem.TimeInMsBetweenTries = 5000;
                    stem.Timeout     = 1000 * 60 * 30; //30min
                    stem.ContentType = "application/json; charset=utf-8";
                    stem.RequestParams.RawContent = Newtonsoft.Json.JsonConvert.SerializeObject(s, settings);
                    Devmasters.Net.Web.BinaryContentResult stems = null;
                    try
                    {
                        Util.Consts.Logger.Debug("Getting stems from " + stem.Url);

                        stems = stem.GetBinary();
                        return(stems.Binary);
                    }
                    catch (Exception e)
                    {
                        Util.Consts.Logger.Error("Classification Stemmer API error " + stem.Url, e);
                        throw;
                    }
                }
            }