示例#1
0
 public void Clear()
 {
     TokenID.Clear();
     TokenFrequency.Clear();
     Tokens.Clear();
     InvokeChanged();
 }
示例#2
0
 public Boolean RemoveToken(String token)
 {
     Boolean output = TokenFrequency.Remove(token);
     output = output && TokenID.Remove(token);
     output = output && Tokens.Remove(token);
     InvokeChanged();
     return output;
 }
示例#3
0
 /// <summary>
 /// Gets frequency of the token
 /// </summary>
 /// <param name="token">The token.</param>
 /// <returns></returns>
 public Int32 GetTokenFrequency(String token)
 {
     if (Count == 0) return 0;
     if (TokenFrequency.ContainsKey(token))
     {
         return TokenFrequency[token];
     }
     return 0;
 }
示例#4
0
        /// <summary>
        /// Gets ranked list of tokens and their absolute frequencies
        /// </summary>
        /// <param name="limit">The limit.</param>
        /// <returns></returns>
        public List<KeyValuePair<String, Int32>> GetRankedTokenFrequency(Int32 limit = -1)
        {
            if (limit == -1) limit = Tokens.Count;

            List<KeyValuePair<String, Int32>> output = new List<KeyValuePair<string, int>>();
            ///List<KeyValuePair<String, Int32>> list = new List<KeyValuePair<string, int>>();

            List<KeyValuePair<string, int>> list = TokenFrequency.OrderByDescending(x => x.Value).ToList();

            output = list.Take(Math.Min(limit, list.Count)).ToList();
            return output;

        }
示例#5
0
        /// <summary>
        /// Returns cross-section tokens between the specified list and dictionary
        /// </summary>
        /// <param name="toMatch">To match.</param>
        /// <param name="removeFromToMatch">if set to <c>true</c> it will remove tokens that were matched from specified <c>toMatch</c> list.</param>
        /// <returns></returns>
        public List<String> GetTokens(List<String> toMatch, Boolean removeFromToMatch = true)
        {
            List<String> output = new List<string>();

            for (int i = 0; i < toMatch.Count; i++)
            {
                if (TokenFrequency.ContainsKey(toMatch[i]))
                {
                    output.Add(toMatch[i]);
                }
            }

            if (removeFromToMatch) toMatch.RemoveAll(x => output.Contains(x));


            return output;
        }
示例#6
0
        /// <summary>
        /// Removes specified tokens from the dictionary
        /// </summary>
        /// <param name="tokens">The tokens.</param>
        /// <param name="inverseFilter">if set to <c>true</c> [inverse filter].</param>
        /// <returns></returns>
        public Int32 FilterTokens(List<String> tokens, Boolean inverseFilter = true)
        {
            Int32 c = 0;
            if (!inverseFilter)
            {
                Tokens.RemoveAll(x => tokens.Contains(x));


                for (int i = 0; i < tokens.Count; i++)
                {
                    TokenFrequency.Remove(tokens[i]);
                    TokenID.Remove(tokens[i]);
                    c++;
                    
                }
                InvokeChanged();
                return c;
            }

            List<String> toRemove = new List<string>();


            if (inverseFilter)
            {
                var tkns = GetTokens();
                tokens.ForEach(x => tkns.Remove(x));
                toRemove.AddRange(tkns);
            }
            else
            {
                toRemove.AddRange(tokens);
            }

            foreach (String tkn in toRemove)
            {
                if (RemoveToken(tkn))
                {
                    c++;
                }
            }

            InvokeChanged();

            return c;
        }