Пример #1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- AsciiItem -->
        /// <summary>
        ///      An item for the AsciiValue list
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        private string AsciiItem(int i)
        {
            EndemeItem item = this[i];


            string str = "";

            if (string.IsNullOrWhiteSpace(Label))
            {
                str = "this[" + i + "]";
            }
            else
            {
                str = Label + "[" + i + "]";
            }


            str += " = ";


            if (item.Item != null && item.Item.GetType() == typeof(Endeme))
            {
                str += item.ToProfileString() + ((Endeme)item.Item.Value).FullDesignation;
            }
            else
            {
                str += item.ToString();
            }
            return(str);
        }
Пример #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
        // ----------------------------------------------------------------------------------------
        /// <!-- UniquenessTest -->
        /// <summary>
        ///      Determines whether all elements have unique endemes
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        ///      TODO: add in the possibility that there may be more than one endeme set
        ///      alpha code
        /// </remarks>
        public bool UniquenessTest()
        {
            Dictionary <string, int> tally = new Dictionary <string, int>(_list.Count);

            for (int i = 0; i < _order.Count; ++i)
            {
                EndemeItem en  = this[i];
                string     key = en.ItemEndeme;
                if (!tally.ContainsKey(key))
                {
                    tally.Add(key, 0);
                }
                tally[key]++;
            }

            if (tally.Count > _labelIdx.Count)
            {
                throw new ApplicationException("Missing item in endeme list index");
            }
            if (tally.Count < _labelIdx.Count)
            {
                throw new ApplicationException("Extra item in endeme list index");
            }

            return(_labelIdx.Count == _list.Count);
        }
Пример #4
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);
        }
Пример #5
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);
     }
 }
Пример #6
0
        // ----------------------------------------------------------------------------------------
        /// <!-- AddToIndex -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="element"></param>
        /// <remarks>beta code - nearly production ready</remarks>
        private void AddToIndex(Guid guid, EndemeItem element)
        {
            string label = element.ItemLabel;

            if (!_labelIdx.ContainsKey(label))
            {
                _labelIdx.Add(label, new List <Guid>());
            }
            _labelIdx[label].Add(guid);
        }
Пример #7
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Educe -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="enTK"></param>
        /// <returns></returns>
        public EndemeItem Educe(EndemeTermKey enTK, bool rawSource)
        {
            EndemeItem item = this[enTK];

            if (item == null)
            {
                this.Add("", Endeme.Part(0, enTK), Endeme.Part(1, enTK), null, rawSource);
                item = this[enTK];
            }
            return(item);
        }
Пример #8
0
        // ----------------------------------------------------------------------------------------
        /// <!-- SetFieldExactly -->
        /// <summary>
        ///      This can't be public because EndemeField knows nothing about existing endeme sets
        /// </summary>
        /// <param name="enFormatted"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public EndemeItem SetFieldExactly(string enFormatted, object value)
        {
            string setLabel = Endeme.Part(0, enFormatted);
            string enString = Endeme.Part(1, enFormatted);

            if (this.EnRef[setLabel] == null)
            {
                Pause();
            }
            EndemeItem item = this.SetFieldExactly(this.EnRef[setLabel], enString, value);

            return(item);
        }
Пример #9
0
        // ----------------------------------------------------------------------------------------
        /// <!-- MostLike -->
        /// <summary>
        ///      Returns the element most similar to the input endeme using the Match algorithm
        /// </summary>
        /// <param name="en"></param>
        /// <returns></returns>
        /// <remarks>beta code - nearly production ready</remarks>
        public EndemeItem MostLike(Endeme en)
        {
            EndemeList orderedList = this.OrderBy(en);

            if (orderedList.Count == 0)
            {
                return(null);
            }
            EndemeItem element = orderedList[orderedList.Count - 1];
            EndemeItem el2     = this[element.ItemKey];

            el2.TempMatch = element.TempMatch;
            return(el2);
        }
Пример #10
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);
         }
     }
 }
