예제 #1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- InsertRegisterExactly -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="enProfile"></param>
        /// <param name="value"></param>
        public void InsertRegisterExactly(EndemeProfile enProfile, object value, bool rawSource)
        {
            // --------------------------------------------------------------------------
            //  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, rawSource);
                }
                else
                {
                    enObject.Item = EndemeObject.Simple(new EndemeValue(value));
                }


                //string str = AsciiValue;
            }
        }
예제 #2
0
        // ----------------------------------------------------------------------------------------
        /// <!-- 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);
        }
예제 #3
0
        }                                                                                                                                                                                          // ---+

        // ----------------------------------------------------------------------------------------
        /// <!-- 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);
        }
예제 #4
0
 // ----------------------------------------------------------------------------------------
 /// <!-- 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);                                                                     // |
 }                                                                                     // |
예제 #5
0
 // ----------------------------------------------------------------------------------------
 /// <!-- 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);
     }
 }
예제 #6
0
 public EndemeObject this[string profile]
 {
     get { return(GetExactObject(profile)); }
     set { EndemeObject obj = GetExactObject(profile); if (obj == null)
           {
               InsertRegisterExactly(profile, value, true);
           }
           else
           {
               obj.Item = value.Item;
           } }
 }
예제 #7
0
 public void SetValue(EndemeTermKey profile, EndemeValue value, bool rawSource)
 {
     if (Regex.IsMatch(profile.ToString(), "[*!]"))
     {
         EndemeObject enObj = RegField.Educe(profile, rawSource);
         enObj.Item = value;
     }
     else
     {
         ListField.Educe(profile, rawSource).Item = value;
     }
 }
예제 #8
0
        // ----------------------------------------------------------------------------------------
        /// <!-- 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);
        }
예제 #9
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Educe -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        public EndemeObject Educe(EndemeTermKey profile, bool rawSource)
        {
            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, rawSource);
            }
            return(enObject);
        }
예제 #10
0
        // ----------------------------------------------------------------------------------------
        /// <!-- 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);
        }
예제 #11
0
        // ----------------------------------------------------------------------------------------
        /// <!-- 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);
        }
예제 #12
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);
            }
        }
예제 #13
0
        }                                                                                                                                                                          // <--+

        public EndemeObject Add(EndemeProfile enProfile, object value, bool rawSource)
        {
            EndemeObject enObj = new EndemeObject("", enProfile, new EndemeValue(value)); Add(enObj); return(enObj);
        }                                                                                                                                                                                          // ---+
예제 #14
0
        }                                                                                     // |

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