// ----------------------------------------------------------------------------------------
        /// <!-- 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);
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- 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;
            }
        }
Exemple #3
0
 // --------------------------------------------------------------------------------------
 /// <!-- Init -->
 /// <summary>
 ///
 /// </summary>
 /// <param name="label"></param>
 /// <param name="code"></param>
 /// <param name="path"></param>
 /// <param name="value"></param>
 /// <param name="match"></param>
 private void Init(string label, EndemeProfile path, object value)
 {
     if (value != null && value.GetType().Name == "EndemeObject")
     {
         throw new Exception("You may not put an EndemeObject inside an EndemeObject.");
     }
     Init(label, path, 0.0);
     Item = new EndemeValue(value);
 }
Exemple #4
0
 // --------------------------------------------------------------------------------------
 /// <!-- Init -->
 /// <summary>
 ///
 /// </summary>
 /// <param name="label"></param>
 /// <param name="code"></param>
 /// <param name="endeme"></param>
 /// <param name="match"></param>
 /// <remarks>alpha code</remarks>
 private void Init(string label, EndemeProfile path, double match)
 {
     if (path != null && path.Count == 0)
     {
         Pause();
     }
     ItemProfile = path;
     ItemLabel   = label;
     //if (ItemProfile != null)  ItemProfile.TempMatch.Add(match);
     _value = new List <EndemeValue>(1);
 }
        // ----------------------------------------------------------------------------------------
        /// <!-- ContainsCount -->
        /// <summary>
        ///      Determines the number of segments containing the count of the target endeme
        /// </summary>
        /// <param name="enTarget"></param>
        /// <returns></returns>
        internal int ContainsCount(EndemeProfile profile, Endeme enTarget)
        {
            Endeme enTgt = enTarget;
            int    found = 0;

            for (int j = 0; j < profile.Count; ++j)
            {
                found += profile[j].ItemEndeme.ContainsCount(enTgt);
            }
            return(found);
        }
 // ----------------------------------------------------------------------------------------
 /// <!-- 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);
     }
 }
 // ----------------------------------------------------------------------------------------
 /// <!-- Match -->
 /// <summary>
 ///      Match two profiles, saving the results internally
 /// </summary>
 /// <param name="matchProfile"></param>
 internal void Match(EndemeProfile matchProfile)
 {
     for (int i = 0; i < this.Segment.Count; ++i)
     {
         EndemeSet enSet = this.Segment[i].EnSet;
         if (matchProfile.Contains(enSet))
         {
             EndemeItem segment2 = matchProfile[enSet];
             EndemeItem segment1 = Segment[i];
             segment1.TempMatch = segment1.ItemEndeme.Match(segment2.ItemEndeme, WeightFormula.Refined);
             //TempMatch[i] = segment1.ItemEndeme.Match(segment2.ItemEndeme, WeightFormula.Refined);
         }
     }
 }
        // ----------------------------------------------------------------------------------------
        /// <!-- 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);
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- Copy -->
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public EndemeProfile Copy()
        {
            EndemeProfile profile = new EndemeProfile();

            profile.Operator = this.Operator;
            //profile.TempMatch     = new List<double>(this.TempMatch);
            profile.ParentArray = this.ParentArray;


            profile.Segment = new List <EndemeItem>(this.Segment.Count);
            for (int i = 0; i < Segment.Count; ++i)
            {
                profile.Segment.Add(this.Segment[i].Copy());
            }
            return(profile);
        }
Exemple #10
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);
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- 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);
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- IsSubsetOf -->
        /// <summary>
        ///      Determines whether the input profile is a subset of this profile
        /// </summary>
        /// <param name="profilethis"></param>
        /// <returns></returns>
        public bool IsSubsetOf(EndemeProfile profile)
        {
            Dictionary <EndemeItem, int> index = new Dictionary <EndemeItem, int>(profile.Count);

            for (int i = 0; i < profile.Count; ++i)
            {
                index.Add(profile.Segment[i], i);
            }
            for (int j = 0; j < Segment.Count; ++j)
            {
                if (!index.ContainsKey(Segment[j]))
                {
                    return(false);
                }
            }
            return(true);
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- 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);
        }
Exemple #15
0
 public EndemeObject(string label, EndemeProfile profile, EndemeValue value)
 {
     Init(label, profile, value);
 }
Exemple #16
0
 private void Init(string label, EndemeProfile path, EndemeValue value)
 {
     Init(label, path, 0.0);
     _value_0 = value; //.ToList<EndemeValue>();  // with linq
     //_value = new List<EndemeValue>(value);
 }
Exemple #17
0
 internal void Add(EndemeProfile profile, EndemeValue value)
 {
     RegField.Add(new EndemeObject(value.Label, profile, value));
 }
Exemple #18
0
 private EndemeObject(string label, EndemeProfile profile, EndemeValue[] value)
 {
     Init(label, profile, value);
 }
        }                                                                                                                                                                          // <--+

        public EndemeObject Add(EndemeProfile enProfile, object value, bool rawSource)
        {
            EndemeObject enObj = new EndemeObject("", enProfile, new EndemeValue(value)); Add(enObj); return(enObj);
        }                                                                                                                                                                                          // ---+
 public EndemeObject this[EndemeProfile profile] {
     get { return(GetExactObject(profile)); }
 }