public virtual void IncrementCount(K1 o1, K2 o2, int count)
        {
            IntCounter <K2> c = GetCounter(o1);

            c.IncrementCount(o2, count);
            total += count;
        }
        public virtual void SubtractAll(K1 key, IntCounter <K2> c)
        {
            IntCounter <K2> myInner = GetCounter(key);

            Counters.SubtractInPlace(myInner, c);
            total -= c.TotalIntCount();
        }
        public virtual void AddAll(K1 key, IntCounter <K2> c)
        {
            IntCounter <K2> myInner = GetCounter(key);

            Counters.AddInPlace(myInner, c);
            total += c.TotalIntCount();
        }
        public virtual void SetCount(K1 o1, K2 o2, int count)
        {
            IntCounter <K2> c        = GetCounter(o1);
            int             oldCount = GetCount(o1, o2);

            total -= oldCount;
            c.SetCount(o2, count);
            total += count;
        }
        /// <summary>replace the counter for K1-index o by new counter c</summary>
        public virtual IntCounter <K2> SetCounter(K1 o, IntCounter <K2> c)
        {
            IntCounter <K2> old = GetCounter(o);

            total -= old.TotalIntCount();
            map[o] = c;
            total += c.TotalIntCount();
            return(old);
        }
        public virtual IntCounter <K1> TotalCounts()
        {
            IntCounter <K1> tc = new IntCounter <K1>();

            foreach (K1 k1 in map.Keys)
            {
                tc.SetCount(k1, map[k1].TotalCount());
            }
            return(tc);
        }
        public virtual int GetCount(K1 o1, K2 o2)
        {
            IntCounter <K2> c = GetCounter(o1);

            if (c.TotalCount() == 0 && !c.KeySet().Contains(o2))
            {
                return(DefaultReturnValue());
            }
            return(c.GetIntCount(o2));
        }
        public virtual bool ContainsKey(K1 o1, K2 o2)
        {
            if (!map.Contains(o1))
            {
                return(false);
            }
            IntCounter <K2> c = map[o1];

            return(c.ContainsKey(o2));
        }
 public virtual void AddAll(Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter <K1, K2> c)
 {
     foreach (K1 key in c.FirstKeySet())
     {
         IntCounter <K2> inner   = c.GetCounter(key);
         IntCounter <K2> myInner = GetCounter(key);
         Counters.AddInPlace(myInner, inner);
         total += inner.TotalIntCount();
     }
 }
        // it's empty, get rid of it!
        public virtual void Remove(K1 key)
        {
            IntCounter <K2> counter = map[key];

            if (counter != null)
            {
                total -= counter.TotalIntCount();
            }
            Sharpen.Collections.Remove(map, key);
        }
        /// <returns>total number of entries (key pairs)</returns>
        public virtual int Size()
        {
            int result = 0;

            foreach (K1 o in FirstKeySet())
            {
                IntCounter <K2> c = map[o];
                result += c.Size();
            }
            return(result);
        }
        /// <returns>the inner Counter associated with key o</returns>
        public virtual IntCounter <K2> GetCounter(K1 o)
        {
            IntCounter <K2> c = map[o];

            if (c == null)
            {
                c = new IntCounter <K2>(innerMF);
                c.SetDefaultReturnValue(defaultValue);
                map[o] = c;
            }
            return(c);
        }
        public virtual int Remove(K1 o1, K2 o2)
        {
            IntCounter <K2> c        = GetCounter(o1);
            int             oldCount = GetCount(o1, o2);

            total -= oldCount;
            c.Remove(o2);
            if (c.IsEmpty())
            {
                Sharpen.Collections.Remove(map, o1);
            }
            return(oldCount);
        }
        public virtual void RemoveZeroCounts()
        {
            ICollection <K1> firstKeySet = Generics.NewHashSet(FirstKeySet());

            foreach (K1 k1 in firstKeySet)
            {
                IntCounter <K2> c = GetCounter(k1);
                Counters.RetainNonZeros(c);
                if (c.IsEmpty())
                {
                    Sharpen.Collections.Remove(map, k1);
                }
            }
        }
 public virtual void SubtractAll(Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter <K1, K2> c, bool removeKeys)
 {
     foreach (K1 key in c.FirstKeySet())
     {
         IntCounter <K2> inner   = c.GetCounter(key);
         IntCounter <K2> myInner = GetCounter(key);
         Counters.SubtractInPlace(myInner, inner);
         if (removeKeys)
         {
             Counters.RetainNonZeros(myInner);
         }
         total -= inner.TotalIntCount();
     }
 }
        /// <summary>
        /// A simple String representation of this TwoDimensionalCounter, which has
        /// the String representation of each key pair
        /// on a separate line, followed by the count for that pair.
        /// </summary>
        /// <remarks>
        /// A simple String representation of this TwoDimensionalCounter, which has
        /// the String representation of each key pair
        /// on a separate line, followed by the count for that pair.
        /// The items are tab separated, so the result is a tab-separated value (TSV)
        /// file.  Iff none of the keys contain spaces, it will also be possible to
        /// treat this as whitespace separated fields.
        /// </remarks>
        public override string ToString()
        {
            StringBuilder buff = new StringBuilder();

            foreach (K1 key1 in map.Keys)
            {
                IntCounter <K2> c = GetCounter(key1);
                foreach (K2 key2 in c.KeySet())
                {
                    double score = c.GetCount(key2);
                    buff.Append(key1).Append("\t").Append(key2).Append("\t").Append(score).Append("\n");
                }
            }
            return(buff.ToString());
        }
        public virtual IntCounter <Pair <K1, K2> > Flatten()
        {
            IntCounter <Pair <K1, K2> > result = new IntCounter <Pair <K1, K2> >();

            result.SetDefaultReturnValue(defaultValue);
            foreach (K1 key1 in FirstKeySet())
            {
                IntCounter <K2> inner = GetCounter(key1);
                foreach (K2 key2 in inner.KeySet())
                {
                    result.SetCount(new Pair <K1, K2>(key1, key2), inner.GetIntCount(key2));
                }
            }
            return(result);
        }
 /// <summary>Produces a new ConditionalCounter.</summary>
 /// <returns>a new ConditionalCounter, where order of indices is reversed</returns>
 public static Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter <K2, K1> ReverseIndexOrder <K1, K2>(Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter <K1, K2> cc)
 {
     // the typing on the outerMF is violated a bit, but it'll work....
     Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter <K2, K1> result = new Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter((MapFactory)cc.outerMF, (MapFactory)cc.innerMF);
     foreach (K1 key1 in cc.FirstKeySet())
     {
         IntCounter <K2> c = cc.GetCounter(key1);
         foreach (K2 key2 in c.KeySet())
         {
             int count = c.GetIntCount(key2);
             result.SetCount(key2, key1, count);
         }
     }
     return(result);
 }
 public virtual void Clean()
 {
     foreach (K1 key1 in Generics.NewHashSet(map.Keys))
     {
         IntCounter <K2> c = map[key1];
         foreach (K2 key2 in Generics.NewHashSet(c.KeySet()))
         {
             if (c.GetIntCount(key2) == 0)
             {
                 c.Remove(key2);
             }
         }
         if (c.KeySet().IsEmpty())
         {
             Sharpen.Collections.Remove(map, key1);
         }
     }
 }
