Пример #1
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (this.GetType() != obj.GetType())
            {
                return(false);
            }

            // safe because of the GetType check
            SerializableKeyValuePair <TKey, TValue> pair = (SerializableKeyValuePair <TKey, TValue>)obj;

            // use this pattern to compare reference members
            if (!Object.Equals(Key, pair.Key))
            {
                return(false);
            }

            // use this pattern to compare value members
            if (!Value.Equals(pair.Value))
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        public int Compare(SerializableKeyValuePair <TKey, TValue> x, SerializableKeyValuePair <TKey, TValue> y)
        {
            int val1 = x.Key.CompareTo(y.Key);
            int val2 = x.Value.CompareTo(y.Value);

            return(val1.CompareTo(val2));
        }
Пример #3
0
        /// <summary>
        /// The number of times a feature has appeared in a category
        /// </summary>
        /// <param name="feature">Feature</param>
        /// <param name="category">Category</param>
        /// <returns>Count of specified feature in specified category</returns>
        protected int FeaturesCount(string feature, string category)
        {
            SerializableKeyValuePair <string, string> pair = new SerializableKeyValuePair <string, string>(feature, category);

            if (FeatureCategoryCombinations.ContainsKey(pair))
            {
                return(FeatureCategoryCombinations[pair]);
            }
            return(0);
        }
Пример #4
0
        /// <summary>
        /// Increase the count of a feature/category pair
        /// </summary>
        /// <param name="feature">Pair: feature and its frequence</param>
        /// <param name="category">Category</param>
        protected void IncreaseFeatures(SerializableKeyValuePair <string, int> feature, string category)
        {
            SerializableKeyValuePair <string, string> pair = new SerializableKeyValuePair <string, string>(feature.Key, category);

            if (!FeatureCategoryCombinations.ContainsKey(pair))
            {
                FeatureCategoryCombinations.Add(pair, feature.Value);
            }
            else
            {
                FeatureCategoryCombinations[pair] += feature.Value;
            }
        }
Пример #5
0
        public bool DeleteFeatureCategoryCombination(string feature, string category)
        {
            SerializableKeyValuePair <string, string> pair =
                new SerializableKeyValuePair <string, string>(feature, category);

            if (FeatureCategoryCombinations.ContainsKey(pair))
            {
                int count = FeatureCategoryCombinations[pair];
                FeatureCategoryCombinations.Remove(pair);
                if (ItemsCountInCategory[category] >= count)
                {
                    ItemsCountInCategory[category] -= count;
                }
                else
                {
                    ItemsCountInCategory.Remove(category);
                    Thresholds.Remove(category);
                }

                return(true);
            }
            return(false);
        }