Ejemplo n.º 1
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.ToString();
                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);
        }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
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></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);
                if (enSet != null)
                {
                    if (this.EnRef[enSet.Label] == null)
                    {
                        this.EnRef.Add(enSet);
                    }
                }
            }

            return(item);
        }
Ejemplo n.º 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)
        {
            // --------------------------------------------------------------------------
            //  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)), "");

            enItem.Item = Endeme.Part(2, enItemFormatted);
            return(enItem);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Educe -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="en"></param>
        /// <returns></returns>
        public EndemeItem Educe(string en)
        {
            EndemeItem item = this[en];

            if (item == null)
            {
                this.Add("", Endeme.Part(0, en), Endeme.Part(1, en), null);
                item = this[en];
            }
            return(item);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        private string AsciiItem(EndemeItem item)
        {
            string str = "";

            if (item.Item != null && item.Item.GetType() == typeof(Endeme))
            {
                str = "[" + item.HeaderString() + ((Endeme)item.Item.Value).FullDesignation + "]";
            }
            else
            {
                str = item.ToString();
            }
            return(str);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
         }
     }
 }
Ejemplo n.º 12
0
 //public List<Guid>   this[string lbl] { get { if (_labelIdx.ContainsKey(lbl)) return _labelIdx[lbl]  ; else return null; } } // TODO: need to convert to an EndemeElement list
 public EndemeItem this[string en]
 {
     get { EndemeItem item = GetExactField(en); if (item == null)
           {
               item = SetFieldExactly(en, new EndemeValue(null));
           }
           return(item); }
     set { EndemeItem item = GetExactField(en); if (item == null)
           {
               item = SetFieldExactly(en, value);
           }
           else
           {
               item.Item = value.Item;
           } }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 14
0
        // ----------------------------------------------------------------------------------------
        /// <!-- GetMatchList -->
        /// <summary>
        ///      Orders the list by the sort profile
        /// </summary>
        /// <param name="sortProfile"></param>
        /// <returns></returns>
        public List <IEndemeItem> GetMatchList(string sortProfile)
        {
            List <IEndemeItem> list = new List <IEndemeItem>();

            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);
                list = ListField.OrderBy(item.ItemEndeme).ToList();
            }
            return(list);
        }
Ejemplo n.º 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);                                                                        // |
 }                                                                                        // |
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 19
0
        }                                                                                        // |

        public Guid Add(EndemeItem element)
        {
            return(Add(Guid.NewGuid(), element));
        }                                                                                                                                                                   // <-+--+
Ejemplo n.º 20
0
 public void          Add(EndemeItem item)
 {
     item.TempMatch = 0.0; Segment.Add(item);
 }
Ejemplo n.º 21
0
 // ----------------------------------------------------------------------------------------
 //  Short methods and properties
 // ----------------------------------------------------------------------------------------
 public void          Add(Endeme en)
 {
     EndemeItem item = new EndemeItem(en, ""); item.TempMatch = 0.0; Segment.Add(item);
 }
Ejemplo n.º 22
0
 public EndemeProfile(EndemeItem enItem)
 {
     Init(); Segment.Add(enItem); Operator = '+';
 }
Ejemplo n.º 23
0
 public EndemeItem    Copy(                 )
 {
     EndemeItem item = new EndemeItem(ItemLabel, ItemEndeme.Copy(), _value.ToArray()); item.ItemCode = ItemCode; item.TempMatch = TempMatch; return(item);
 }