// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); } }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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; }
public void SetEnSet(string setLabel, EndemeSet value) { if (!this.Contains(setLabel)) { Add(value); } SetRef[setLabel] = value; }
public EndemeItem this[EndemeSet enSet] { get { int i = IndexOf(enSet); if (i >= 0) { return(Segment[i]); } else { return(null); } } }
public EndemeReference Add(EndemeSet enSet) { if (!this.Contains(enSet.Label.ToLower())) { SetRef.Add(enSet.Label.ToLower(), enSet); } else { Pause(); } return(this); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
private int IndexOf(EndemeSet enSet) { for (int i = 0; i < this.Segment.Count; ++i) { if (Segment[i].EnSet == enSet) { return(i); } } return(-1); }
// ---------------------------------------------------------------------------------------- /// <!-- 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))); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); } } }
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; }
// ---------------------------------------------------------------------------------------- /// <!-- 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); }
// ---------------------------------------------------------------------------------------- /// <!-- 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); } }
// ---------------------------------------------------------------------------------------- /// <!-- 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; } }
// ---------------------------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------------------------- public EndemeList(string label, EndemeSet enSet) { Init(label, enSet); }
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 bool Contains(EndemeSet enSet) { return(IndexOf(enSet) >= 0); }
public bool Contains(EndemeSet enSet) { return(SetRef.ContainsValue(enSet)); }