/// <summary> /// Collect up a set of unique WfiWordforms. /// </summary> private void GetUniqueWords(Dictionary <string, IWfiWordform> wordforms, string buffer) { int start = -1; // -1 means we're still looking for a word to start. int length = 0; int totalLengh = buffer.Length; for (int i = 0; i < totalLengh; i++) { bool isWordforming = m_ws.get_IsWordForming(buffer[i]); if (isWordforming) { length++; if (start < 0) //first character in this word? { start = i; } } if ((start > -1) && // had a word and found yet? (!isWordforming || i == totalLengh - 1 /*last char of the input*/)) { string word = buffer.Substring(start, length); if (!wordforms.ContainsKey(word)) { ITsString tss = TsStringUtils.MakeString(word, m_ws.Handle); wordforms.Add(word, WfiWordformServices.FindOrCreateWordform(m_cache, tss)); } length = 0; start = -1; } } }
private void CreateTryAWordSandbox() { // skip if it's before we've set the word if (m_sWordForm == null) { return; } // skip if it's before we've set up the rootsite control if (m_rootb == null) { return; } // skip if we're not visible if (!Visible) { return; } //Debug.WriteLine("TryAWordRootSite:WordForm - creating sandbox for " + m_sWordForm.Text); NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => { m_wordform = WfiWordformServices.FindOrCreateWordform(m_cache, m_sWordForm); }); //if (m_cache.IsDummyObject(hvo)) // m_wordform = new WfiWordform(); IAnalysis analysis = m_vc.GetGuessForWordform(m_wordform, m_cache.DefaultVernWs); if (analysis is NullWAG) { analysis = m_wordform; } m_rootb.SetRootObject(analysis.Hvo, m_vc, m_kfragSingleInterlinearAnalysisWithLabels, m_styleSheet); //Debug.Assert(m_tryAWordSandbox == null); m_tryAWordSandbox = new TryAWordSandbox(m_cache, Mediator, m_propertyTable, StyleSheet, m_vc.LineChoices, analysis); m_tryAWordSandbox.Visible = false; Controls.Add(m_tryAWordSandbox); SetSandboxSize(); SetSandboxLocation(); m_tryAWordSandbox.Visible = true; SetBackgroundColor(); int height = Math.Max(ScrollRange.Height, m_tryAWordSandbox.Height) + SystemInformation.HorizontalScrollBarHeight; if (Height != height) { Height = height; } m_tryAWordSandbox.SizeChanged += m_tryAWordSandbox_SizeChanged; //m_tryAWordSandbox.Focus(); }
/// ------------------------------------------------------------------------------------ /// <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); }
public void SetAgentOpinion() { ICmAgent agent = Cache.LangProject.DefaultComputerAgent; IWfiWordform wf = WfiWordformServices.FindOrCreateWordform(Cache, TsStringUtils.MakeTss("xxxyyyzzz12234", Cache.DefaultVernWs)); IWfiAnalysis wa = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>().Create(); wf.AnalysesOC.Add(wa); Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent)); wa.SetAgentOpinion(agent, Opinions.approves); Assert.AreEqual(Opinions.approves, wa.GetAgentOpinion(agent)); wa.SetAgentOpinion(agent, Opinions.disapproves); Assert.AreEqual(Opinions.disapproves, wa.GetAgentOpinion(agent)); wa.SetAgentOpinion(agent, Opinions.noopinion); Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent)); }
private static IAnalysis CreateWordAnalysisStack(FdoCache cache, Word word, ITsStrFactory strFactory) { if (word.Items == null || word.Items.Length <= 0) { return(null); } IAnalysis analysis = null; var wsFact = cache.WritingSystemFactory; ILgWritingSystem wsMainVernWs = null; foreach (var wordItem in word.Items) { ITsString wordForm = null; switch (wordItem.type) { case "txt": wsMainVernWs = GetWsEngine(wsFact, wordItem.lang); wordForm = strFactory.MakeString(wordItem.Value, wsMainVernWs.Handle); analysis = WfiWordformServices.FindOrCreateWordform(cache, wordForm); break; case "punct": wordForm = strFactory.MakeString(wordItem.Value, GetWsEngine(wsFact, wordItem.lang).Handle); analysis = WfiWordformServices.FindOrCreatePunctuationform(cache, wordForm); break; } if (wordForm != null) { break; } } // now add any alternative word forms. (overwrite any existing) if (analysis != null && analysis.HasWordform) { AddAlternativeWssToWordform(analysis, word, wsMainVernWs, strFactory); } if (analysis != null) { UpgradeToWordGloss(word, ref analysis); } else { Debug.Assert(analysis != null, "What else could this do?"); } //Add any morphemes to the thing if (word.morphemes != null && word.morphemes.morphs.Length > 0) { //var bundle = newSegment.Cache.ServiceLocator.GetInstance<IWfiMorphBundleFactory>().Create(); //analysis.Analysis.MorphBundlesOS.Add(bundle); //foreach (var morpheme in word.morphemes) //{ // //create a morpheme // foreach(item item in morpheme.items) // { // //fill in morpheme's stuff // } //} } return(analysis); }