/// ------------------------------------------------------------------------------------ /// <summary> /// Determines whether the specified rendering can be deleted. /// </summary> /// ------------------------------------------------------------------------------------ public bool CanRenderingBeDeleted(string rendering) { KeyTermRenderingInfo info = RenderingInfo; if (info == null) { return(false); } var normalized = rendering.Normalize(NormalizationForm.FormC); return(info.AddlRenderings.Contains(normalized) && info.PreferredRendering != normalized); }
// --------------------------------------------------------------------------------------------- /// <summary> /// Gather all renderings from the host and from any additions the user(s) might have made. /// Set the best rendering either based on the user's (previous) choice of based on the one that /// occurs most frequently. /// </summary> // --------------------------------------------------------------------------------------------- public void LoadRenderings() { m_allRenderings = new HashSet <string>(); m_bestTranslation = null; int max = -1; Dictionary <string, int> occurrences = new Dictionary <string, int>(); foreach (var termId in m_termSurrogate.BiblicalTermIds) { int value = 4; // First rendering for each term is considered the best, so it counts more. IList <string> renderings = GetTermRenderings(termId); if (renderings == null) { continue; } foreach (string termRendering in renderings.Where(rendering => rendering != null). Select(t => t.Normalize(NormalizationForm.FormC))) { m_allRenderings.Add(termRendering); int num; occurrences.TryGetValue(termRendering, out num); occurrences[termRendering] = num + value; if (num > max) { m_bestTranslation = termRendering; max = num; } value = 1; } } KeyTermRenderingInfo info = RenderingInfo; if (info != null) { m_allRenderings.UnionWith(info.AddlRenderings.Where(r => r != null)); if (!string.IsNullOrEmpty(info.PreferredRendering)) { m_bestTranslation = info.PreferredRendering; } else if (m_bestTranslation == null) { m_bestTranslation = info.AddlRenderings.FirstOrDefault(r => r != null); } } if (m_bestTranslation == null) { m_bestTranslation = string.Empty; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determines whether the specified rendering can be deleted. /// </summary> /// ------------------------------------------------------------------------------------ public void DeleteRendering(string rendering) { rendering = rendering.Normalize(NormalizationForm.FormC); KeyTermRenderingInfo info = RenderingInfo; if (info == null || !info.AddlRenderings.Contains(rendering)) { throw new ArgumentException("Cannot delete non-existent rendering: " + rendering); } if (info.AddlRenderings.Remove(rendering)) { m_allRenderings.Remove(rendering); UpdateRenderingInfoFile(); if (m_bestTranslation == rendering) { m_bestTranslation = null; // New "best" will be re-determined when needed. } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a rendering. /// </summary> /// ------------------------------------------------------------------------------------ public void AddRendering(string rendering) { string normalizedForm = rendering.Normalize(NormalizationForm.FormC); if (Renderings.Contains(normalizedForm)) { throw new ArgumentException(Properties.Resources.kstidRenderingExists); } KeyTermRenderingInfo info = RenderingInfo; if (info == null) { info = new KeyTermRenderingInfo(m_termSurrogate.TermId, BestRendering); m_keyTermRenderingInfo.Add(info); } info.AddlRenderings.Add(rendering); m_allRenderings.Add(normalizedForm); if (m_bestTranslation == string.Empty) { m_bestTranslation = rendering; } UpdateRenderingInfoFile(); }