Пример #11
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Insert -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="ord"></param>
        /// <param name="element"></param>
        /// <returns></returns>
        /// <remarks>beta code - nearly production ready</remarks>
        public EndemeItem Insert(int ord, EndemeItem 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);
        }
Пример #12
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);
        }
Пример #13
0
        // ----------------------------------------------------------------------------------------
        /// <!-- GetFromCode -->
        /// <summary>
        ///      This is jsut a stopgap for now, it needs an index to run fast
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        /// <remarks>TODO: fix me, need to build a code index or something</remarks>
        public List <EndemeItem> GetFromCode(string code)
        {
            List <EndemeItem> list = new List <EndemeItem>();

            foreach (EndemeItem el in _list.Values)
            {
                EndemeItem found = EndemeItem.Empty;
                if (el.ItemCode == code)
                {
                    found = el;
                    list.Add(found);
                }
            }

            return(list);
        }
Пример #14
0
 public EndemeItem this[EndemeTermKey enTerm]
 {
     get { EndemeItem item = GetExactField(enTerm); if (item == null)
           {
               item = SetFieldExactly(enTerm, new EndemeValue(null));
           }
           return(item); }
     set { EndemeItem item = GetExactField(enTerm); if (item == null)
           {
               item = SetFieldExactly(enTerm, value);
           }
           else
           {
               item.Item = value.Item;
           } }
 }
Пример #15
0
 // ----------------------------------------------------------------------------------------
 /// <!-- Add -->
 /// <summary>
 ///      Adds an element to the EndemeList
 /// </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, EndemeItem element)   // <---------------------------------------+
 {                                                // |
     element.ItemKey = guid;                      // |
     _list.Add(guid, element);                    // |
     _order.Add(guid);                            // |
     AddToIndex(guid, element);                   // |
     if (element.ItemEndeme.EnSet == null)
     {
         element.EnSet = DefaultEnSet;                                                    // |
     }
     // |
     if (!Sane)
     {
         throw new NullReferenceException("EndemeList '" + Label + "' is insane.");       // |
     }
     return(guid);                                                                        // |
 }                                                                                        // |
Пример #16
0
        // ----------------------------------------------------------------------------------------
        /// <!-- ExactlyLike -->
        /// <summary>
        ///      Returns an item only if it has exactly the same endeme
        /// </summary>
        /// <param name="en"></param>
        /// <returns></returns>
        public EndemeItem ExactlyLike(Endeme en)
        {
            int        count = 0;
            EndemeItem item  = null;

            for (int i = 0; i < this.Count; ++i)
            {
                if (this[i].ItemEndeme == en)
                {
                    count++;
                    item = this[i];
                }
            }
            if (count > 1)
            {
                throw new Exception("boom");
            }
            return(item);
        }
Пример #17
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);
        }
Пример #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
 // ----------------------------------------------------------------------------------------
 //  Short methods and properties
 // ----------------------------------------------------------------------------------------
 public void              ChangeGuid(Guid oldId, Guid newId)
 {
     EndemeItem item = _list[oldId]; Remove(oldId); Add(newId, item);
 }
Пример #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 void          Add(EndemeItem item)
 {
     item.TempMatch = 0.0; Segment.Add(item);
 }
Пример #22
0
 // ----------------------------------------------------------------------------------------
 //  Short methods and properties
 // ----------------------------------------------------------------------------------------
 public void          Add(Endeme en)
 {
     EndemeItem item = new EndemeItem(en, ""); item.TempMatch = 0.0; Segment.Add(item);
 }
Пример #23
0
 public EndemeProfile(EndemeItem enItem)
 {
     Init(); Segment.Add(enItem); Operator = '+';
 }
Пример #24
0
        }                                                                                        // |

        public Guid Add(EndemeItem element)
        {
            return(Add(Guid.NewGuid(), element));
        }                                                                                                                                                                                      // <-+--+
Пример #25
0
 public EndemeItem    Copy(                 )
 {
     EndemeItem item = new EndemeItem(ItemLabel, ItemEndeme.Copy(), _value.ToArray()); item.ItemCode = ItemCode; item.TempMatch = TempMatch; return(item);
 }