Пример #20
0
 public virtual void ClearCounts()
 {
     if (foundCorrect != null)
     {
         foundCorrect.Clear();
     }
     else
     {
         foundCorrect = new IntCounter <L>();
     }
     if (foundGuessed != null)
     {
         foundGuessed.Clear();
     }
     else
     {
         foundGuessed = new IntCounter <L>();
     }
     if (correctGuesses != null)
     {
         correctGuesses.Clear();
     }
     else
     {
         correctGuesses = new IntCounter <L>();
     }
     if (tpCount != null)
     {
         Arrays.Fill(tpCount, 0);
     }
     if (fnCount != null)
     {
         Arrays.Fill(fnCount, 0);
     }
     if (fpCount != null)
     {
         Arrays.Fill(fpCount, 0);
     }
     tokensCount   = 0;
     tokensCorrect = 0;
 }
 public _AbstractCollection_750(IntCounter <E> _enclosing)
 {
     this._enclosing = _enclosing;
 }
 public _IFactory_726(IntCounter <E> _enclosing)
 {
     this._enclosing       = _enclosing;
     this.serialVersionUID = 7470763055803428477L;
 }
 public _AbstractSet_436(IntCounter <E> _enclosing)
 {
     this._enclosing = _enclosing;
 }
Пример #24
0
 public _IFactory_726(IntCounter <E> _enclosing)
 {
     this._enclosing       = _enclosing;
     this.serialVersionUID = serialVersionUID;
 }
        public virtual int TotalCount(K1 k1)
        {
            IntCounter <K2> c = GetCounter(k1);

            return(c.TotalIntCount());
        }