Beispiel #1
0
        //Get feature id from feature set by feature string
        //If feature string is not existed in the set, generate a new id and return it
        private long GetId(string key)
        {
            FeatureIdPair pair;
            if (featureset_dict_.TryGetValue(key, out pair) == true)
            {
                return pair.Key;
            }

            return Utils.ERROR_INVALIDATED_FEATURE;
        }
        /// <summary>
        /// Get font at current location.
        /// </summary>
        /// <returns></returns>
        public virtual Font GetFont()
        {
            Font currentFont;

            _fonts.TryGetValue(_index, out currentFont);
            return(currentFont);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            BTreeDictionary <string, string> WordLookup = new BTreeDictionary <string, string>();

            WordLookup.Add("Hello", "Cool World!");
            WordLookup.Add("Hello", "Cooler World!");
            WordLookup.Add("Brown", "Fox!");
            WordLookup.Add("Foo", "Bar");
            string v;

            if (WordLookup.TryGetValue("Foo", out v))
            {
                Console.WriteLine("Foo was found! Value = {0}", v);
            }

            if (WordLookup.MoveFirst())
            {
                Console.WriteLine();
                Console.WriteLine("Words in Lookup:");
                do
                {
                    Console.WriteLine("Key:{0}, Value={1} ", WordLookup.CurrentKey, WordLookup.CurrentValue);
                } while (WordLookup.MoveNext());
            }

            Console.ReadLine();
        }
Beispiel #4
0
        //Regenerate feature id and shrink features with lower frequency
        public void Shrink(EncoderTagger[] xList, int freq)
        {
            var old2new = new BTreeDictionary <long, long>();

            featureLexicalDict.Shrink(freq);
            maxid_ = featureLexicalDict.RegenerateFeatureId(old2new, y_.Count);
            var feature_count = xList.Length;

            //Update feature ids
            Parallel.For(0, feature_count, parallelOption, i =>
            {
                for (var j = 0; j < xList[i].feature_cache_.Count; j++)
                {
                    var newfs     = new List <long>();
                    long rstValue = 0;
                    for (int index = 0; index < xList[i].feature_cache_[j].Length; index++)
                    {
                        var v = xList[i].feature_cache_[j][index];
                        if (old2new.TryGetValue(v, out rstValue) == true)
                        {
                            newfs.Add(rstValue);
                        }
                    }
                    xList[i].feature_cache_[j] = newfs.ToArray();
                }
            });

            Logger.WriteLine("Feature size in total : {0}", maxid_);
        }
Beispiel #5
0
        //Regenerate feature id and shrink features with lower frequency
        public void Shrink(EncoderTagger[] xList, int freq)
        {
            BTreeDictionary<long, long> old2new = new BTreeDictionary<long, long>();
            featureLexicalDict.Shrink(freq);
            maxid_ = featureLexicalDict.RegenerateFeatureId(old2new, y_.Count);
            int feature_count = xList.Length;

            //Update feature ids
#if NO_SUPPORT_PARALLEL_LIB
            for (int i = 0;i < feature_cache_.Count;i++)
#else
            Parallel.For(0, feature_count, parallelOption, i =>
#endif
            {
                for (int j = 0; j < xList[i].feature_cache_.Count; j++)
                {
                    List<long> newfs = new List<long>();
                    long rstValue = 0;
                    foreach (long v in xList[i].feature_cache_[j])
                    {
                        if (old2new.TryGetValue(v, out rstValue) == true)
                        {
                            newfs.Add(rstValue);
                        }
                    }
                    xList[i].feature_cache_[j] = newfs.ToArray();
                }
            }
#if NO_SUPPORT_PARALLEL_LIB
#else
            );
#endif

            Console.WriteLine("Feature size in total : {0}", maxid_);
        }
Beispiel #6
0
 public Block?FindExactBlock(Address address)
 {
     if (blocks.TryGetValue(address, out var b))
     {
         return(b.Block);
     }
     else
     {
         return(null);
     }
 }
Beispiel #7
0
        public double GetAlpha(long index)
        {
            if (alpha_ != null)
            {
                return(alpha_[index]);
            }
            double weight = 0.0f;

            alpha_two_tuples.TryGetValue(index, out weight);

            return(weight);
        }
Beispiel #8
0
        //Regenerate feature id and shrink features with lower frequency
        public void Shrink(EncoderTagger[] xList, int freq)
        {
            var old2new = new BTreeDictionary<long, long>();
            featureLexicalDict.Shrink(freq);
            maxid_ = featureLexicalDict.RegenerateFeatureId(old2new, y_.Count);
            var feature_count = xList.Length;

            //Update feature ids
#if NO_SUPPORT_PARALLEL_LIB
            for (int i = 0;i < feature_cache_.Count;i++)
#else
            Parallel.For(0, feature_count, parallelOption, i =>
#endif
            {
                for (var j = 0; j < xList[i].feature_cache_.Count; j++)
                {
                    var newfs = new List<long>();
                    long rstValue = 0;
                    for (int index = 0; index < xList[i].feature_cache_[j].Length; index++)
                    {
                        var v = xList[i].feature_cache_[j][index];
                        if (old2new.TryGetValue(v, out rstValue) == true)
                        {
                            newfs.Add(rstValue);
                        }
                    }
                    xList[i].feature_cache_[j] = newfs.ToArray();
                }
            }
#if NO_SUPPORT_PARALLEL_LIB
#else
);
#endif

            Console.WriteLine("Feature size in total : {0}", maxid_);
        }
        void SequencedTest(int start, int incr, int stop, string name)
        {
            int          count = Math.Abs(start - stop) / Math.Abs(incr);
            const string myTestValue1 = "T1", myTestValue2 = "t2";
            string       test;

            BTreeDictionary <int, string> data = new BTreeDictionary <int, string>(Comparer);
            Stopwatch time = new Stopwatch();

            time.Start();
            //large order-forward
            for (int i = start; i != stop; i += incr)
            {
                if (!data.TryAdd(i, myTestValue1))
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} insert  {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            for (int i = start; i != stop; i += incr)
            {
                if (!data.TryGetValue(i, out test) || test != myTestValue1)
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} seek    {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            for (int i = start; i != stop; i += incr)
            {
                if (!data.TryUpdate(i, myTestValue2))
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} modify  {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            for (int i = start; i != stop; i += incr)
            {
                if (!data.TryGetValue(i, out test) || test != myTestValue2)
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} seek#2  {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            int tmpCount = 0;

            foreach (KeyValuePair <int, string> tmp in data)
            {
                if (tmp.Value != myTestValue2)
                {
                    throw new ApplicationException();
                }
                else
                {
                    tmpCount++;
                }
            }
            if (tmpCount != count)
            {
                throw new ApplicationException();
            }

            Trace.TraceInformation("{0} foreach {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            for (int i = start; i != stop; i += incr)
            {
                if (!data.Remove(i))
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} delete  {1} in {2}", name, count, time.ElapsedMilliseconds);

            for (int i = start; i != stop; i += incr)
            {
                if (data.TryGetValue(i, out test))
                {
                    throw new ApplicationException();
                }
            }
        }