// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); } }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); } } }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
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; } } }
// ---------------------------------------------------------------------------------------- /// <!-- 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); // | } // |
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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; } }
// ---------------------------------------------------------------------------------------- // Short methods and properties // ---------------------------------------------------------------------------------------- public void ChangeGuid(Guid oldId, Guid newId) { EndemeItem item = _list[oldId]; Remove(oldId); Add(newId, item); }
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); }
public void Add(EndemeItem item) { item.TempMatch = 0.0; Segment.Add(item); }
// ---------------------------------------------------------------------------------------- // Short methods and properties // ---------------------------------------------------------------------------------------- public void Add(Endeme en) { EndemeItem item = new EndemeItem(en, ""); item.TempMatch = 0.0; Segment.Add(item); }
public EndemeProfile(EndemeItem enItem) { Init(); Segment.Add(enItem); Operator = '+'; }
} // | public Guid Add(EndemeItem element) { return(Add(Guid.NewGuid(), element)); } // <-+--+
public EndemeItem Copy( ) { EndemeItem item = new EndemeItem(ItemLabel, ItemEndeme.Copy(), _value.ToArray()); item.ItemCode = ItemCode; item.TempMatch = TempMatch; return(item); }