public void FindNextMatch_RequireNormalization() { IWritingSystem ws; Cache.ServiceLocator.WritingSystemManager.GetOrSet("grc", out ws); int wsGreek = ws.Handle; TreeNode catNode = new TreeNode("Proper Names"); m_treeView.Nodes.Add(catNode); TreeNode chkTermNode = new TreeNode("Abraham"); ICmPossibilityList list = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create(); Cache.LanguageProject.CheckListsOC.Add(list); IChkTerm term = Cache.ServiceLocator.GetInstance <IChkTermFactory>().Create(); list.PossibilitiesOS.Add(term); ITsString tssName = Cache.TsStrFactory.MakeString("Abraham".Normalize(NormalizationForm.FormD), Cache.DefaultUserWs); const string abrahamGrk = "\u1F08\u03B2\u03C1\u03B1\u1F71\u03BC"; ITsString tssDesc = Cache.TsStrFactory.MakeString(abrahamGrk.Normalize(NormalizationForm.FormD), wsGreek); ITsString tssSeeAlso = Cache.TsStrFactory.MakeString("", Cache.DefaultUserWs); term.Name.set_String(Cache.DefaultUserWs, tssName); term.Description.set_String(wsGreek, tssDesc); term.SeeAlso.set_String(Cache.DefaultUserWs, tssName); chkTermNode.Tag = term; catNode.Nodes.Add(chkTermNode); m_treeView.SelectedNode = catNode; Assert.AreEqual(KeyTermsTree.FindResult.MatchFound, m_treeView.CallFindNextMatch(abrahamGrk.Normalize(NormalizationForm.FormC))); Assert.AreEqual("Abraham", m_treeView.SelectedNode.Text); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds Gloss, Definition and SeeAlso info to a Check Term for the given writing system /// </summary> /// <param name="term">The ChkTerm</param> /// <param name="hvoWs">The HVO of the writing system.</param> /// <param name="gloss">The primary gloss.</param> /// <param name="description">The description.</param> /// <param name="seeAlso">Alternate glosses, separated by semi-colons.</param> /// ------------------------------------------------------------------------------------ private void SetLocalizedInfo(IChkTerm term, int hvoWs, string gloss, string description, string seeAlso) { term.Name.set_String(hvoWs, gloss); term.Description.set_String(hvoWs, description); term.SeeAlso.set_String(hvoWs, seeAlso); }
private bool ShouldAddLeafNode(ICmPossibility keyTerm, IFdoOwningSequence <ICmPossibility> subKeyTerms) { // if we have a book filter and the keyterm doesn't have subpossibilities (ie. it's a leaf node) // make sure this key term has an occurrence in the books specified by the book filter. if (subKeyTerms.Count == 0) { if (HasBookFilter) { IChkTerm chkTerm = (IChkTerm)keyTerm; foreach (IChkRef chkRef in chkTerm.OccurrencesOS) { int bookIdOfOccurrence = ScrReference.GetBookFromBcv(chkRef.Ref); if (FilteredBookIds.Contains(bookIdOfOccurrence)) { // the reference is in one of our filtered books // so add its key term to our tree. return(true); } } } else { // no book filter to apply, so add all the key terms. return(true); } } else { // return false. not a leaf-node. } return(false); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Fill in a keyterm node in the database from a Term /// </summary> /// <param name="owner">CmPossibility that is above the term in the hierarchy (probably /// a category)</param> /// <param name="term">Term to get info from</param> /// <param name="localizations">The localizations.</param> /// ------------------------------------------------------------------------------------ private void AddTerm(ICmPossibility owner, Term term, IEnumerable <BiblicalTermsLocalization> localizations) { int hvoWs = (term.Language == "Hebrew") ? m_wsHebrew : m_wsGreek; // Strip off any sense numbers string lemma = term.Lemma.TrimEnd( '-', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'); IChkTerm newTerm = CreateChkTerm(term.Id, hvoWs, lemma, term.Including, owner); Debug.Assert(newTerm != null); foreach (BiblicalTermsLocalization loc in localizations) { TermLocalization termLoc = loc.FindTerm(term.Id); if (termLoc != null) { // First "gloss" is the primary one and will become the name of the // possibility. Susequent glosses will be stored in the SeeAlso field. SetLocalizedGlossAndDescription(newTerm, termLoc, loc.WritingSystemHvo); } } // If there are references on this node then add them to the keyterm node AddRefsToKeyTerm(term.Id, newTerm, hvoWs, term.References, term.Form ?? lemma); }
//#region Public methods ///// ------------------------------------------------------------------------------------ ///// <summary> ///// Adds the specified renderings. ///// </summary> ///// <param name="termRenderings">The collection of references that correspond to the ///// biblical terms that have vernacular renderings.</param> ///// ------------------------------------------------------------------------------------ //public void Add(IEnumerable<IChkRef> termRenderings) //{ // foreach (IChkRef rendering in termRenderings) // Renderings.Add(new XmlTermRendering(rendering)); //} //#endregion #region Methods to write annotations to cache /// ------------------------------------------------------------------------------------ /// <summary> /// Writes the list of renderings to the specified cache. /// </summary> /// <param name="lp">The language project.</param> /// <param name="termsListVersionsMatch">flag indicating whether the term list versions /// in the project is the same as the term list version used by the XML data that was /// read.</param> /// <param name="ResolveConflict">The delegate to call to resolve a conflict when a /// different rendering already exists.</param> /// ------------------------------------------------------------------------------------ internal void WriteToCache(ILangProject lp, bool termsListVersionsMatch, Func <IChkRef, string, string, bool> ResolveConflict) { m_term = FindTerm(lp, termsListVersionsMatch); foreach (XmlTermRendering rendering in Renderings) { rendering.WriteToCache(m_term, ResolveConflict); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a ChkRef object /// </summary> /// <param name="term">The ChkTerm that will own the ChkRef</param> /// <param name="hvoWs">The HVO of the original-language writing system.</param> /// <param name="keyword">The specific Greek or Hebrew word(s) in the original text, /// though not necessarily the surface (i.e., inflected) form.</param> /// <param name="reference">Scripture reference in BBCCCVVV format</param> /// <param name="location">The 1-based index of the word in the verse in the original /// language</param> /// ------------------------------------------------------------------------------------ private void CreateChkRef(IChkTerm term, int hvoWs, string keyword, int reference, int location) { IChkRef newRef = m_servLoc.GetInstance <IChkRefFactory>().Create(); term.OccurrencesOS.Add(newRef); newRef.Ref = reference; newRef.KeyWord = m_scr.Cache.TsStrFactory.MakeString(keyword, hvoWs); newRef.Location = location; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Build a list of the KeyTermRef objects that will be displayed in the key terms /// rendering grid. /// </summary> /// <param name="chkTerm">The term node to get references for. This could be the /// category node, in which case we just clear the list.</param> /// <param name="filteredBookIds">list of book ids that are in the current filter. /// If null, then filtering is not on and all references should be included</param> /// ------------------------------------------------------------------------------------ public void LoadRenderingsForKeyTerm(IChkTerm chkTerm, List <int> filteredBookIds) { m_dataGridView.RowEnter -= m_dataGridView_RowEnter; m_dataGridView.RowCount = 0; m_list.Clear(); PopulateKeyTermRefs(chkTerm, filteredBookIds); if (m_stylesheet != null) { if (!String.IsNullOrEmpty(chkTerm.Name.get_String(m_wsGreek).Text)) { m_OriginalTerm.WritingSystemCode = m_wsGreek; } else if (!String.IsNullOrEmpty(chkTerm.Name.get_String(m_wsHebrew).Text)) { m_OriginalTerm.WritingSystemCode = m_wsHebrew; } else { throw new ArgumentException("Unexpected biblical term - no Greek or Hebrew Name. Term id = " + chkTerm); } if (m_OriginalTerm.Font != null) { m_OriginalTerm.Font.Dispose(); } m_OriginalTerm.Font = m_stylesheet.GetUiFontForWritingSystem( m_OriginalTerm.WritingSystemCode, m_OriginalTerm.SizeOfFontAt100Percent * ZoomFactor); } m_dataGridView.RowCount = m_list.Count; m_dataGridView.KeyTermRefs = m_list; m_dataGridView.RowEnter += m_dataGridView_RowEnter; Sort(m_sortedColumn, false, kRefCol); m_prevResultRow = -1; if (m_firstLoad && m_persistence != null) { OnLoadSettings(m_persistence.SettingsKey); } m_firstLoad = false; if (m_dataGridView.RowCount == 0) { if (ReferenceListEmptied != null) { ReferenceListEmptied(this, EventArgs.Empty); } } else { OnReferenceChanged(0); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add references to a sense or keyterm node in the database from XML data. /// </summary> /// <param name="termId">The term ID.</param> /// <param name="term">The ChkTerm</param> /// <param name="hvoWs">The HVO of the original-language writing system.</param> /// <param name="references">List of long integers representing BBCCCVVV references plus /// two digits indicating the number of the word in the verse in the original text</param> /// <param name="keyword">The specific Greek or Hebrew word(s) in the original text, /// though not necessarily the surface (i.e., inflected) form.</param> /// ------------------------------------------------------------------------------------ private void AddRefsToKeyTerm(int termId, IChkTerm term, int hvoWs, List <long> references, string keyword) { // Get all of the ref items from the sense node foreach (long reference in references) { int scrRef = (int)(reference / 100); // Get rid of last two digits int location = (int)(reference % 100); CreateChkRef(term, hvoWs, keyword, scrRef, location); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="XmlTerm"/> class based on the given /// collection of Scripture notes. /// </summary> /// <param name="term">The key term.</param> /// ------------------------------------------------------------------------------------ public XmlTerm(IChkTerm term) { m_term = term; TermIdNum = term.TermId; KeyWord = new XmlKeyWord(term); foreach (IChkRef occurrence in term.OccurrencesOS.Where(o => o.Status != KeyTermRenderingStatus.AutoAssigned && o.Status != KeyTermRenderingStatus.Unassigned)) { Renderings.Add(new XmlTermRendering(occurrence)); } Debug.Assert(Renderings.Count > 0); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="XmlTerm"/> class based on the given /// collection of Scripture notes. /// </summary> /// <param name="term">The key term.</param> /// ------------------------------------------------------------------------------------ public XmlTerm(IChkTerm term) { m_term = term; TermIdNum = term.TermId; KeyWord = new XmlKeyWord(term); foreach (IChkRef occurrence in term.OccurrencesOS.Where(o => o.Status != KeyTermRenderingStatus.AutoAssigned && o.Status != KeyTermRenderingStatus.Unassigned)) { Renderings.Add(new XmlTermRendering(occurrence)); } Debug.Assert(Renderings.Count > 0); }
private KeyTermRef CreateCheckRef(int scrRef) { IChkTerm chkTerm = Cache.ServiceLocator.GetInstance <IChkTermFactory>().Create(); Cache.LanguageProject.KeyTermsList.PossibilitiesOS.Add(chkTerm); IChkRef chkRef = Cache.ServiceLocator.GetInstance <IChkRefFactory>().Create(); chkTerm.OccurrencesOS.Add(chkRef); chkRef.Ref = scrRef; return(new KeyTermRef(chkRef)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="XmlKeyWord"/> class, based on the given /// run information /// </summary> /// ------------------------------------------------------------------------------------ public XmlKeyWord(IChkTerm term) { ITsString origLangTerm = term.OccurrencesOS.First().KeyWord; Debug.Assert(origLangTerm.RunCount == 1); int ws = origLangTerm.get_WritingSystem(0); string icuLocale; if (!s_mapWsToIcuLocale.TryGetValue(ws, out icuLocale)) { ILgWritingSystemFactory lgwsf = term.Cache.LanguageWritingSystemFactoryAccessor; s_mapWsToIcuLocale[ws] = icuLocale = lgwsf.GetStrFromWs(ws); } IcuLocale = icuLocale; Text = origLangTerm.Text; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Matches the old check refs to the new check refs and copies over any renderings, /// then adds the ids of the old ChkTerms and ChkRefs to the set of IDs to be deleted. /// </summary> /// <param name="newKeyTerms">The CmPossibility whose SubPossiblities are the new key /// terms.</param> /// <param name="oldTerms">The old (top-level) key terms.</param> /// <param name="dlg">Progress dialog box (can be null)</param> /// ------------------------------------------------------------------------------------ private void CopyRenderingsFromOldCheckRefs(ICmPossibility newKeyTerms, IFdoOwningSequence <ICmPossibility> oldTerms, IProgress dlg) { foreach (ICmPossibility poss in oldTerms) { // TE-7697, oldTerms contained something that wasn't a IChkTerm, so changed // using IChkTerm as loop variable to explicit cast and check for failure IChkTerm term = poss as IChkTerm; if (term != null) { foreach (IChkRef oldChkRef in term.OccurrencesOS) { if (oldChkRef.Status != KeyTermRenderingStatus.Unassigned) { foreach (IChkRef newChkRef in ChkRefMatcher.FindCorrespondingChkRefs( newKeyTerms, oldChkRef)) { newChkRef.Status = oldChkRef.Status; newChkRef.RenderingRA = oldChkRef.RenderingRA; if (newChkRef.RenderingRA != null) { IChkTerm owningTerm = (IChkTerm)newChkRef.Owner; bool fRenderingAlreadyInCollection = false; foreach (IChkRendering rendering in owningTerm.RenderingsOC) { if (rendering.SurfaceFormRA == newChkRef.RenderingRA) { fRenderingAlreadyInCollection = true; break; } } if (!fRenderingAlreadyInCollection) { IChkRendering rendering = m_servLoc.GetInstance <IChkRenderingFactory>().Create(); owningTerm.RenderingsOC.Add(rendering); rendering.SurfaceFormRA = newChkRef.RenderingRA; } } } } } if (dlg != null) { dlg.Step(1); } } CopyRenderingsFromOldCheckRefs(newKeyTerms, poss.SubPossibilitiesOS, null); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="XmlKeyWord"/> class, based on the given /// run information /// </summary> /// ------------------------------------------------------------------------------------ public XmlKeyWord(IChkTerm term) { ITsString origLangTerm = term.OccurrencesOS.First().KeyWord; Debug.Assert(origLangTerm.RunCount == 1); int ws = origLangTerm.get_WritingSystem(0); string icuLocale; if (!s_mapWsToIcuLocale.TryGetValue(ws, out icuLocale)) { ILgWritingSystemFactory lgwsf = term.Cache.LanguageWritingSystemFactoryAccessor; s_mapWsToIcuLocale[ws] = icuLocale = lgwsf.GetStrFromWs(ws); } IcuLocale = icuLocale; Text = origLangTerm.Text; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a Check Term /// </summary> /// <param name="termId">The term id.</param> /// <param name="hvoWs">The HVO of the original-language writing system.</param> /// <param name="name">The Lemma form of the term in the original language (i.e., Greek /// or Hebrew)</param> /// <param name="description">A list of other derived forms of the term in the original /// language (can be null)</param> /// <param name="owner">CmPossibility that is above the term in the hierarchy (probably /// a category)</param> /// <returns>The new ChkTerm</returns> /// ------------------------------------------------------------------------------------ private IChkTerm CreateChkTerm(int termId, int hvoWs, string name, string description, ICmPossibility owner) { IChkTerm newTerm = m_servLoc.GetInstance <IChkTermFactory>().Create(); owner.SubPossibilitiesOS.Add(newTerm); newTerm.TermId = termId; newTerm.Name.set_String(hvoWs, name); if (!String.IsNullOrEmpty(description)) { newTerm.Description.set_String(hvoWs, description); } return(newTerm); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Recursively adds XML terms for any terms in the list that have occurrences with /// renderings or explicit non-renderings (i.e., "ignored"). /// </summary> /// ------------------------------------------------------------------------------------ private void AddTerms(IFdoOwningSequence <ICmPossibility> possibilities) { foreach (ICmPossibility poss in possibilities) { IChkTerm term = poss as IChkTerm; if (term != null && term.OccurrencesOS.Any(o => o.Status != KeyTermRenderingStatus.AutoAssigned && o.Status != KeyTermRenderingStatus.Unassigned)) { Terms.Add(new XmlTerm(term)); } if (poss.SubPossibilitiesOS.Any()) { AddTerms(poss.SubPossibilitiesOS); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Writes this rendering to the specified cache. /// </summary> /// <param name="term">The term to which this rendering belongs.</param> /// <param name="ResolveConflict">The delegate to call to resolve a conflict when a /// different rendering already exists.</param> /// ------------------------------------------------------------------------------------ internal void WriteToCache(IChkTerm term, Func <IChkRef, string, string, bool> ResolveConflict) { IChkRef occ = term.OccurrencesOS.FirstOrDefault(o => o.Ref == Reference && o.Location == Location); if (occ == null) { MessageBox.Show(string.Format("Couldn't find occurrence {0} in {1} for imported rendering of term: {2}.", Location, (new BCVRef(Reference)), term.Name.AnalysisDefaultWritingSystem), "Unable to Import"); return; } if (string.IsNullOrEmpty(VernRendering)) { if (occ.Status != KeyTermRenderingStatus.Ignored) { occ.Status = KeyTermRenderingStatus.Ignored; occ.RenderingRA = null; } return; } string existingRendering = occ.RenderingRA == null ? null : occ.RenderingRA.Form.VernacularDefaultWritingSystem.Text; if (existingRendering == VernRendering) { return; // already set. Nothing to do. } if (!string.IsNullOrEmpty(existingRendering)) { if (!ResolveConflict(occ, existingRendering, VernRendering)) { return; // Leave existing rendering } } // See if the word form already exists IWfiWordform wordForm = WfiWordformServices.FindOrCreateWordform(term.Cache, VernRendering, term.Services.WritingSystems.DefaultVernacularWritingSystem); KeyTermRef ktRef = new KeyTermRef(occ); // Change the reference's status and attach the word form to the ChkRef ktRef.AssignRendering(wordForm); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Recursively populate a list with key term references /// </summary> /// <param name="keyTerm">ChkTerm which is part of the keyterm hierarchy</param> /// <param name="filteredBookIds">list of books in the filter, or null if no filter</param> /// ------------------------------------------------------------------------------------ private void PopulateKeyTermRefs(IChkTerm keyTerm, List <int> filteredBookIds) { foreach (IChkRef chkRef in keyTerm.OccurrencesOS) { KeyTermRef keyRef = new KeyTermRef(chkRef); if (filteredBookIds == null || filteredBookIds.Contains(keyRef.RefInCurrVersification.Book)) { keyRef.PropertyChanged -= OnKeyTermRefPropertyChanged; keyRef.PropertyChanged += OnKeyTermRefPropertyChanged; m_list.Add(keyRef); } } foreach (IChkTerm kt in keyTerm.SubPossibilitiesOS) { PopulateKeyTermRefs(kt, filteredBookIds); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Assigns a rendering for this check reference. /// </summary> /// <param name="wordForm">The word form.</param> /// ------------------------------------------------------------------------------------ internal void AssignRendering(IWfiWordform wordForm) { if (wordForm == null) { throw new ArgumentNullException("wordForm", "Cannot assign a rendering to a null word form."); } RenderingStatus = KeyTermRenderingStatus.Assigned; m_chkRef.RenderingRA = wordForm; IChkTerm owningChkTerm = (IChkTerm)m_chkRef.Owner; bool fChkTermRenderingAlreadySet = owningChkTerm.RenderingsOC.Any(rendering => rendering.SurfaceFormRA == wordForm); if (!fChkTermRenderingAlreadySet) { IChkRendering newRendering = m_cache.ServiceLocator.GetInstance <IChkRenderingFactory>().Create(); owningChkTerm.RenderingsOC.Add(newRendering); newRendering.SurfaceFormRA = wordForm; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Writes this rendering to the specified cache. /// </summary> /// <param name="term">The term to which this rendering belongs.</param> /// <param name="ResolveConflict">The delegate to call to resolve a conflict when a /// different rendering already exists.</param> /// ------------------------------------------------------------------------------------ internal void WriteToCache(IChkTerm term, Func<IChkRef, string, string, bool> ResolveConflict) { IChkRef occ = term.OccurrencesOS.FirstOrDefault(o => o.Ref == Reference && o.Location == Location); if (occ == null) { MessageBox.Show(string.Format("Couldn't find occurrence {0} in {1} for imported rendering of term: {2}.", Location, (new BCVRef(Reference)), term.Name.AnalysisDefaultWritingSystem), "Unable to Import"); return; } if (string.IsNullOrEmpty(VernRendering)) { if (occ.Status != KeyTermRenderingStatus.Ignored) { occ.Status = KeyTermRenderingStatus.Ignored; occ.RenderingRA = null; } return; } string existingRendering = occ.RenderingRA == null ? null : occ.RenderingRA.Form.VernacularDefaultWritingSystem.Text; if (existingRendering == VernRendering) return; // already set. Nothing to do. if (!string.IsNullOrEmpty(existingRendering)) { if (!ResolveConflict(occ, existingRendering, VernRendering)) return; // Leave existing rendering } // See if the word form already exists IWfiWordform wordForm = WfiWordformServices.FindOrCreateWordform(term.Cache, VernRendering, term.Services.WritingSystems.DefaultVernacularWritingSystem); KeyTermRef ktRef = new KeyTermRef(occ); // Change the reference's status and attach the word form to the ChkRef ktRef.AssignRendering(wordForm); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="InvalidRendering"/> class. /// </summary> /// <param name="parentKeyTerm">The owner of the key term.</param> /// <param name="rendering">The invalid rendering.</param> /// ------------------------------------------------------------------------------------ public InvalidRendering(IChkTerm parentKeyTerm, IChkRendering rendering) { m_parentKeyTerm = parentKeyTerm; m_rendering = rendering; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the CkkRef records associated with the given term to the hashtable. /// </summary> /// <param name="chkTerm">The key term.</param> /// <param name="bcvToChkRefs">The BCV to CHK refs.</param> /// ------------------------------------------------------------------------------------ private void AddChkRefsToBCVmap(IChkTerm chkTerm, ref Dictionary<int, List<KeyTermRef>> bcvToChkRefs) { List<int> filteredBookNum = m_FilteredBookIds; // if we don't have a book filter, we only care about // updating keyterms for renderings in books we have in our // project. // NOTE: What do we do about updating renderings for books // that have been removed from the project? if (filteredBookNum == null) filteredBookNum = new List<int>(); if (filteredBookNum.Count == 0) { foreach (IScrBook book in m_scr.ScriptureBooksOS) filteredBookNum.Add(book.CanonicalNum); } foreach (IChkRef chkRef in chkTerm.OccurrencesOS) { if (filteredBookNum != null && filteredBookNum.Count > 0) { int bookNumOfOccurrence = ScrReference.GetBookFromBcv(chkRef.Ref); // if we have a book filter, we only care about mapping for // renderings that are showing. if (!filteredBookNum.Contains(bookNumOfOccurrence)) continue; } if (!bcvToChkRefs.ContainsKey(chkRef.Ref)) { bcvToChkRefs.Add(chkRef.Ref, new List<KeyTermRef>()); } bcvToChkRefs[chkRef.Ref].Add(new KeyTermRef(chkRef)); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the localized gloss, description, and "see also" information in the given /// writing system for a key term. /// </summary> /// <param name="term">The key term</param> /// <param name="termLoc">The localization information</param> /// <param name="ws">The HVO of the writing system</param> /// ------------------------------------------------------------------------------------ private void SetLocalizedGlossAndDescription(IChkTerm term, TermLocalization termLoc, int ws) { string[] glosses = termLoc.Gloss.Split(new [] { ';' }, 2); SetLocalizedInfo(term, ws, glosses[0].Trim(), termLoc.DescriptionText == null ? null : termLoc.DescriptionText.Trim().Trim('-'), (glosses.Length == 2) ? glosses[1].Trim() : null); }
private static void AppendMarkOccurrencesToKeyTerm(IChkTerm keyTerm1) { // Create references of MRK 1:1 for the key term CreateChkRef(keyTerm1, 41001001); // Create references of MRK 1:2 for the key term CreateChkRef(keyTerm1, 41001002); }
private IChkRef LoadRenderingsAndSelectOccurrenceInRenderingCtrl(IChkTerm term, int iOccurrence) { m_ktVwWrapper.RenderingsControl.LoadRenderingsForKeyTerm(term.Hvo, null); SetCurrentLineInRenderingCtrl(iOccurrence); return term.OccurrencesOS[iOccurrence]; }
private IChkTerm CreateSubChkTerm(IChkTerm parentKeyTerm, string name) { IChkTerm keyTerm = parentKeyTerm.SubPossibilitiesOS.Append(new ChkTerm()) as IChkTerm; keyTerm.Name.SetAlternative(name, Cache.DefaultUserWs); return keyTerm; }
private static IChkRef CreateChkRef(IChkTerm keyTermPossible, int bcv) { IChkRef chkRef = new ChkRef(); keyTermPossible.OccurrencesOS.Append(chkRef); chkRef.Ref = bcv; return chkRef; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds an occurrence to and old-style sense. /// </summary> /// <param name="term">The ChkTerm (a sense or subsense).</param> /// <param name="reference">The Scripture reference.</param> /// <param name="wordform">The wordform.</param> /// <param name="keyword">The keyword (transliterated from Greek)</param> /// <param name="status">The rendering status.</param> /// <returns>The newly added ChkRef</returns> /// ------------------------------------------------------------------------------------ protected IChkRef AddOccurrenceToOldStyleSense(IChkTerm term, int reference, IWfiWordform wordform, string keyword, KeyTermRenderingStatus status) { IChkRef occurrence = Cache.ServiceLocator.GetInstance<IChkRefFactory>().Create(); term.OccurrencesOS.Add(occurrence); occurrence.KeyWord = m_factory.MakeString(keyword, m_wsEn); occurrence.Ref = reference; // If wordform is null, status must either be unassigned or ignored // If wordform is not null, status must either be assigned or auto-assigned Debug.Assert(((wordform == null) && (status == KeyTermRenderingStatus.Unassigned || status == KeyTermRenderingStatus.Ignored)) || ((wordform != null) && (status == KeyTermRenderingStatus.Assigned || status == KeyTermRenderingStatus.AutoAssigned))); occurrence.Status = status; occurrence.RenderingRA = wordform; return occurrence; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Recursively populate a list with key term references /// </summary> /// <param name="keyTerm">ChkTerm which is part of the keyterm hierarchy</param> /// <param name="filteredBookIds">list of books in the filter, or null if no filter</param> /// ------------------------------------------------------------------------------------ private void PopulateKeyTermRefs(IChkTerm keyTerm, List<int> filteredBookIds) { foreach (IChkRef chkRef in keyTerm.OccurrencesOS) { KeyTermRef keyRef = new KeyTermRef(chkRef); if (filteredBookIds == null || filteredBookIds.Contains(keyRef.RefInCurrVersification.Book)) { keyRef.PropertyChanged -= OnKeyTermRefPropertyChanged; keyRef.PropertyChanged += OnKeyTermRefPropertyChanged; m_list.Add(keyRef); } } foreach (IChkTerm kt in keyTerm.SubPossibilitiesOS) PopulateKeyTermRefs(kt, filteredBookIds); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Build a list of the KeyTermRef objects that will be displayed in the key terms /// rendering grid. /// </summary> /// <param name="chkTerm">The term node to get references for. This could be the /// category node, in which case we just clear the list.</param> /// <param name="filteredBookIds">list of book ids that are in the current filter. /// If null, then filtering is not on and all references should be included</param> /// ------------------------------------------------------------------------------------ public void LoadRenderingsForKeyTerm(IChkTerm chkTerm, List<int> filteredBookIds) { m_dataGridView.RowEnter -= m_dataGridView_RowEnter; m_dataGridView.RowCount = 0; m_list.Clear(); PopulateKeyTermRefs(chkTerm, filteredBookIds); if (m_stylesheet != null) { if (!String.IsNullOrEmpty(chkTerm.Name.get_String(m_wsGreek).Text)) m_OriginalTerm.WritingSystemCode = m_wsGreek; else if (!String.IsNullOrEmpty(chkTerm.Name.get_String(m_wsHebrew).Text)) m_OriginalTerm.WritingSystemCode = m_wsHebrew; else throw new ArgumentException("Unexpected biblical term - no Greek or Hebrew Name. Term id = " + chkTerm); if (m_OriginalTerm.Font != null) m_OriginalTerm.Font.Dispose(); m_OriginalTerm.Font = m_stylesheet.GetUiFontForWritingSystem( m_OriginalTerm.WritingSystemCode, m_OriginalTerm.SizeOfFontAt100Percent * ZoomFactor); } m_dataGridView.RowCount = m_list.Count; m_dataGridView.KeyTermRefs = m_list; m_dataGridView.RowEnter += m_dataGridView_RowEnter; Sort(m_sortedColumn, false, kRefCol); m_prevResultRow = -1; if (m_firstLoad && m_persistence != null) OnLoadSettings(m_persistence.SettingsKey); m_firstLoad = false; if (m_dataGridView.RowCount == 0) { if (ReferenceListEmptied != null) ReferenceListEmptied(this, EventArgs.Empty); } else OnReferenceChanged(0); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Finds and selects the "next" (starting from the currently selected node) node for a /// term whose name, description, or see also contains text matching the given string. /// </summary> /// ------------------------------------------------------------------------------------ protected internal FindResult FindNextMatch(string s) { s = s.Normalize(NormalizationForm.FormD); if (m_lastFindString != s || m_lastFoundNode != SelectedNode) { m_lastFindString = s; m_startingNodeForFind = SelectedNode; m_lastFoundNode = null; } if (m_startingNodeForFind == m_lastFoundNode) { return(FindResult.NoMoreMatches); } Func <TreeNode, bool> Matches = node => { if (node.Text.IndexOf(s, StringComparison.InvariantCultureIgnoreCase) >= 0) { return(true); } IChkTerm term = node.Tag as IChkTerm; return(term != null && (term.Name.OccursInAnyAlternative(s) || term.Description.OccursInAnyAlternative(s) || term.SeeAlso.OccursInAnyAlternative(s))); }; bool hitStartingNode = false; bool hitLastFoundNode = false; TreeNode foundNode = null; foreach (TreeNode node in AllNodes) { if (node == m_startingNodeForFind) { if (hitLastFoundNode) { break; } hitStartingNode = true; } else if (node == m_lastFoundNode) { if (!hitStartingNode) { foundNode = null; } hitLastFoundNode = true; } else if (Matches(node)) { bool foundFirstMatchBeforeStart = (foundNode == null && !hitStartingNode); bool foundWhatWeWereLookingFor = hitLastFoundNode || (hitStartingNode && m_lastFoundNode == null); if (foundFirstMatchBeforeStart || foundWhatWeWereLookingFor) { foundNode = node; if (hitStartingNode) { break; } } } } if (foundNode == null && m_startingNodeForFind != m_lastFoundNode && Matches(m_startingNodeForFind)) { foundNode = m_startingNodeForFind; } if (foundNode == null) { bool noMatchFound = m_lastFoundNode == null && !Matches(SelectedNode); m_lastFoundNode = null; return(noMatchFound ? FindResult.NoMatchFound : FindResult.NoMoreMatches); } m_lastFoundNode = foundNode; SelectedNode = foundNode; return(FindResult.MatchFound); }
private IChkRef CreateChkRef(IChkTerm keyTermPossible, int bcv) { IChkRef chkRef = Cache.ServiceLocator.GetInstance<IChkRefFactory>().Create(); keyTermPossible.OccurrencesOS.Add(chkRef); chkRef.Ref = bcv; return chkRef; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds an occurrence to and old-style sense. /// </summary> /// <param name="term">The ChkTerm (a sense or subsense).</param> /// <param name="reference">The Scripture reference.</param> /// <param name="wordform">The wordform.</param> /// <param name="keyword">The keyword (transliterated from Greek)</param> /// <returns>The newly added ChkRef</returns> /// ------------------------------------------------------------------------------------ protected IChkRef AddOccurrenceToOldStyleSense(IChkTerm term, int reference, IWfiWordform wordform, string keyword) { return AddOccurrenceToOldStyleSense(term, reference, wordform, keyword, (wordform == null) ? KeyTermRenderingStatus.Unassigned : KeyTermRenderingStatus.Assigned); }
private IChkTerm CreateSubChkTerm(IChkTerm parentKeyTerm, string name) { IChkTerm keyTerm = Cache.ServiceLocator.GetInstance<IChkTermFactory>().Create(); parentKeyTerm.SubPossibilitiesOS.Add(keyTerm); keyTerm.Name.set_String(Cache.DefaultUserWs, name); return keyTerm; }
public void FindCorrespondingChkRef() { // First, create a possibility list with the old key terms and set some ChkRefs to // have renderings. IWfiWordform abc = Cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(); abc.Form.SetVernacularDefaultWritingSystem("abc"); IWfiWordform def = Cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(); abc.Form.SetVernacularDefaultWritingSystem("def"); IWfiWordform ghi = Cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(); abc.Form.SetVernacularDefaultWritingSystem("ghi"); IWfiWordform jkl = Cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(); abc.Form.SetVernacularDefaultWritingSystem("jkl"); IWfiWordform mno = Cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(); abc.Form.SetVernacularDefaultWritingSystem("mno"); ICmPossibilityList oldKeyTermsList = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create(); m_lp.CheckListsOC.Add(oldKeyTermsList); IChkTerm term = Cache.ServiceLocator.GetInstance <IChkTermFactory>().Create(); oldKeyTermsList.PossibilitiesOS.Add(term); term.Name.set_String(m_wsEn, "Adultery"); IChkTerm subsense = Cache.ServiceLocator.GetInstance <IChkTermFactory>().Create(); term.SubPossibilitiesOS.Add(subsense); subsense.Name.set_String(m_wsEn, "The act of sexual unfaithfulness"); IChkRef chkrefMoicheuw040005027 = AddOccurrenceToOldStyleSense(subsense, 040005027, abc, "moicheuw"); IChkRef chkrefMoicheuw040005028 = AddOccurrenceToOldStyleSense(subsense, 040005028, abc, "moicheuw"); IChkRef chkrefMoichaomai040005032 = AddOccurrenceToOldStyleSense(subsense, 040005032, def, "moichaomai"); IChkRef chkrefMoicheia040015019 = AddOccurrenceToOldStyleSense(subsense, 040015019, ghi, "moicheia"); IChkRef chkrefMoichaomai040019009 = AddOccurrenceToOldStyleSense(subsense, 040019009, def, "moichaomai"); subsense = Cache.ServiceLocator.GetInstance <IChkTermFactory>().Create(); term.SubPossibilitiesOS.Add(subsense); subsense.Name.set_String(m_wsEn, "One who sexually violates marriage vows"); IChkTerm subsubsense = Cache.ServiceLocator.GetInstance <IChkTermFactory>().Create(); subsense.SubPossibilitiesOS.Add(subsubsense); subsubsense.Name.set_String(m_wsEn, "Masculine offenders"); IChkRef chkrefMoichos042018011 = AddOccurrenceToOldStyleSense(subsubsense, 042018011, jkl, "moichos"); IChkRef chkrefMoichos046006009 = AddOccurrenceToOldStyleSense(subsubsense, 046006009, jkl, "moichos"); IChkRef chkrefMoichos058013004 = AddOccurrenceToOldStyleSense(subsubsense, 058013004, jkl, "moichos"); subsubsense = Cache.ServiceLocator.GetInstance <IChkTermFactory>().Create(); subsense.SubPossibilitiesOS.Add(subsubsense); subsubsense.Name.set_String(m_wsEn, "Feminine offenders"); IChkRef chkrefMoichalis045007003 = AddOccurrenceToOldStyleSense(subsubsense, 045007003, mno, "moichalis"); IChkRef chkrefMoichalis061002014 = AddOccurrenceToOldStyleSense(subsubsense, 061002014, mno, "moichalis"); // Next, load the new list of Biblicalk terms BiblicalTermsList terms = new BiblicalTermsList(); terms.Version = Guid.NewGuid(); terms.KeyTerms = new List <Term>(); terms.KeyTerms.Add(new Term(3, "KT", "\u03b1\u03b2\u03b2\u03b1", "Greek", "abba; father", null, null, 4101403603, 4500801516, 4800400618)); string sGrkMoichaomai = "\u03BC\u03BF\u03B9\u03C7\u1F71\u03BF\u03BC\u03B1\u03B9"; terms.KeyTerms.Add(new Term(1139, "KT", "\u03BC\u03BF\u03B9\u03C7\u1F71\u03BF\u03BC\u03B1\u03B9-1", "Greek", "commit adultery", sGrkMoichaomai, "\u03BC\u03BF\u03B9\u03C7\u03B5\u1F77\u03B1, \u03BC\u03BF\u03B9\u03C7\u03B5\u1F7B\u03C9, \u03BC\u03BF\u03B9\u03C7\u03B1\u03BB\u1F77\u03C2, \u03BC\u03BF\u03B9\u03C7\u1F79\u03C2", 04000503223, 04001900917, 04101001123, 04101001210)); string sGrkMoicheia = "\u03BC\u03BF\u03B9\u03C7\u03B5\u1F77\u03B1"; terms.KeyTerms.Add(new Term(1140, "KT", "\u03BC\u03BF\u03B9\u03C7\u1F71\u03BF\u03BC\u03B1\u03B9-2", "Greek", "adultery", sGrkMoicheia, "\u03BC\u03BF\u03B9\u03C7\u03B5\u1F77\u03B1, \u03BC\u03BF\u03B9\u03C7\u03B5\u1F7B\u03C9, \u03BC\u03BF\u03B9\u03C7\u03B1\u03BB\u1F77\u03C2, \u03BC\u03BF\u03B9\u03C7\u1F79\u03C2", 04001501909, 04300800310)); string sGrkMoicheuw = "\u03BC\u03BF\u03B9\u03C7\u03B5\u1F7B\u03C9"; terms.KeyTerms.Add(new Term(1141, "KT", "\u03BC\u03BF\u03B9\u03C7\u1F71\u03BF\u03BC\u03B1\u03B9-3", "Greek", "commit adultery", sGrkMoicheuw, "\u03BC\u03BF\u03B9\u03C7\u03B5\u1F77\u03B1, \u03BC\u03BF\u03B9\u03C7\u03B5\u1F7B\u03C9, \u03BC\u03BF\u03B9\u03C7\u03B1\u03BB\u1F77\u03C2, \u03BC\u03BF\u03B9\u03C7\u1F79\u03C2", 04000502705, 04000502708, 04000502815, 04001901812, 04101001907, 04201601810, 04201601817, 04201802005, 04300800410, 04500202204, 04500202205, 04501300904, 05900201105, 05900201113, 06600202208)); string sGrkMoichalis = "\u03BC\u03BF\u03B9\u03C7\u03B1\u03BB\u1F77\u03C2"; terms.KeyTerms.Add(new Term(1142, "KT", "\u03BC\u03BF\u03B9\u03C7\u1F71\u03BF\u03BC\u03B1\u03B9-4", "Greek", "adulterous; adulteress", sGrkMoichalis, "\u03BC\u03BF\u03B9\u03C7\u03B5\u1F77\u03B1, \u03BC\u03BF\u03B9\u03C7\u03B5\u1F7B\u03C9, \u03BC\u03BF\u03B9\u03C7\u03B1\u03BB\u1F77\u03C2, \u03BC\u03BF\u03B9\u03C7\u1F79\u03C2", 04001203909, 04001600404, 04100803815, 04500700306, 04500700326, 05900400401, 06100201404)); string sGrkMoichos = "\u03BC\u03BF\u03B9\u03C7\u1F79\u03C2"; terms.KeyTerms.Add(new Term(1143, "KT", "\u03BC\u03BF\u03B9\u03C7\u1F71\u03BF\u03BC\u03B1\u03B9-5", "Greek", "adulterer", sGrkMoichos, "\u03BC\u03BF\u03B9\u03C7\u03B5\u1F77\u03B1, \u03BC\u03BF\u03B9\u03C7\u03B5\u1F7B\u03C9, \u03BC\u03BF\u03B9\u03C7\u03B1\u03BB\u1F77\u03C2, \u03BC\u03BF\u03B9\u03C7\u1F79\u03C2", 04201801122, 04600600917)); List <BiblicalTermsLocalization> localizations = new List <BiblicalTermsLocalization>(1); ICmPossibilityList newBiblicalTermsList = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create(); m_lp.CheckListsOC.Add(newBiblicalTermsList); DummyTeKeyTermsInit.CallLoadKeyTerms(newBiblicalTermsList, terms, localizations); ICmPossibility newKtList = null; foreach (ICmPossibility category in newBiblicalTermsList.PossibilitiesOS) { if (category.Abbreviation.get_String(m_wsEn).Text == "KT") { newKtList = category; } } Assert.IsNotNull(newKtList); // Now check to make sure FindCorrespondingChkRefs works List <IChkRef> chkRefs = ChkRefMatcher.FindCorrespondingChkRefs(newKtList, chkrefMoichalis045007003); Assert.AreEqual(2, chkRefs.Count); Assert.AreEqual(sGrkMoichalis.Normalize(NormalizationForm.FormD), chkRefs[0].KeyWord.Text); Assert.AreEqual(045007003, chkRefs[0].Ref); Assert.AreEqual(6, chkRefs[0].Location); Assert.AreEqual(sGrkMoichalis.Normalize(NormalizationForm.FormD), chkRefs[1].KeyWord.Text); Assert.AreEqual(045007003, chkRefs[1].Ref); Assert.AreEqual(26, chkRefs[1].Location); chkRefs = ChkRefMatcher.FindCorrespondingChkRefs(newKtList, chkrefMoichalis061002014); Assert.AreEqual(1, chkRefs.Count); Assert.AreEqual(sGrkMoichalis.Normalize(NormalizationForm.FormD), chkRefs[0].KeyWord.Text); Assert.AreEqual(061002014, chkRefs[0].Ref); Assert.AreEqual(4, chkRefs[0].Location); chkRefs = ChkRefMatcher.FindCorrespondingChkRefs(newKtList, chkrefMoichaomai040005032); Assert.AreEqual(1, chkRefs.Count); Assert.AreEqual(sGrkMoichaomai.Normalize(NormalizationForm.FormD), chkRefs[0].KeyWord.Text); Assert.AreEqual(040005032, chkRefs[0].Ref); Assert.AreEqual(23, chkRefs[0].Location); chkRefs = ChkRefMatcher.FindCorrespondingChkRefs(newKtList, chkrefMoichaomai040019009); Assert.AreEqual(1, chkRefs.Count); Assert.AreEqual(sGrkMoichaomai.Normalize(NormalizationForm.FormD), chkRefs[0].KeyWord.Text); Assert.AreEqual(040019009, chkRefs[0].Ref); Assert.AreEqual(17, chkRefs[0].Location); chkRefs = ChkRefMatcher.FindCorrespondingChkRefs(newKtList, chkrefMoicheia040015019); Assert.AreEqual(1, chkRefs.Count); Assert.AreEqual(sGrkMoicheia.Normalize(NormalizationForm.FormD), chkRefs[0].KeyWord.Text); Assert.AreEqual(040015019, chkRefs[0].Ref); Assert.AreEqual(9, chkRefs[0].Location); chkRefs = ChkRefMatcher.FindCorrespondingChkRefs(newKtList, chkrefMoicheuw040005027); Assert.AreEqual(2, chkRefs.Count); Assert.AreEqual(sGrkMoicheuw.Normalize(NormalizationForm.FormD), chkRefs[0].KeyWord.Text); Assert.AreEqual(040005027, chkRefs[0].Ref); Assert.AreEqual(5, chkRefs[0].Location); Assert.AreEqual(sGrkMoicheuw.Normalize(NormalizationForm.FormD), chkRefs[1].KeyWord.Text); Assert.AreEqual(040005027, chkRefs[1].Ref); Assert.AreEqual(8, chkRefs[1].Location); chkRefs = ChkRefMatcher.FindCorrespondingChkRefs(newKtList, chkrefMoicheuw040005028); Assert.AreEqual(1, chkRefs.Count); Assert.AreEqual(sGrkMoicheuw.Normalize(NormalizationForm.FormD), chkRefs[0].KeyWord.Text); Assert.AreEqual(040005028, chkRefs[0].Ref); Assert.AreEqual(15, chkRefs[0].Location); chkRefs = ChkRefMatcher.FindCorrespondingChkRefs(newKtList, chkrefMoichos042018011); Assert.AreEqual(1, chkRefs.Count); Assert.AreEqual(sGrkMoichos.Normalize(NormalizationForm.FormD), chkRefs[0].KeyWord.Text); Assert.AreEqual(042018011, chkRefs[0].Ref); Assert.AreEqual(22, chkRefs[0].Location); chkRefs = ChkRefMatcher.FindCorrespondingChkRefs(newKtList, chkrefMoichos046006009); Assert.AreEqual(1, chkRefs.Count); Assert.AreEqual(sGrkMoichos.Normalize(NormalizationForm.FormD), chkRefs[0].KeyWord.Text); Assert.AreEqual(046006009, chkRefs[0].Ref); Assert.AreEqual(17, chkRefs[0].Location); chkRefs = ChkRefMatcher.FindCorrespondingChkRefs(newKtList, chkrefMoichos058013004); Assert.AreEqual(0, chkRefs.Count, "We removed this reference from the new list to test the case where no match is found"); }
//#region Public methods ///// ------------------------------------------------------------------------------------ ///// <summary> ///// Adds the specified renderings. ///// </summary> ///// <param name="termRenderings">The collection of references that correspond to the ///// biblical terms that have vernacular renderings.</param> ///// ------------------------------------------------------------------------------------ //public void Add(IEnumerable<IChkRef> termRenderings) //{ // foreach (IChkRef rendering in termRenderings) // Renderings.Add(new XmlTermRendering(rendering)); //} //#endregion #region Methods to write annotations to cache /// ------------------------------------------------------------------------------------ /// <summary> /// Writes the list of renderings to the specified cache. /// </summary> /// <param name="lp">The language project.</param> /// <param name="termsListVersionsMatch">flag indicating whether the term list versions /// in the project is the same as the term list version used by the XML data that was /// read.</param> /// <param name="ResolveConflict">The delegate to call to resolve a conflict when a /// different rendering already exists.</param> /// ------------------------------------------------------------------------------------ internal void WriteToCache(ILangProject lp, bool termsListVersionsMatch, Func<IChkRef, string, string, bool> ResolveConflict) { m_term = FindTerm(lp, termsListVersionsMatch); foreach (XmlTermRendering rendering in Renderings) rendering.WriteToCache(m_term, ResolveConflict); }