コード例 #1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- BuildSegment -->
        /// <summary>
        ///      Converts a formatted endeme item string into an endeme item with a string value
        /// </summary>
        /// <param name="enItemFormatted"></param>
        /// <param name="enRef"></param>
        /// <returns></returns>
        public static EndemeItem BuildSegment(string enItemFormatted, EndemeReference enRef, bool rawSource)
        {
            // --------------------------------------------------------------------------
            //  Resolve endeme set
            // --------------------------------------------------------------------------
            string    label = Endeme.Part(0, enItemFormatted);
            EndemeSet enSet = null;

            if (enRef != null)
            {
                enSet = enRef[label];
            }
            if (enSet == null || string.IsNullOrEmpty(enSet.Label))
            {
                enSet = new EndemeSet(label);
            }


            // --------------------------------------------------------------------------
            //  Build endeme item
            // --------------------------------------------------------------------------
            EndemeItem enItem = new EndemeItem(new Endeme(enSet, Endeme.Part(1, enItemFormatted), rawSource), "");

            enItem.Item = Endeme.Part(2, enItemFormatted);
            return(enItem);
        }
コード例 #2
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Add -->
        /// <summary>
        ///      Adds and Endeme Item/value to the list of fields
        /// </summary>
        /// <param name="label"></param>
        /// <param name="enSet"></param>
        /// <param name="endeme"></param>
        /// <param name="value"></param>
        /// <remarks>
        ///      Fills in the endeme set, creates a new endeme item with the value,
        ///      adds it to the list of field values, adds the endeme set to the reference if needed
        /// </remarks>
        /// <returns>sets the guid etc</returns>
        public EndemeItem Add(string label, EndemeSet enSet, Endeme endeme, object value)
        {
            EndemeItem item = null;

            //if (enSet == null)
            //    Pause();
            if (endeme == null)
            {
                return(null);
            }
            else
            {
                if (endeme.EnSet == null)
                {
                    endeme.EnSet = enSet;
                }
                if (endeme.EnSet != enSet)
                {
                    throw new Exception("boom");
                }
                item = new EndemeItem(label, endeme, new EndemeValue(value));
                this.Add(item);  // this sets the Guid
                if (enSet != null)
                {
                    if (this.EnRef[enSet.Label] == null)
                    {
                        this.EnRef.Add(enSet);
                    }
                }
            }

            return(item);
        }
コード例 #3
0
 // ----------------------------------------------------------------------------------------
 /// <!-- GetExactField -->
 /// <summary>
 ///
 /// </summary>
 /// <param name="enSet"></param>
 /// <param name="en"></param>
 /// <returns></returns>
 public EndemeItem GetExactField(EndemeSet enSet, Endeme en)
 {
     if (en == null || enSet == null)
     {
         return(null);
     }
     else
     {
         if (en.EnSet == null)
         {
             en.EnSet = enSet;
         }
         if (en.EnSet != enSet)
         {
             throw new Exception("boom");
         }
         if (!this.ContainsSet(enSet))
         {
             return(null);
         }
         //if (!this.EnRef.ContainsSet(enSet)) return null;
         EndemeItem item = this.ExactlyLike(en);
         return(item);
     }
 }
コード例 #4
0
ファイル: EndemeSet.cs プロジェクト: jonrgroverlib/InfoLib
 // ----------------------------------------------------------------------------------------
 /// <!-- IsEmpty -->
 /// <summary>
 ///
 /// </summary>
 /// <param name="enSet"></param>
 /// <returns></returns>
 public static bool IsEmpty(EndemeSet enSet)
 {
     return(
         enSet == null ||
         string.IsNullOrWhiteSpace(enSet.Label) ||
         enSet._char == null ||
         enSet._char.Count == 0);
 }
