public virtual void TestCoreMap()
        {
            ICoreMap @object = new ArrayCoreMap(0);

            NUnit.Framework.Assert.IsFalse(@object.ContainsKey(typeof(CoreMapTest.StringA)));
            @object.Set(typeof(CoreMapTest.StringA), "stem");
            NUnit.Framework.Assert.IsTrue(@object.ContainsKey(typeof(CoreMapTest.StringA)));
            NUnit.Framework.Assert.AreEqual("stem", @object.Get(typeof(CoreMapTest.StringA)));
            @object.Set(typeof(CoreMapTest.StringA), "hi");
            NUnit.Framework.Assert.AreEqual("hi", @object.Get(typeof(CoreMapTest.StringA)));
            NUnit.Framework.Assert.AreEqual(null, @object.Get(typeof(CoreMapTest.IntegerA)));
            @object.Set(typeof(CoreMapTest.IntegerA), 4);
            NUnit.Framework.Assert.AreEqual(int.Parse(4), @object.Get(typeof(CoreMapTest.IntegerA)));
            @object.Set(typeof(CoreMapTest.StringB), "Yes");
            NUnit.Framework.Assert.AreEqual("Wrong # objects", 3, @object.KeySet().Count);
            NUnit.Framework.Assert.AreEqual("Wrong keyset", new HashSet <Type>(Arrays.AsList(typeof(CoreMapTest.StringA), typeof(CoreMapTest.IntegerA), typeof(CoreMapTest.StringB))), @object.KeySet());
            NUnit.Framework.Assert.AreEqual("Wrong remove value", int.Parse(4), @object.Remove(typeof(CoreMapTest.IntegerA)));
            NUnit.Framework.Assert.AreEqual("Wrong # objects", 2, @object.KeySet().Count);
            NUnit.Framework.Assert.AreEqual("Wrong keyset", new HashSet <Type>(Arrays.AsList(typeof(CoreMapTest.StringA), typeof(CoreMapTest.StringB))), @object.KeySet());
            NUnit.Framework.Assert.AreEqual("Wrong value", "hi", @object.Get(typeof(CoreMapTest.StringA)));
            NUnit.Framework.Assert.AreEqual("Wrong value", "Yes", @object.Get(typeof(CoreMapTest.StringB)));
            NUnit.Framework.Assert.AreEqual(null, @object.Set(typeof(CoreMapTest.IntegerA), 7));
            NUnit.Framework.Assert.AreEqual(int.Parse(7), @object.Get(typeof(CoreMapTest.IntegerA)));
            NUnit.Framework.Assert.AreEqual(int.Parse(7), @object.Set(typeof(CoreMapTest.IntegerA), 3));
            NUnit.Framework.Assert.AreEqual(int.Parse(3), @object.Get(typeof(CoreMapTest.IntegerA)));
        }
        public virtual void TestEqualsReversedInsertOrder()
        {
            ArrayCoreMap     foo        = new ArrayCoreMap();
            IList <ICoreMap> paragraphs = new List <ICoreMap>();
            ArrayCoreMap     f1         = new ArrayCoreMap();

            f1.Set(typeof(CoreAnnotations.TextAnnotation), "f");
            paragraphs.Add(f1);
            ArrayCoreMap f2 = new ArrayCoreMap();

            f2.Set(typeof(CoreAnnotations.TextAnnotation), "o");
            paragraphs.Add(f2);
            foo.Set(typeof(CoreAnnotations.ParagraphsAnnotation), paragraphs);
            foo.Set(typeof(CoreAnnotations.TextAnnotation), "A");
            foo.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "B");
            ArrayCoreMap     bar         = new ArrayCoreMap();
            IList <ICoreMap> paragraphs2 = new List <ICoreMap>(paragraphs);

            bar.Set(typeof(CoreAnnotations.TextAnnotation), "A");
            bar.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "B");
            bar.Set(typeof(CoreAnnotations.ParagraphsAnnotation), paragraphs2);
            NUnit.Framework.Assert.AreEqual(foo, bar);
            NUnit.Framework.Assert.AreEqual(bar, foo);
            NUnit.Framework.Assert.IsFalse(foo.Equals(f1));
            NUnit.Framework.Assert.IsFalse(foo.Equals(f2));
            NUnit.Framework.Assert.AreEqual(3, foo.Size());
        }
        public virtual void TestGetAndSet()
        {
            ArrayCoreMap foo = new ArrayCoreMap();

            NUnit.Framework.Assert.AreEqual(0, foo.Size());
            foo.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            NUnit.Framework.Assert.AreEqual("foo", foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.ParagraphsAnnotation)));
            NUnit.Framework.Assert.AreEqual(1, foo.Size());
            foo.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "F");
            NUnit.Framework.Assert.AreEqual("foo", foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual("F", foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.ParagraphsAnnotation)));
            NUnit.Framework.Assert.AreEqual(2, foo.Size());
            IList <ICoreMap> paragraphs = new List <ICoreMap>();
            ArrayCoreMap     f1         = new ArrayCoreMap();

            f1.Set(typeof(CoreAnnotations.TextAnnotation), "f");
            paragraphs.Add(f1);
            ArrayCoreMap f2 = new ArrayCoreMap();

            f2.Set(typeof(CoreAnnotations.TextAnnotation), "o");
            paragraphs.Add(f2);
            foo.Set(typeof(CoreAnnotations.ParagraphsAnnotation), paragraphs);
            NUnit.Framework.Assert.AreEqual("foo", foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual("F", foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            // will test equality of the coremaps in another test
            NUnit.Framework.Assert.AreEqual(3, foo.Size());
        }
        public virtual void TestMaps()
        {
            Random           random = new Random();
            IList <ICoreMap> maps   = new LinkedList <ICoreMap>();

            for (int i = 0; i < 25; i++)
            {
                ArrayCoreMap m = new ArrayCoreMap();
                m.Set(typeof(CoreMapTest.IntegerA), random.NextInt());
                maps.Add(m);
            }
            IDictionary <ICoreMap, int> view = CoreMaps.AsMap(maps, typeof(CoreMapTest.IntegerA));

            // test getting and setting
            foreach (ICoreMap map in maps)
            {
                NUnit.Framework.Assert.IsTrue(view.Contains(map));
                NUnit.Framework.Assert.AreEqual(view[map], map.Get(typeof(CoreMapTest.IntegerA)));
                int v = random.NextInt();
                map.Set(typeof(CoreMapTest.IntegerA), v);
                NUnit.Framework.Assert.AreEqual(view[map], v);
                NUnit.Framework.Assert.AreEqual(view[map], map.Get(typeof(CoreMapTest.IntegerA)));
            }
            // test iterating and set views
            NUnit.Framework.Assert.AreEqual(new LinkedList <ICoreMap>(view.Keys), maps);
            foreach (KeyValuePair <ICoreMap, int> entry in view)
            {
                NUnit.Framework.Assert.AreEqual(entry.Key.Get(typeof(CoreMapTest.IntegerA)), entry.Value);
                int v = random.NextInt();
                entry.SetValue(v);
                NUnit.Framework.Assert.AreEqual(entry.Value, v);
                NUnit.Framework.Assert.AreEqual(entry.Key.Get(typeof(CoreMapTest.IntegerA)), v);
            }
        }
        public virtual void TestKeySet()
        {
            ArrayCoreMap foo = new ArrayCoreMap();

            foo.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            foo.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "NN");
            foo.Set(typeof(CoreAnnotations.DocIDAnnotation), null);
            NUnit.Framework.Assert.IsTrue(foo.KeySet().Contains(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.IsTrue(foo.KeySet().Contains(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            NUnit.Framework.Assert.IsTrue(foo.KeySet().Contains(typeof(CoreAnnotations.DocIDAnnotation)));
            NUnit.Framework.Assert.IsFalse(foo.KeySet().Contains(typeof(CoreAnnotations.TokensAnnotation)));
        }
        public virtual void TestToShortString()
        {
            ArrayCoreMap foo = new ArrayCoreMap();

            foo.Set(typeof(CoreAnnotations.TextAnnotation), "word");
            foo.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "NN");
            NUnit.Framework.Assert.AreEqual("word/NN", foo.ToShortString("Text", "PartOfSpeech"));
            NUnit.Framework.Assert.AreEqual("NN", foo.ToShortString("PartOfSpeech"));
            NUnit.Framework.Assert.AreEqual(string.Empty, foo.ToShortString("Lemma"));
            NUnit.Framework.Assert.AreEqual("word|NN", foo.ToShortString('|', "Text", "PartOfSpeech", "Lemma"));
            foo.Set(typeof(CoreAnnotations.AntecedentAnnotation), "the price of tea");
            NUnit.Framework.Assert.AreEqual("{word/NN/the price of tea}", foo.ToShortString("Text", "PartOfSpeech", "Antecedent"));
        }
        public virtual void TestToShorterString()
        {
            ArrayCoreMap a = new ArrayCoreMap();

            a.Set(typeof(CoreAnnotations.TextAnnotation), "Australia");
            a.Set(typeof(CoreAnnotations.NamedEntityTagAnnotation), "LOCATION");
            a.Set(typeof(CoreAnnotations.BeforeAnnotation), "  ");
            a.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "NNP");
            a.Set(typeof(CoreAnnotations.ShapeAnnotation), "Xx");
            NUnit.Framework.Assert.AreEqual("Incorrect toShorterString()", "[Text=Australia NamedEntityTag=LOCATION]", a.ToShorterString("Text", "NamedEntityTag"));
            NUnit.Framework.Assert.AreEqual("Incorrect toShorterString()", "[Text=Australia]", a.ToShorterString("Text"));
            NUnit.Framework.Assert.AreEqual("Incorrect toShorterString()", "[Text=Australia NamedEntityTag=LOCATION Before=   PartOfSpeech=NNP Shape=Xx]", a.ToShorterString());
        }
        public virtual void TestCopyConstructor()
        {
            ArrayCoreMap biff = new ArrayCoreMap();

            biff.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            biff.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "B");
            biff.Set(typeof(CoreAnnotations.LemmaAnnotation), "fozzle");
            ArrayCoreMap boff = new ArrayCoreMap(biff);

            NUnit.Framework.Assert.AreEqual(3, boff.Size());
            NUnit.Framework.Assert.AreEqual(biff, boff);
            NUnit.Framework.Assert.AreEqual("fozzle", boff.Get(typeof(CoreAnnotations.LemmaAnnotation)));
        }
        public virtual void TestCoreLabelSetWordBehavior()
        {
            CoreLabel foo = new CoreLabel();

            foo.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            foo.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "B");
            foo.Set(typeof(CoreAnnotations.LemmaAnnotation), "fool");
            // Lemma gets removed with word
            ArrayCoreMap copy = new ArrayCoreMap(foo);

            NUnit.Framework.Assert.AreEqual(copy, foo);
            foo.SetWord("foo");
            NUnit.Framework.Assert.AreEqual(copy, foo);
            // same word set
            foo.SetWord("bar");
            NUnit.Framework.Assert.IsFalse(copy.Equals(foo));
            // lemma removed
            foo.SetWord("foo");
            NUnit.Framework.Assert.IsFalse(copy.Equals(foo));
            // still removed
            foo.Set(typeof(CoreAnnotations.LemmaAnnotation), "fool");
            NUnit.Framework.Assert.AreEqual(copy, foo);
            // back to normal
            // Hash code is consistent
            int hashCode = foo.GetHashCode();

            NUnit.Framework.Assert.AreEqual(copy.GetHashCode(), hashCode);
            foo.SetWord("bar");
            NUnit.Framework.Assert.IsFalse(hashCode == foo.GetHashCode());
            foo.SetWord("foo");
            NUnit.Framework.Assert.IsFalse(hashCode == foo.GetHashCode());
            // Hash code doesn't care between a value of null and the key not existing
            NUnit.Framework.Assert.IsTrue(foo.Lemma() == null);
            int lemmalessHashCode = foo.GetHashCode();

            foo.Remove(typeof(CoreAnnotations.LemmaAnnotation));
            NUnit.Framework.Assert.AreEqual(lemmalessHashCode, foo.GetHashCode());
            foo.SetLemma(null);
            NUnit.Framework.Assert.AreEqual(lemmalessHashCode, foo.GetHashCode());
            foo.SetLemma("fool");
            NUnit.Framework.Assert.AreEqual(hashCode, foo.GetHashCode());
            // Check equals
            foo.SetWord("bar");
            foo.SetWord("foo");
            ArrayCoreMap nulledCopy = new ArrayCoreMap(foo);

            NUnit.Framework.Assert.AreEqual(nulledCopy, foo);
            foo.Remove(typeof(CoreAnnotations.LemmaAnnotation));
            NUnit.Framework.Assert.AreEqual(nulledCopy, foo);
        }
        public virtual void TestRemove()
        {
            ArrayCoreMap foo = new ArrayCoreMap();

            foo.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            foo.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "F");
            NUnit.Framework.Assert.AreEqual("foo", foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual("F", foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            NUnit.Framework.Assert.AreEqual(2, foo.Size());
            foo.Remove(typeof(CoreAnnotations.TextAnnotation));
            NUnit.Framework.Assert.AreEqual(1, foo.Size());
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual("F", foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            foo.Set(typeof(CoreAnnotations.TextAnnotation), "bar");
            NUnit.Framework.Assert.AreEqual("bar", foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual("F", foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            NUnit.Framework.Assert.AreEqual(2, foo.Size());
            foo.Remove(typeof(CoreAnnotations.TextAnnotation));
            NUnit.Framework.Assert.AreEqual(1, foo.Size());
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual("F", foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            foo.Remove(typeof(CoreAnnotations.PartOfSpeechAnnotation));
            NUnit.Framework.Assert.AreEqual(0, foo.Size());
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            // Removing an element that doesn't exist
            // shouldn't blow up on us in any way
            foo.Remove(typeof(CoreAnnotations.PartOfSpeechAnnotation));
            NUnit.Framework.Assert.AreEqual(0, foo.Size());
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            // after removing all sorts of stuff, the original ArrayCoreMap
            // should now be equal to a new empty one
            ArrayCoreMap bar = new ArrayCoreMap();

            NUnit.Framework.Assert.AreEqual(foo, bar);
            foo.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            foo.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "F");
            bar.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            NUnit.Framework.Assert.IsFalse(foo.Equals(bar));
            foo.Remove(typeof(CoreAnnotations.PartOfSpeechAnnotation));
            NUnit.Framework.Assert.AreEqual(foo, bar);
            NUnit.Framework.Assert.AreEqual(1, foo.Size());
            foo.Remove(typeof(CoreAnnotations.PartOfSpeechAnnotation));
            NUnit.Framework.Assert.AreEqual(1, foo.Size());
            NUnit.Framework.Assert.AreEqual("foo", foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
        }
示例#11
0
        /// <summary>
        /// Creates an instance by copying values from the given other CoreMap,
        /// using the values it associates with the given set of hashkeys for
        /// the immutable, hashable keys used by hashcode and equals.
        /// </summary>
        public HashableCoreMap(ArrayCoreMap other, ICollection <Type> hashkey)
            : base(other)
        {
            int keyHashcode   = 0;
            int valueHashcode = 0;

            foreach (Type key in hashkey)
            {
                // NB it is important to compose these hashcodes in an order-independent
                // way, so we just add them all here.
                keyHashcode   += key.GetHashCode();
                valueHashcode += base.Get((Type)key).GetHashCode();
            }
            this.immutableKeys = hashkey;
            this.hashcode      = keyHashcode * 31 + valueHashcode;
        }
        public virtual void TestNoHanging()
        {
            ArrayCoreMap     foo        = new ArrayCoreMap();
            IList <ICoreMap> paragraphs = new List <ICoreMap>();
            ArrayCoreMap     f1         = new ArrayCoreMap();

            f1.Set(typeof(CoreAnnotations.TextAnnotation), "f");
            paragraphs.Add(f1);
            ArrayCoreMap f2 = new ArrayCoreMap();

            f2.Set(typeof(CoreAnnotations.TextAnnotation), "o");
            paragraphs.Add(f2);
            foo.Set(typeof(CoreAnnotations.ParagraphsAnnotation), paragraphs);
            foo.ToString();
            foo.GetHashCode();
        }
        public virtual void TestEquality()
        {
            ICoreMap a = new ArrayCoreMap();
            ICoreMap b = new ArrayCoreMap();

            NUnit.Framework.Assert.IsTrue(a.Equals(b));
            NUnit.Framework.Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
            a.Set(typeof(CoreMapTest.StringA), "hi");
            NUnit.Framework.Assert.IsFalse(a.Equals(b));
            NUnit.Framework.Assert.IsFalse(a.GetHashCode() == b.GetHashCode());
            b.Set(typeof(CoreMapTest.StringA), "hi");
            NUnit.Framework.Assert.IsTrue(a.Equals(b));
            NUnit.Framework.Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
            a.Remove(typeof(CoreMapTest.StringA));
            NUnit.Framework.Assert.IsFalse(a.Equals(b));
            NUnit.Framework.Assert.IsFalse(a.GetHashCode() == b.GetHashCode());
        }
示例#14
0
        // static stuff
        /// <summary>
        /// Merge one CoreMap into another -- that is, overwrite and add any keys in
        /// the base CoreMap with those in the one to be merged.
        /// </summary>
        /// <remarks>
        /// Merge one CoreMap into another -- that is, overwrite and add any keys in
        /// the base CoreMap with those in the one to be merged.
        /// This method is functional -- neither of the argument CoreMaps are changed.
        /// </remarks>
        /// <param name="base">The CoreMap to serve as the base (keys in this are lower priority)</param>
        /// <param name="toBeMerged">The CoreMap to merge in (keys in this are higher priority)</param>
        /// <returns>A new CoreMap representing the merge of the two inputs</returns>
        public static ICoreMap Merge(ICoreMap @base, ICoreMap toBeMerged)
        {
            //(variables)
            ICoreMap rtn = new ArrayCoreMap(@base.Size());

            //(copy base)
            foreach (Type key in @base.KeySet())
            {
                rtn.Set(key, @base.Get(key));
            }
            //(merge)
            foreach (Type key_1 in toBeMerged.KeySet())
            {
                rtn.Set(key_1, toBeMerged.Get(key_1));
            }
            //(return)
            return(rtn);
        }
        public virtual void TestObjectLoops()
        {
            ArrayCoreMap foo = new ArrayCoreMap();

            foo.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            foo.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "B");
            IList <ICoreMap> fooParagraph = new List <ICoreMap>();

            fooParagraph.Add(foo);
            ArrayCoreMap f1 = new ArrayCoreMap();

            f1.Set(typeof(CoreAnnotations.ParagraphsAnnotation), fooParagraph);
            IList <ICoreMap> p1 = new List <ICoreMap>();

            p1.Add(f1);
            foo.Set(typeof(CoreAnnotations.ParagraphsAnnotation), p1);
            foo.ToString();
            foo.GetHashCode();
        }
        public virtual void TestSimpleEquals()
        {
            ArrayCoreMap     foo        = new ArrayCoreMap();
            IList <ICoreMap> paragraphs = new List <ICoreMap>();
            ArrayCoreMap     f1         = new ArrayCoreMap();

            f1.Set(typeof(CoreAnnotations.TextAnnotation), "f");
            paragraphs.Add(f1);
            ArrayCoreMap f2 = new ArrayCoreMap();

            f2.Set(typeof(CoreAnnotations.TextAnnotation), "o");
            paragraphs.Add(f2);
            foo.Set(typeof(CoreAnnotations.ParagraphsAnnotation), paragraphs);
            ArrayCoreMap bar = new ArrayCoreMap();

            bar.Set(typeof(CoreAnnotations.ParagraphsAnnotation), paragraphs);
            NUnit.Framework.Assert.AreEqual(foo, bar);
            NUnit.Framework.Assert.AreEqual(bar, foo);
            NUnit.Framework.Assert.IsFalse(foo.Equals(f1));
            NUnit.Framework.Assert.IsFalse(foo.Equals(f2));
            NUnit.Framework.Assert.AreEqual(f1, f1);
            NUnit.Framework.Assert.IsFalse(f1.Equals(f2));
        }
        public virtual void TestCreate()
        {
            ArrayCoreMap foo = new ArrayCoreMap();

            NUnit.Framework.Assert.AreEqual(0, foo.Size());
        }
        /// <summary>
        /// This method is for comparing the speed of the ArrayCoreMap family and
        /// HashMap.
        /// </summary>
        /// <remarks>
        /// This method is for comparing the speed of the ArrayCoreMap family and
        /// HashMap. It tests random access speed for a fixed number of accesses, i,
        /// for both a CoreLabel (can be swapped out for an ArrayCoreMap) and a
        /// HashMap. Switching the order of testing (CoreLabel first or second) shows
        /// that there's a slight advantage to the second loop, especially noticeable
        /// for small i - this is due to some background java funky-ness, so we now
        /// run 50% each way.
        /// </remarks>
        public static void Main(string[] args)
        {
            Type[] allKeys = new Type[] { typeof(CoreAnnotations.TextAnnotation), typeof(CoreAnnotations.LemmaAnnotation), typeof(CoreAnnotations.PartOfSpeechAnnotation), typeof(CoreAnnotations.ShapeAnnotation), typeof(CoreAnnotations.NamedEntityTagAnnotation
                                                                                                                                                                                                                           ), typeof(CoreAnnotations.DocIDAnnotation), typeof(CoreAnnotations.ValueAnnotation), typeof(CoreAnnotations.CategoryAnnotation), typeof(CoreAnnotations.BeforeAnnotation), typeof(CoreAnnotations.AfterAnnotation), typeof(CoreAnnotations.OriginalTextAnnotation
                                                                                                                                                                                                                                                                                                                                                                                                                                                      ), typeof(CoreAnnotations.ArgumentAnnotation), typeof(CoreAnnotations.MarkingAnnotation) };
            // how many iterations
            int    numBurnRounds = 10;
            int    numGoodRounds = 60;
            int    numIterations = 2000000;
            int    maxNumKeys    = 12;
            double gains         = 0.0;

            for (int numKeys = 1; numKeys <= maxNumKeys; numKeys++)
            {
                // the HashMap instance
                Dictionary <string, string> hashmap = new Dictionary <string, string>(numKeys);
                // the CoreMap instance
                ICoreMap coremap = new ArrayCoreMap(numKeys);
                // the set of keys to use
                string[] hashKeys = new string[numKeys];
                Type[]   coreKeys = new Type[numKeys];
                for (int key = 0; key < numKeys; key++)
                {
                    hashKeys[key] = allKeys[key].GetSimpleName();
                    coreKeys[key] = allKeys[key];
                }
                // initialize with default values
                for (int i = 0; i < numKeys; i++)
                {
                    coremap.Set(coreKeys[i], i.ToString());
                    hashmap[hashKeys[i]] = i.ToString();
                }
                System.Diagnostics.Debug.Assert(coremap.Size() == numKeys);
                System.Diagnostics.Debug.Assert(hashmap.Count == numKeys);
                // for storing results
                double[] hashTimings = new double[numGoodRounds];
                double[] coreTimings = new double[numGoodRounds];
                Random   rand        = new Random(0);
                bool     foundEqual  = false;
                for (int round = 0; round < numBurnRounds + numGoodRounds; round++)
                {
                    System.Console.Error.Write(".");
                    if (round % 2 == 0)
                    {
                        // test timings on hashmap first
                        long   hashStart = Runtime.NanoTime();
                        int    length    = hashKeys.Length;
                        string last      = null;
                        for (int i_1 = 0; i_1 < numIterations; i_1++)
                        {
                            int    key_1 = rand.NextInt(length);
                            string val   = hashmap[hashKeys[key_1]];
                            if (val == last)
                            {
                                foundEqual = true;
                            }
                            last = val;
                        }
                        if (round >= numBurnRounds)
                        {
                            hashTimings[round - numBurnRounds] = (Runtime.NanoTime() - hashStart) / 1000000000.0;
                        }
                    }
                    {
                        // test timings on coremap
                        long   coreStart = Runtime.NanoTime();
                        int    length    = coreKeys.Length;
                        string last      = null;
                        for (int i_1 = 0; i_1 < numIterations; i_1++)
                        {
                            int    key_1 = rand.NextInt(length);
                            string val   = coremap.Get(coreKeys[key_1]);
                            if (val == last)
                            {
                                foundEqual = true;
                            }
                            last = val;
                        }
                        if (round >= numBurnRounds)
                        {
                            coreTimings[round - numBurnRounds] = (Runtime.NanoTime() - coreStart) / 1000000000.0;
                        }
                    }
                    if (round % 2 == 1)
                    {
                        // test timings on hashmap second
                        long   hashStart = Runtime.NanoTime();
                        int    length    = hashKeys.Length;
                        string last      = null;
                        for (int i_1 = 0; i_1 < numIterations; i_1++)
                        {
                            int    key_1 = rand.NextInt(length);
                            string val   = hashmap[hashKeys[key_1]];
                            if (val == last)
                            {
                                foundEqual = true;
                            }
                            last = val;
                        }
                        if (round >= numBurnRounds)
                        {
                            hashTimings[round - numBurnRounds] = (Runtime.NanoTime() - hashStart) / 1000000000.0;
                        }
                    }
                }
                if (foundEqual)
                {
                    System.Console.Error.Write(" [found equal]");
                }
                System.Console.Error.WriteLine();
                double       hashMean    = ArrayMath.Mean(hashTimings);
                double       coreMean    = ArrayMath.Mean(coreTimings);
                double       percentDiff = (hashMean - coreMean) / hashMean * 100.0;
                NumberFormat nf          = new DecimalFormat("0.00");
                System.Console.Out.WriteLine("HashMap @ " + numKeys + " keys: " + hashMean + " secs/2million gets");
                System.Console.Out.WriteLine("CoreMap @ " + numKeys + " keys: " + coreMean + " secs/2million gets (" + nf.Format(System.Math.Abs(percentDiff)) + "% " + (percentDiff >= 0.0 ? "faster" : "slower") + ")");
                gains += percentDiff;
            }
            System.Console.Out.WriteLine();
            gains = gains / maxNumKeys;
            System.Console.Out.WriteLine("Average: " + System.Math.Abs(gains) + "% " + (gains >= 0.0 ? "faster" : "slower") + ".");
        }
 public _AbstractSet_162(ArrayCoreMap _enclosing)
 {
     this._enclosing = _enclosing;
 }
        public virtual void TestObjectLoopEquals()
        {
            ArrayCoreMap foo = new ArrayCoreMap();

            foo.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            foo.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "B");
            IList <ICoreMap> fooParagraph = new List <ICoreMap>();

            fooParagraph.Add(foo);
            ArrayCoreMap f1 = new ArrayCoreMap();

            f1.Set(typeof(CoreAnnotations.ParagraphsAnnotation), fooParagraph);
            IList <ICoreMap> p1 = new List <ICoreMap>();

            p1.Add(f1);
            foo.Set(typeof(CoreAnnotations.ParagraphsAnnotation), p1);
            foo.ToString();
            int          fh  = foo.GetHashCode();
            ArrayCoreMap bar = new ArrayCoreMap();

            bar.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            bar.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "B");
            IList <ICoreMap> barParagraph = new List <ICoreMap>();

            barParagraph.Add(bar);
            ArrayCoreMap f2 = new ArrayCoreMap();

            f2.Set(typeof(CoreAnnotations.ParagraphsAnnotation), barParagraph);
            IList <ICoreMap> p2 = new List <ICoreMap>();

            p2.Add(f2);
            bar.Set(typeof(CoreAnnotations.ParagraphsAnnotation), p2);
            bar.ToString();
            int bh = bar.GetHashCode();

            NUnit.Framework.Assert.AreEqual(foo, bar);
            NUnit.Framework.Assert.AreEqual(bar, foo);
            NUnit.Framework.Assert.AreEqual(fh, bh);
            ArrayCoreMap baz = new ArrayCoreMap();

            baz.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            baz.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "B");
            IList <ICoreMap> foobarParagraph = new List <ICoreMap>();

            foobarParagraph.Add(foo);
            foobarParagraph.Add(bar);
            ArrayCoreMap f3 = new ArrayCoreMap();

            f3.Set(typeof(CoreAnnotations.ParagraphsAnnotation), foobarParagraph);
            IList <ICoreMap> p3 = new List <ICoreMap>();

            p3.Add(f3);
            baz.Set(typeof(CoreAnnotations.ParagraphsAnnotation), p3);
            NUnit.Framework.Assert.IsFalse(foo.Equals(baz));
            NUnit.Framework.Assert.IsFalse(baz.Equals(foo));
            ArrayCoreMap biff = new ArrayCoreMap();

            biff.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            biff.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "B");
            IList <ICoreMap> barfooParagraph = new List <ICoreMap>();

            barfooParagraph.Add(foo);
            barfooParagraph.Add(bar);
            ArrayCoreMap f4 = new ArrayCoreMap();

            f4.Set(typeof(CoreAnnotations.ParagraphsAnnotation), barfooParagraph);
            IList <ICoreMap> p4 = new List <ICoreMap>();

            p4.Add(f4);
            biff.Set(typeof(CoreAnnotations.ParagraphsAnnotation), p4);
            NUnit.Framework.Assert.AreEqual(baz, biff);
            barfooParagraph.Clear();
            NUnit.Framework.Assert.IsFalse(baz.Equals(biff));
            barfooParagraph.Add(foo);
            NUnit.Framework.Assert.IsFalse(baz.Equals(biff));
            barfooParagraph.Add(baz);
            NUnit.Framework.Assert.IsFalse(baz.Equals(biff));
            barfooParagraph.Clear();
            NUnit.Framework.Assert.IsFalse(baz.Equals(biff));
            barfooParagraph.Add(foo);
            barfooParagraph.Add(bar);
            NUnit.Framework.Assert.AreEqual(baz, biff);
        }