Пример #1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- OrderBy -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="sortprofile"></param>
        /// <returns></returns>
        /// <remarks>alpha code</remarks>
        public EndemeDefinition OrderBy(EndemeProfile sortprofile)
        {
            // --------------------------------------------------------------------------
            //  Put the keys in order, preserving the keys
            // --------------------------------------------------------------------------
            EndemeDefinition toOrder = this.CopyAll();

            foreach (Guid key in toOrder)
            {
                EndemeProfile profile = toOrder[key].ItemProfile;
                toOrder[key].ItemProfile.Match(sortprofile);
            }


            // --------------------------------------------------------------------------
            //  Order the register by match using Linq
            // --------------------------------------------------------------------------
            List <Guid>      orderedKeys = toOrder._list.OrderBy(x => x.Value.TempMatch).Select(x => x.Key).ToList();
            EndemeDefinition ordered     = new EndemeDefinition(Label, EnRef);

            foreach (Guid key in orderedKeys)
            {
                ordered.Add(key, toOrder[key]);
            }
            return(ordered);
        }
Пример #2
0
 // ----------------------------------------------------------------------------------------
 /// <!-- Set -->
 /// <summary>
 ///
 /// </summary>
 /// <param name="enDef"></param>
 public void Set(EndemeDefinition enDef)
 {
     _list     = enDef._list;
     _order    = enDef._order;
     _labelIdx = enDef._labelIdx;
     _codeIdx  = enDef._codeIdx;
     _enRef    = enDef._enRef;
     _label    = enDef._label;
 }
Пример #3
0
 public EndemeObject this[EndemeActuator enAct] {
     get { EndemeDefinition def = By(enAct); if (def.Count > 0)
           {
               return(def[0]);
           }
           else
           {
               return(EndemeObject.Empty);
           } }
 }
Пример #4
0
        // ----------------------------------------------------------------------------------------
        /// <!-- SortedCopy -->
        /// <summary>
        ///      Returns an endeme definition sorted by its object's TempMatch
        /// </summary>
        /// <returns></returns>
        public EndemeDefinition SortedCopy()
        {
            List <KeyValuePair <Guid, EndemeObject> > sorted = _list.OrderByDescending(o => o.Value.TempMatch).ToList();
            EndemeDefinition output = new EndemeDefinition(Label, EnRef);

            for (int i = 0; i < sorted.Count; ++i)
            {
                output.Add(sorted[i].Key, sorted[i].Value);
            }
            return(output);
        }
Пример #5
0
        // ----------------------------------------------------------------------------------------
        /// <!-- PartNotHaving -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="enSet"></param>
        /// <returns></returns>
        internal EndemeDefinition PartNotHaving(EndemeSet enSet)
        {
            EndemeDefinition output = new EndemeDefinition(this.Label, this.EnRef);

            foreach (Guid key in this._order)
            {
                EndemeProfile profile = this[key].ItemProfile;
                if (!profile.Contains(enSet))
                {
                    output.Add(key, _list[key]);
                }
            }
            return(output);
        }
Пример #6
0
        // ----------------------------------------------------------------------------------------
        /// <!-- CopyAll -->
        /// <summary>
        ///      Makes a copy preserving the keys
        /// </summary>
        /// <returns></returns>
        /// <remarks>beta code - nearly production ready</remarks>
        public EndemeDefinition CopyAll()
        {
            EndemeDefinition list = new EndemeDefinition(this.Label);

            foreach (Guid key in this)
            {
                list.Add(key, this[key].Copy_simple());
            }
            if (!list.Sane)
            {
                throw new NullReferenceException("EndemeList '" + list.Label + "' is insane.");
            }
            return(list);
        }