コード例 #5
0
 // ----------------------------------------------------------------------------------------
 /// <!-- Init -->
 /// <summary>
 ///      Initializes the endeme list
 /// </summary>
 /// <param name="label"></param>
 /// <param name="set"></param>
 private void Init(string label, EndemeSet set)
 {
     _label    = label;
     _list     = new Dictionary <Guid, EndemeItem>();
     _order    = new List <Guid>();
     _labelIdx = new Dictionary <string, List <Guid> >();
     _enSet    = set;
 }
コード例 #6
0
 public void            SetEnSet(string setLabel, EndemeSet value)
 {
     if (!this.Contains(setLabel))
     {
         Add(value);
     }
     SetRef[setLabel] = value;
 }
コード例 #7
0
 public EndemeItem this[EndemeSet enSet] {
     get { int i = IndexOf(enSet); if (i >= 0)
           {
               return(Segment[i]);
           }
           else
           {
               return(null);
           } }
 }
コード例 #8
0
 public EndemeReference Add(EndemeSet enSet)
 {
     if (!this.Contains(enSet.Label.ToLower()))
     {
         SetRef.Add(enSet.Label.ToLower(), enSet);
     }
     else
     {
         Pause();
     } return(this);
 }
コード例 #9
0
 // ----------------------------------------------------------------------------------------
 /// <!-- ContainsSet -->
 /// <summary>
 ///
 /// </summary>
 /// <param name="enSet"></param>
 /// <returns></returns>
 /// <remarks>alpha code</remarks>
 internal bool ContainsSet(EndemeSet enSet)
 {
     foreach (Guid key in _list.Keys)
     {
         if (enSet == _list[key].ItemEndeme.EnSet)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #10
0
 private int IndexOf(EndemeSet enSet)
 {
     for (int i = 0; i < this.Segment.Count; ++i)
     {
         if (Segment[i].EnSet == enSet)
         {
             return(i);
         }
     }
     return(-1);
 }
コード例 #11
0
        // ----------------------------------------------------------------------------------------
        /// <!-- GetExactField -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="enFormatted"></param>
        /// <returns></returns>
        public EndemeItem GetExactField(string enFormatted)
        {
            string    setLabel = Endeme.Part(0, enFormatted);
            EndemeSet enSet    = this.EnRef[setLabel];

            if (enSet == null || enSet.Count < 1 || string.IsNullOrEmpty(enSet.Label))
            {
                Pause();
            }
            //throw new KeyNotFoundException("Endeme set '"+setLabel+"' not found in endeme reference");
            return(this.GetExactField(enSet, Endeme.Part(1, enFormatted)));
        }
コード例 #12
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Add -->
        /// <summary>
        ///      Adds an Endeme Item/value to the list of fields
        /// </summary>
        /// <param name="label"></param>
        /// <param name="enSet"></param>
        /// <param name="endeme"></param>
        /// <param name="value"></param>
        /// <remarks>gets the endeme set, creates a new endeme, Adds and EndemeItem to the list</remarks>
        public void Add(string label, string enSet, string endeme, string value, bool rawSource)
        {
            EndemeSet endemeSet = this.EnRef[enSet];

            if (endemeSet == null || endemeSet.Count < 1)
            {
                throw new Exception("Please do not use empty/unreferenced endeme sets {" + enSet + "} when storing endeme values.");
            }
            Endeme en = new Endeme(endemeSet, endeme, rawSource);

            this.Add(label, endemeSet, en, value);
        }
コード例 #13
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);
        }
コード例 #14
0
 // ----------------------------------------------------------------------------------------
 /// <!-- 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);
         }
     }
 }
コード例 #15
0
        public EndemeList(string label, EndemeReference enRef, double equalThreshold)
        {
            Init(label, null);
            if (enRef == null)
            {
                throw new Exception("boom");                // EnRef = new EndemeReference();
            }
            else
            {
                this.EnRef = enRef;
            }
            this.EqualityThreshold = equalThreshold;

            this._enSet = enRef.SetRef.FirstOrDefault(x => x.Key != "").Value;
        }
