Exemplo n.º 1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- MostLike -->
        /// <summary>
        ///      Returns the element most similar to the input endeme using the Match algorithm
        /// </summary>
        /// <param name="en"></param>
        /// <returns></returns>
        /// <remarks>beta code - nearly production ready</remarks>
        public EndemeItem MostLike(Endeme en)
        {
            EndemeList orderedList = this.OrderBy(en);

            if (orderedList.Count == 0)
            {
                return(null);
            }
            EndemeItem element = orderedList[orderedList.Count - 1];
            EndemeItem el2     = this[element.ItemKey];

            el2.TempMatch = element.TempMatch;
            return(el2);
        }
Exemplo n.º 2
0
        // ----------------------------------------------------------------------------------------
        /// <!-- CopyAll -->
        /// <summary>
        ///      Makes a copy preserving the keys
        /// </summary>
        /// <returns></returns>
        /// <remarks>beta code - nearly production ready</remarks>
        public EndemeList CopyAll()
        {
            EndemeList list = new EndemeList(Label, this.DefaultEnSet);

            foreach (Guid key in this)
            {
                list.Add(key, this[key].Copy());
            }
            if (!list.Sane)
            {
                throw new NullReferenceException("EndemeList '" + list.Label + "' is insane.");
            }
            return(list);
        }
Exemplo n.º 3
0
 // ----------------------------------------------------------------------------------------
 //  Constructors
 // ----------------------------------------------------------------------------------------
 public EndemeField(string label, EndemeReference enRef, double equalThreshold)
 {
     Label     = label;
     _field    = new EndemeList(label, enRef, equalThreshold);
     _register = new EndemeDefinition(label, enRef);
 }
Exemplo n.º 4
0
        // ----------------------------------------------------------------------------------------
        /// <!-- OrderBy -->
        /// <summary>
        ///      Orders the elements in the list using the 'NewMatch' algorithm (produces a new list)
        /// </summary>
        /// <param name="sortEndeme"></param>
        /// <returns></returns>
        /// <remarks>beta code - nearly production ready</remarks>
        public EndemeList OrderBy(Endeme sortEndeme)
        {
            if (sortEndeme.EnSet == null)
            {
                sortEndeme.EnSet = DefaultEnSet;
            }


            // --------------------------------------------------------------------------
            //  Put the keys in order, preserving the keys
            // --------------------------------------------------------------------------
            EndemeList toOrder = this.CopyAll();

            foreach (Guid key in toOrder)
            {
                toOrder[key].TempMatch = sortEndeme.Match(toOrder[key].ItemEndeme, WeightFormula.Refined);
                // TODO: change this to Match1
            }


            // --------------------------------------------------------------------------
            //  Order the list by match using Linq  TODO: use this!
            // --------------------------------------------------------------------------
            List <Guid> orderedKeys = toOrder._list.OrderBy(x => x.Value.TempMatch).Select(x => x.Key).ToList();


            //// --------------------------------------------------------------------------
            ////  Order the list by match without Linq
            //// --------------------------------------------------------------------------
            //Dictionary<Guid,double> quantRaw = new Dictionary<Guid,double>();
            //for (int i = 0; i < toOrder.Count; ++i)
            //    quantRaw.Add(toOrder[i].ItemKey, toOrder[i].TempMatch);
            //SortedDictionary<Guid,double> raw = new SortedDictionary<Guid,double>(quantRaw);
            //List<Guid> orderedKeys = new List<Guid>();
            //List<double> values = new List<double>(raw.Values);
            //values.Sort();
            //for (int i = 0; i < values.Count; ++i)
            //{
            //    Guid g = Guid.Empty;
            //    foreach (Guid key in raw.Keys)
            //    {
            //        if (raw[key] == values[i] && raw[key] > 0)
            //            g = key;
            //    }
            //    if (g != Guid.Empty)
            //    {
            //        orderedKeys.Add(g);
            //        raw.Remove(g);
            //    }
            //}


            // --------------------------------------------------------------------------
            //  Put the list in order, preserving the keys
            // --------------------------------------------------------------------------
            EndemeList ordered = new EndemeList(Label, toOrder.DefaultEnSet);

            foreach (Guid key in orderedKeys)
            {
                ordered.Add(key, toOrder[key]);
            }

            if (!Sane)
            {
                throw new NullReferenceException("EndemeList '" + Label + "' is insane.");
            }
            return(ordered);
        }