Пример #7
0
        // ----------------------------------------------------------------------------------------
        /// <!-- GetMatchList -->
        /// <summary>
        ///      Orders the list by the sort profile
        /// </summary>
        /// <param name="sortProfile"></param>
        /// <returns></returns>
        public List <IAmAnEndemeItem> GetMatchList(string sortProfile, bool rawSource)
        {
            List <IAmAnEndemeItem> list = new List <IAmAnEndemeItem>();

            if (Regex.IsMatch(sortProfile, "[*!]"))
            {
                EndemeDefinition part = RegField.PartNotHaving(RegField.EnRef["DSVQAHMU"]);
                list = part.OrderBy(new EndemeProfile(sortProfile, RegField.EnRef)).ToList();
            }
            else
            {
                EndemeItem item = EndemeProfile.BuildSegment(sortProfile, ListField.EnRef, rawSource);
                list = ListField.OrderBy(item.ItemEndeme).ToList();
            }
            return(list);
        }
Пример #8
0
        // ----------------------------------------------------------------------------------------
        /// <!-- By -->
        /// <summary>
        ///      Returns a list of endeme objects by one or more of (filter, order, group?)
        /// </summary>
        /// <param name="actuator"></param>
        /// <returns></returns>
        /// <remarks>
        ///      algortihm:
        ///
        ///      - Go through each HasChar factor and look to see if that is covered by the item profile
        ///         - Look to see if each hashchar factor is covered by the item profile
        /// </remarks>
        public EndemeDefinition By(EndemeActuator actuator)
        {
            actuator.InitWeights();

            EndemeDefinition output = new EndemeDefinition(this.Label + "_" + actuator.ToString(), this.EnRef);


            // --------------------------------------------------------------------------
            //  Go through each item and see whether to add it to the out put list
            // --------------------------------------------------------------------------
            foreach (EndemeObject item in _list.Values)
            {
                // ----------------------------------------------------------------------
                //  Check whether the item's profile covers all of the HasChar factors
                // ----------------------------------------------------------------------
                double charMatch = actuator.HasChar.CharMatch(item.ItemProfile);


                double setMatch = actuator.HasSets.SetMatch(item.ItemProfile);


                double orderMatch = actuator.Ordered.OrderMatch(item.ItemProfile);


                // ----------------------------------------------------------------------
                //  Check for (AND) all the defined value factors
                // ----------------------------------------------------------------------
                bool valFound = true;
                if (charMatch > -0.5 && setMatch > -0.5 && orderMatch > -0.5)
                {
                    foreach (ValueFactor val in actuator.HasVals)
                    {
                        valFound &= val.FoundInProfile(item.ItemProfile.Segment);
                    }
                }


                // ----------------------------------------------------------------------
                //  Check for (OR) all the weight factors
                // ----------------------------------------------------------------------
                double weightMatch = 1.0;
                if (charMatch > -0.5 && setMatch > -0.5 && orderMatch > -0.5)
                {
                    foreach (WeightFactor wgt in actuator.Weights)
                    {
                        double factorWeight = wgt.CalculateFactorWeight(item.ItemProfile.Segment);
                        double normalized   = (factorWeight - wgt.WorstMatch) / (wgt.BestMatch - wgt.WorstMatch);
                        weightMatch *= normalized;
                    }
                }


                // ----------------------------------------------------------------------
                //  Add the item if its profile covers all of the defined factor groups
                // ----------------------------------------------------------------------
                if (charMatch > -0.5 && setMatch > -0.5 && orderMatch > -0.5 && valFound)
                {
                    EndemeObject copy = item.Copy();
                    copy.TempMatch = charMatch + weightMatch;
                    output.Add(copy);
                }
            }


            // --------------------------------------------------------------------------
            //  Order output by weight
            // --------------------------------------------------------------------------
            if (output.Count > 1)
            {
                return(output.SortedCopy());
            }
            else
            {
                return(output);
            }
        }
Пример #9
0
 // ----------------------------------------------------------------------------------------
 //  Constructors
 // ----------------------------------------------------------------------------------------
 public EndemeField(string label, EndemeReference enRef, double equalThreshold)
 {
     Label     = label;
     _field    = new EndemeList(label, enRef, equalThreshold);
     _register = new EndemeDefinition(label, enRef);
 }