Esempio n. 1
0
        /// <summary>
        ///     Compute Jaro-Winkler similarity.
        /// </summary>
        /// <param name="str1">The first string to compare.</param>
        /// <param name="str2">The second string to compare.</param>
        /// <returns>The Jaro-Winkler similarity in the range [0, 1]</returns>
        /// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
        public double Similarity(string str1, string str2)
        {
            Guarantee.IsStringNotNullOrEmpty(str1, nameof(str1));
            Guarantee.IsStringNotNullOrEmpty(str2, nameof(str2));

            if (str1.Equals(str2))
            {
                return(1f);
            }

            var   mtp = _macthes(str1, str2);
            float m   = mtp[0];

            if (m == 0)
            {
                return(0f);
            }
            double j = (m / str1.Length + m / str2.Length + (m - mtp[1]) / m)
                       / Three;
            var jw = j;

            if (j > DefaultThreshold)
            {
                jw = j + Math.Min(JwCoef, 1.0 / mtp[Three]) * mtp[2] * (1 - j);
            }
            return(jw);
        }
Esempio n. 2
0
        /// <summary>
        ///     Returns an authorized client via clientID and secretID.
        ///     This is an analog of constructor which is using <see cref="SpotifyClientConfig" />
        /// </summary>
        /// <param name="clientId">ClientID which you can get from your SpotifyApp</param>
        /// <param name="secretId">SecretID which you can get from your SpotifyApp</param>
        /// <returns>Instance of <see cref="SpotifySearchEngine{TIn}" /></returns>
        public static SpotifyClient GetAuthorizedByIds(string clientId, string secretId)
        {
            Guarantee.IsStringNotNullOrEmpty(clientId, nameof(clientId));
            Guarantee.IsStringNotNullOrEmpty(secretId, nameof(secretId));

            return(new SpotifyClient(SpotifyClientConfig.CreateDefault()
                                     .WithAuthenticator(new ClientCredentialsAuthenticator(clientId, secretId))));
        }
Esempio n. 3
0
        /// <summary>
        ///     Gets <see cref="User" /> via his screen name.
        /// </summary>
        /// <param name="screenName">Screen name of the user. Example: vk.com/@ThisIsYourScreenName@</param>
        /// <param name="vkApi">Authorized Vk Api</param>
        /// <returns>If user is not found it returns NULL.</returns>
        /// <example><see cref="screenName" />="id345234523"</example>
        public static User GetUserByScreenName(string screenName, VkApi vkApi)
        {
            Guarantee.IsStringNotNullOrEmpty(screenName, nameof(screenName));
            Guarantee.IsArgumentNotNull(vkApi, nameof(vkApi));

            if (!vkApi.IsAuthorized)
            {
                throw new ArgumentException("API has to be authorized.", nameof(vkApi));
            }

            return(vkApi.Users.Get(new[] { screenName })?.FirstOrDefault());
        }
Esempio n. 4
0
        /// <summary>
        /// Splits your Enumerable into lists with the specified count of max elements.
        /// </summary>
        /// <param name="collection">Your collection.</param>
        /// <param name="nSize">Max size of one list.</param>
        /// <typeparam name="T">It doesn't make a sense. I mean whatever you want :D</typeparam>
        /// <returns></returns>
        public static IEnumerable <List <T> > SplitOnLists <T>(IEnumerable <T> collection, int nSize = 30)
        {
            Guarantee.IsEnumerableNotNullOrEmpty(collection, nameof(collection));

            //transform to list cause you can get there a range without any problems :)
            var listToSplit = new List <T>(collection);
            var listOfLists = new List <List <T> >();

            for (int i = 0; i < listToSplit.Count; i += nSize)
            {
                listOfLists.Add(listToSplit.GetRange(i, Math.Min(nSize, listToSplit.Count - i)));
            }

            return(listOfLists);
        }
Esempio n. 5
0
        /// <summary>
        ///     Authorize <see cref="VkApi" /> by specified login and password.
        ///     Attaches VkAudioService to get music from VK.
        /// </summary>
        /// <param name="login">Your login.</param>
        /// <param name="password">Your password.</param>
        /// <returns>Authorized VK.</returns>
        public static VkApi AuthorizeApi(string login, string password)
        {
            Guarantee.IsStringNotNullOrEmpty(login, nameof(login));
            Guarantee.IsStringNotNullOrEmpty(password, nameof(password));

            var services = new ServiceCollection();

            services.AddAudioBypass();

            var api = new VkApi(services);

            api.Authorize(new ApiAuthParams
            {
                Login    = login,
                Password = password
            });

            return(api);
        }