コード例 #16
0
        // ----------------------------------------------------------------------------------------
        /// <!-- SetFieldExactly -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="enSet"></param>
        /// <param name="endeme"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public EndemeItem SetFieldExactly(EndemeSet enSet, Endeme endeme, object value)
        {
            EndemeItem item = null;

            // --------------------------------------------------------------------------
            //  Preprocess the endeme
            // --------------------------------------------------------------------------
            if (endeme == null)
            {
                return(null);
            }
            else
            {
                if (endeme.EnSet == null)
                {
                    endeme.EnSet = enSet;
                }
                if (endeme.EnSet != enSet)
                {
                    throw new Exception("boom");
                }


                // ----------------------------------------------------------------------
                //  Figure out what value to store and where to store the value
                // ----------------------------------------------------------------------
                item = this.ExactlyLike(endeme);
                if (item == null)
                {
                    item = this.Add("", enSet, endeme, EndemeItem.Simple(new EndemeValue(value)));
                }
                else
                {
                    item.Item = EndemeItem.Simple(new EndemeValue(value));
                }


                //string str = AsciiValue;
            }

            return(item);
        }
コード例 #17
0
ファイル: EndemeSet.cs プロジェクト: jonrgroverlib/InfoLib
        // ----------------------------------------------------------------------------------------
        /// <!-- Equals -->
        /// <summary>
        ///      Returns similarity of two sets - same name, same version, same letters, same labels,
        ///      does not check other details
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        /// <remarks>production ready</remarks>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (Object.ReferenceEquals(obj, this))
            {
                return(true);
            }
            if (obj.GetType() != typeof(EndemeSet))
            {
                return(false);
            }
            EndemeSet target = (EndemeSet)obj;


            bool same
                = (this.Label == target.Label) &&
                  (this.Version == target.Version) &&
                  (this.Count == target.Count)
                ;

            if (same)
            {
                foreach (char c in _char.Keys)
                {
                    EndemeCharacteristic cha = this[c];
                    if (cha != target[c])
                    {
                        same = false;
                        break;
                    }
                }
                return(same);
            }
            else
            {
                return(false);
            }
        }
コード例 #18
0
        // ----------------------------------------------------------------------------------------
        /// <!-- SetField -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="key1"></param>
        /// <param name="key2"></param>
        /// <param name="value"></param>
        public void SetField(EndemeSet enSet, Endeme endeme, object value)
        {
            // --------------------------------------------------------------------------
            //  Preprocess the endeme
            // --------------------------------------------------------------------------
            if (endeme == null)
            {
                return;  // storage location not definced
            }
            else
            {
                if (endeme.EnSet == null)
                {
                    endeme.EnSet = enSet;
                }
                if (endeme.EnSet != enSet)
                {
                    throw new Exception("error- storage endeme has wrong endeme set");
                }


                // ----------------------------------------------------------------------
                //  Figure out what value to store and where to store the value
                // ----------------------------------------------------------------------
                EndemeItem item = this.MostLike(endeme);
                if (item == null || item.TempMatch < this.EqualityThreshold)
                {
                    item = this.Add("", enSet, endeme, EndemeItem.Simple(new EndemeValue(value)));
                }
                else
                {
                    item.Item = EndemeItem.Simple(new EndemeValue(value));
                }


                //string str = AsciiValue;
            }
        }
コード例 #19
0
 // ----------------------------------------------------------------------------------------
 //  Constructors
 // ----------------------------------------------------------------------------------------
 public EndemeList(string label, EndemeSet enSet)
 {
     Init(label, enSet);
 }
コード例 #20
0
 public EndemeItem Add(string label, EndemeSet enSet, Endeme endeme, object value, bool rawSource)
 {
     EndemeItem item = Add(label, enSet, endeme, value); item.ItemEndeme.RawSource = rawSource; return(item);
 }
コード例 #21
0
 public bool          Contains(EndemeSet enSet)
 {
     return(IndexOf(enSet) >= 0);
 }
コード例 #22
0
 public bool            Contains(EndemeSet enSet)
 {
     return(SetRef.ContainsValue(enSet));
 }