// ----------------------------------------------------------------------------------------
        /// <!-- InsertRegisterExactly -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="enProfile"></param>
        /// <param name="value"></param>
        public void InsertRegisterExactly(EndemeProfile enProfile, object value)
        {
            // --------------------------------------------------------------------------
            //  Preprocess the endeme
            // --------------------------------------------------------------------------
            if (enProfile == null)
            {
                return; // maybe throw, maybe sliding scale on application
            }
            else
            {
                // ----------------------------------------------------------------------
                //  Figure out what value to store and where to store the value
                // ----------------------------------------------------------------------
                EndemeObject enObject = ExactObject(enProfile);
                if (enObject == null)
                {
                    Add(enProfile, value);
                }
                else
                {
                    enObject.Item = EndemeObject.Simple(new EndemeValue(value));
                }


                //string str = AsciiValue;
            }
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- Copy -->
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public EndemeObject Copy_simple()
        {
            EndemeObject enObj = new EndemeObject(ItemLabel, ItemProfile.Copy(), _value_0.Copy()); //ToArray());

            enObj.Item.Label = ItemLabel;
            enObj.ItemKey    = this.ItemKey;  // should this be copied?
            enObj.TempMatch  = 0.0;
            return(enObj);
        }
        }                                                                                                                                                                          // ---+

        // ----------------------------------------------------------------------------------------
        /// <!-- AddToIndex -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="element"></param>
        /// <remarks>beta code - nearly production ready</remarks>
        private void AddToIndex(Guid guid, EndemeObject element)
        {
            string label = element.ItemLabel;

            if (!_labelIdx.ContainsKey(label))
            {
                _labelIdx.Add(label, new List <Guid>());
            }
            _labelIdx[label].Add(guid);
        }
 // ----------------------------------------------------------------------------------------
 /// <!-- Add -->
 /// <summary>
 ///      Adds an element to the EndemeArray
 /// </summary>
 /// <param name="guid"></param>
 /// <param name="element"></param>
 /// <returns>
 ///      Probably ought to return the element not just the Guid since the Element contains the Guid
 /// </returns>
 /// <remarks>beta code - nearly production ready</remarks>
 public Guid Add(Guid guid, EndemeObject element) // <------------------------------------+
 {                                                // |
     element.ItemKey = guid;                      // |
     _list.Add(guid, element);                    // |
     _order.Add(guid);                            // |
     if (_enRef == null && element.EnRef != null)
     {
         _enRef = element.EnRef;                                                       // |  warning: side effect
     }
     return(guid);                                                                     // |
 }                                                                                     // |
Example #5
0
 public void SetValue(string profile, EndemeValue value)
 {
     if (Regex.IsMatch(profile, "[*!]"))
     {
         EndemeObject enObj = RegField.Educe(profile);
         enObj.Item = value;
     }
     else
     {
         ListField.Educe(profile).Item = value;
     }
 }
 // ----------------------------------------------------------------------------------------
 /// <!-- GetSubsetObject -->
 /// <summary>
 ///
 /// </summary>
 /// <param name="enProfile"></param>
 /// <returns></returns>
 public EndemeObject GetSubsetObject(EndemeProfile enProfile)
 {
     if (enProfile == null || enProfile.Count == 0)
     {
         return(null);
     }
     else
     {
         EndemeObject enObject = SubsetObject(enProfile);
         return(enObject);
     }
 }
 public EndemeObject this[string profile]
 {
     get { return(GetExactObject(profile)); }
     set { EndemeObject obj = GetExactObject(profile); if (obj == null)
           {
               InsertRegisterExactly(profile, value);
           }
           else
           {
               obj.Item = value.Item;
           } }
 }
        // ----------------------------------------------------------------------------------------
        /// <!-- Insert -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="ord"></param>
        /// <param name="element"></param>
        /// <returns></returns>
        /// <remarks>beta code - nearly production ready</remarks>
        public EndemeObject Insert(int ord, EndemeObject element)
        {
            Guid guid = Guid.NewGuid();

            _list.Add(guid, element);
            _order.Insert(ord, guid);
            AddToIndex(guid, element);

            if (!Sane)
            {
                throw new NullReferenceException("EndemeList '" + Label + "' is insane.");
            }
            return(element);
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- Educe -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        public EndemeObject Educe(string profile)
        {
            EndemeProfile enProfile = new EndemeProfile(profile, _enRef);

            for (int i = 0; i < enProfile.Count; ++i)
            {
                _enRef.Educe(enProfile[i].ItemEndeme);
            }
            EndemeObject enObject = this[enProfile];

            if (enObject == null)
            {
                enObject = this.Add(enProfile, null);
            }
            return(enObject);
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- SubsetObject -->
        /// <summary>
        ///      Returns an endeme object only if it has exactly the same endeme
        /// </summary>
        /// <param name="en"></param>
        /// <returns></returns>
        public EndemeObject SubsetObject(EndemeProfile enProfile)
        {
            int          count    = 0;
            EndemeObject enObject = null;

            for (int i = 0; i < this.Count; ++i)
            {
                EndemeProfile myProfile = this[i].ItemProfile;
                if (enProfile.IsSubsetOf(myProfile))
                {
                    count++;
                    enObject = this[i];
                }
            }
            if (count > 1)
            {
                throw new Exception("boom");
            }
            return(enObject);
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- ExactObject -->
        /// <summary>
        ///      Returns an endeme object only if it has exactly the same endeme
        /// </summary>
        /// <param name="en"></param>
        /// <returns></returns>
        public EndemeObject ExactObject(EndemeProfile enProfile)
        {
            int          count    = 0;
            EndemeObject enObject = EndemeObject.Empty;

            for (int i = 0; i < this.Count; ++i)
            {
                EndemeProfile myProfile = this[i].ItemProfile;
                if (enProfile == myProfile)
                {
                    count++;
                    enObject = this[i];
                }
            }
            if (count > 1)
            {
                throw new Exception("boom");
            }
            return(enObject);
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- 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.Sort());
            }
            else
            {
                return(output);
            }
        }
        }                                                                                                                                                                          // <--+

        public EndemeObject Add(EndemeProfile enProfile, object value)
        {
            EndemeObject enObj = new EndemeObject("", enProfile, new EndemeValue(value)); Add(enObj); return(enObj);
        }                                                                                                                                                                          // ---+
        }                                                                                     // |

        public Guid         Add(EndemeObject element)
        {
            return(Add(Guid.NewGuid(), element));
        }                                                                                                                                                                          // <--+