public void NewGlossExistingLexEntryAllomorphNewLexSense() { int hvoCba0_0 = GetCbaHvo(0, 0, 0); m_sandbox.SwitchWord(hvoCba0_0, false); string formLexEntry = "xxxab"; ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs); string formAllomorph = "xxxa"; ITsString tssAllomorphForm = StringUtils.MakeTss(formAllomorph, Cache.DefaultVernWs); // first create an entry with a matching allomorph that doesn't match 'verb' POS we will be selecting in the sandbox ILexEntry lexEntry_NounPos; ILexSense lexSense_NounPos; SetupLexEntryAndSense("xxxab", "0.0.xxxab_NounPos", "noun", out lexEntry_NounPos, out lexSense_NounPos); IMoStemAllomorph allomorph0 = lexEntry_NounPos.AlternateFormsOS.Append(new MoStemAllomorph()) as IMoStemAllomorph; allomorph0.Form.SetAlternativeTss(tssAllomorphForm); // now create the entry we want to match, that has a 'verb' POS. ILexEntry lexEntry1_Entry; ILexSense lexEntry1_Sense1; SetupLexEntryAndSense("xxxab", "0.0.xxxab_VerbPos", "verb", out lexEntry1_Entry, out lexEntry1_Sense1); IMoStemAllomorph allomorph = lexEntry1_Entry.AlternateFormsOS.Append(new MoStemAllomorph()) as IMoStemAllomorph; allomorph.Form.SetAlternativeTss(tssAllomorphForm); // mark the count of LexEntries int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count; // add a new word gloss ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa"); int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0); WfiWordform wf = new WfiWordform(Cache, hvoWf); // set word pos to verb int hvoSbWordPos = m_sandbox.GetComboItemHvo(InterlinLineChoices.kflidWordPos, 0, "transitive verb"); m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordPos, 0, hvoSbWordPos); // confirm the analysis (making a real analysis and a LexSense) int hvoGloss = m_sandbox.ConfirmAnalysis(); WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss); // make sure we didn't add entries to the Lexicon. int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count; Assert.AreEqual(cEntriesOrig, cEntriesAfter); // confirm we have only one analysis and that it is monomorphemic WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis; Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform."); Assert.AreEqual(1, wf.AnalysesOC.Count); Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count); Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count); // make sure the strings of the wfi gloss matches the strings of the lex gloss. ValidateSenseWithAnalysis(m_sandbox.GetLexSenseForWord(), wfiGloss, hvoSbWordPos, true, allomorph); }
private void ValidateSenseWithAnalysis(ILexSense sense, WfiGloss wfiGloss, int hvoSbWordPos, bool fMatchMainPossibility, IMoStemAllomorph allomorph) { WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis; CompareTss(sense.Gloss.GetAlternativeTss(Cache.DefaultAnalWs), wfiGloss.Form.GetAlternativeTss(Cache.DefaultAnalWs)); // make sure the morph is linked to the lexicon sense, msa, and part of speech. IWfiMorphBundle morphBundle = wfiAnalysis.MorphBundlesOS[0]; Assert.AreEqual(sense.Hvo, morphBundle.SenseRAHvo); Assert.AreEqual(sense.MorphoSyntaxAnalysisRAHvo, morphBundle.MsaRAHvo); if (!fMatchMainPossibility) { // expect exact possibility Assert.AreEqual(hvoSbWordPos, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRAHvo); } else { IPartOfSpeech posTarget = PartOfSpeech.CreateFromDBObject(Cache, hvoSbWordPos); Assert.AreEqual(posTarget.MainPossibility.Hvo, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRA.MainPossibility.Hvo); } Assert.AreEqual(allomorph.Hvo, morphBundle.MorphRAHvo); Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRAHvo); }
private WfiAnalysis Make2BundleAnalysis(string form1, string form2, string gloss1, string gloss2) { WfiAnalysis result; ILexEntry entry1 = MakeEntry(form1, gloss1); ILexEntry entry2 = MakeEntry(form2, gloss2); result = new WfiAnalysis(); m_wfAxx.AnalysesOC.Add(result); IWfiMorphBundle bundle = result.MorphBundlesOS.Append(new WfiMorphBundle()); bundle.MorphRA = entry1.LexemeFormOA; bundle.SenseRA = entry1.SensesOS[0]; bundle = result.MorphBundlesOS.Append(new WfiMorphBundle()); bundle.MorphRA = entry2.LexemeFormOA; bundle.SenseRA = entry2.SensesOS[0]; WfiGloss gloss = new WfiGloss(); result.MeaningsOC.Add(gloss); gloss.Form.AnalysisDefaultWritingSystem = gloss1 + "." + gloss2; result.SetAgentOpinion(m_fdoCache.LangProject.DefaultUserAgent, Opinions.approves); m_cAnalyses++; return(result); }
/// <summary> /// Update the analysis to what the sandbox is currently. /// </summary> /// <returns>'true', if anything changed, otherwise 'false'.</returns> public bool UpdateAnalysis(WfiAnalysis anal) { CheckDisposed(); UpdateRealAnalysisMethod uram = new UpdateRealAnalysisMethod(this, m_caches, m_choices, anal); bool result = uram.UpdateRealAnalysis(); m_caches.DataAccess.ClearDirty(); return(result); }
public void NewGlossNewLexEntryNewLexSense() { // load sandbox for first 'xxxa' int hvoCba0_0 = GetCbaHvo(0, 0, 0); m_sandbox.SwitchWord(hvoCba0_0, false); // verify that the word gloss is empty ITsString tssEmpty = StringUtils.MakeTss("", Cache.DefaultAnalWs); ITsString tssWordGloss = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs); CompareTss(tssEmpty, tssWordGloss); // add a new word gloss and confirm the analysis. ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa"); // mark the count of LexEntries int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count; // verify no analyses exist for this wordform; int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0); WfiWordform wf = new WfiWordform(Cache, hvoWf); Assert.AreEqual(0, wf.AnalysesOC.Count); // set word pos, to first possibility (e.g. 'adjunct') int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0); Assert.IsFalse(hvoSbWordPos == 0); // select nonzero pos // confirm the analysis (making a real analysis and a LexSense) int hvoGloss = m_sandbox.ConfirmAnalysis(); WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss); CompareTss(tssWordGlossInSandbox, wfiGloss.Form.GetAlternativeTss(Cache.DefaultAnalWs)); // confirm we have only one analysis and that it is monomorphemic WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis; Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform."); Assert.AreEqual(1, wf.AnalysesOC.Count); Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count); Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count); // make sure the strings of the wfi gloss matches the strings of the lex gloss. ValidateSenseWithAnalysis(m_sandbox.GetLexSenseForWord(), wfiGloss, hvoSbWordPos); // make sure a new entry is in the Lexicon. int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count; Assert.AreEqual(cEntriesOrig + 1, cEntriesAfter); }
/// <summary> /// This contructor is only to be used by the /// </summary> /// <param name="owner"></param> /// <param name="caches"></param> /// <param name="choices"></param> /// <param name="anal"></param> public UpdateRealAnalysisMethod(SandboxBase owner, CachePair caches, InterlinLineChoices choices, WfiAnalysis anal) { m_sandbox = owner; m_caches = caches; m_hvoSbWord = kSbWord; // kSbWord really is a constant, not a real hvo. //m_hvoWordform = hvoWordform; //m_hvoWfiAnalysis = hvoWfiAnalysis; m_anal = anal; //m_hvoWordGloss = hvoWordGloss; m_sda = m_caches.DataAccess; m_sdaMain = m_caches.MainCache.MainCacheAccessor; m_cmorphs = m_sda.get_VecSize(m_hvoSbWord, ktagSbWordMorphs); m_choices = choices; //m_tssForm = tssForm; }
// Make some sort of wfics for the text of the specified paragraph. Assumes no double spaces! // Caches results and does not repeat on same para internal int[] MakeAnnotations(StTxtPara para) { int[] previous; if (m_annotations.TryGetValue(para.Hvo, out previous)) { return(previous); } string contents = para.Contents.Text; string[] words = contents.Split(new char[] { ' ', '.' }); int ich = 0; List <int> results = new List <int>(); ICmAnnotationDefn WficType = CmAnnotationDefn.Twfic(Cache); foreach (string word in words) { if (word == "") { ich++; continue; } WfiWordform wordform = new WfiWordform(); Cache.LangProject.WordformInventoryOA.WordformsOC.Add(wordform); wordform.Form.SetAlternative(word, Cache.DefaultVernWs); // JohnT: This should ideally use CmBaseAnnotation.CreateUnownedCba. But most or all uses of this // method are memory-only tests, and that method requires a database. CmBaseAnnotation cba = new CmBaseAnnotation(); Cache.LangProject.AnnotationsOC.Add(cba); cba.BeginOffset = ich; ich += word.Length; cba.EndOffset = ich; ich++; // past space or dot cba.BeginObjectRA = para; cba.AnnotationTypeRA = WficType; //cba.AnnotationTypeRA = ?? can we get CmAnnotationDefn.Twfic(Cache) with a non-database cache? WfiAnalysis analysis = new WfiAnalysis(); wordform.AnalysesOC.Add(analysis); WfiGloss gloss = new WfiGloss(); analysis.MeaningsOC.Add(gloss); gloss.Form.SetAlternative(word + "Gloss" + ich, Cache.DefaultAnalWs); cba.InstanceOfRA = gloss; results.Add(cba.Hvo); } int[] result = results.ToArray(); m_annotations[para.Hvo] = result; return(result); }
public void PickLexGlossCreatingNewAnalysis() { int hvoCba0_0 = GetCbaHvo(0, 0, 0); m_sandbox.SwitchWord(hvoCba0_0, false); ILexEntry lexEntry1_Entry; ILexSense lexEntry1_Sense1; SetupLexEntryAndSense("xxxa", "0.0.xxxa", out lexEntry1_Entry, out lexEntry1_Sense1); // mark the count of LexEntries int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count; // add a new word gloss ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa"); int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0); WfiWordform wf = new WfiWordform(Cache, hvoWf); // set word pos, to first possibility (e.g. 'adjunct') int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0); // confirm the analysis (making a real analysis and a LexSense) int hvoGloss = m_sandbox.ConfirmAnalysis(); WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss); // make sure we didn't add entries or senses to the Lexicon. int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count; Assert.AreEqual(cEntriesOrig, cEntriesAfter); Assert.AreEqual(1, lexEntry1_Entry.SensesOS.Count); // make sure the sense matches the existing one. ILexSense sense = m_sandbox.GetLexSenseForWord(); Assert.AreEqual(lexEntry1_Sense1.Hvo, sense.Hvo); // make sure the morph is linked to our lexicon sense, msa, and part of speech. ValidateSenseWithAnalysis(sense, wfiGloss, hvoSbWordPos); // confirm we have created a new analysis and that it is monomorphemic WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis; Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform."); Assert.AreEqual(1, wf.AnalysesOC.Count); Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count); Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count); }
/// <summary> /// Make (two) monomorphemic analyses on our favorite wordform, connected to two entries, one with two glosses. /// </summary> private void MakeMonoAnalyses() { string formLexEntry = "axx"; ITsString tssLexEntryForm = Cache.MakeVernTss(formLexEntry); int clsidForm; ILexEntry entry = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "axe", null); ILexSense senseAxe = entry.SensesOS[0]; IMoForm form = entry.LexemeFormOA; m_wfaAxe = new WfiAnalysis(); m_wfAxx.AnalysesOC.Add(m_wfaAxe); IWfiMorphBundle bundle = m_wfaAxe.MorphBundlesOS.Append(new WfiMorphBundle()); bundle.MorphRA = form; bundle.SenseRA = senseAxe; m_wgAxe = new WfiGloss(); m_wfaAxe.MeaningsOC.Add(m_wgAxe); m_wgAxe.Form.AnalysisDefaultWritingSystem = "axe"; m_wgChopper = new WfiGloss(); m_wfaAxe.MeaningsOC.Add(m_wgChopper); m_wgChopper.Form.AnalysisDefaultWritingSystem = "chopper"; m_wfaAxe.SetAgentOpinion(m_fdoCache.LangProject.DefaultUserAgent, Opinions.approves); ILexEntry entryCut = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "cut", null); m_wfaCut = new WfiAnalysis(); m_wfAxx.AnalysesOC.Add(m_wfaCut); bundle = m_wfaCut.MorphBundlesOS.Append(new WfiMorphBundle()); bundle.MorphRA = entryCut.LexemeFormOA; bundle.SenseRA = entryCut.SensesOS[0]; m_wgCut = new WfiGloss(); m_wfaCut.MeaningsOC.Add(m_wgCut); m_wgCut.Form.AnalysisDefaultWritingSystem = "cut"; m_wfaCut.SetAgentOpinion(m_fdoCache.LangProject.DefaultUserAgent, Opinions.approves); m_cAnalyses += 2; }
public void NewGlossExistingLexEntryNewLexSense() { int hvoCba0_0 = GetCbaHvo(0, 0, 0); m_sandbox.SwitchWord(hvoCba0_0, false); string formLexEntry = "xxxa"; ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs); int clsidForm; ILexEntry lexEntry1_Entry = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "xxxa.existingsense1", null); ILexSense lexEntry1_Sense1 = lexEntry1_Entry.SensesOS[0]; // mark the count of LexEntries int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count; // add a new word gloss ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa"); int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0); WfiWordform wf = new WfiWordform(Cache, hvoWf); // set word pos, to first possibility (e.g. 'adjunct') int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0); // confirm the analysis (making a real analysis and a LexSense) int hvoGloss = m_sandbox.ConfirmAnalysis(); WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss); // make sure we didn't add entries to the Lexicon. int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count; Assert.AreEqual(cEntriesOrig, cEntriesAfter); // confirm we have only one analysis and that it is monomorphemic WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis; Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform."); Assert.AreEqual(1, wf.AnalysesOC.Count); Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count); Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count); // make sure the strings of the wfi gloss matches the strings of the lex gloss. ValidateSenseWithAnalysis(m_sandbox.GetLexSenseForWord(), wfiGloss, hvoSbWordPos); }
public void SetAgentOpinion() { ICmAgent agent = m_fdoCache.LangProject.DefaultComputerAgent; IWfiWordform wf = new WfiWordform(m_fdoCache, WfiWordform.FindOrCreateWordform(m_fdoCache, "xxxyyyzzz12234", m_fdoCache.DefaultVernWs, true)); IWfiAnalysis wa = new WfiAnalysis(); wf.AnalysesOC.Add(wa); ICmObject target = wa; // can pick anything as target for evaluation! m_fdoCache.BeginUndoTask("doit", "undoit"); wa.SetAgentOpinion(agent, Opinions.approves); m_fdoCache.EndUndoTask(); Assert.AreEqual(Opinions.approves, wa.GetAgentOpinion(agent)); m_fdoCache.Undo(); Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent)); m_fdoCache.Redo(); Assert.AreEqual(Opinions.approves, wa.GetAgentOpinion(agent)); m_fdoCache.BeginUndoTask("changeit", "unchangeit"); wa.SetAgentOpinion(agent, Opinions.disapproves); m_fdoCache.EndUndoTask(); Assert.AreEqual(Opinions.disapproves, wa.GetAgentOpinion(agent)); m_fdoCache.Undo(); Assert.AreEqual(Opinions.approves, wa.GetAgentOpinion(agent)); m_fdoCache.Redo(); Assert.AreEqual(Opinions.disapproves, wa.GetAgentOpinion(agent)); m_fdoCache.BeginUndoTask("clearit", "unclearit"); wa.SetAgentOpinion(agent, Opinions.noopinion); m_fdoCache.EndUndoTask(); Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent)); m_fdoCache.Undo(); Assert.AreEqual(Opinions.disapproves, wa.GetAgentOpinion(agent)); m_fdoCache.Redo(); Assert.AreEqual(Opinions.noopinion, wa.GetAgentOpinion(agent)); }
/// <summary> /// Initilize the gui control. /// </summary> /// <param name="cache"></param> /// <param name="mediator"></param> /// <param name="configurationNode">NB: In this case it is the main 'window' element node, /// se we have to drill down to find the control definition node(s).</param> /// <param name="sourceObject"></param> public void Init(Mediator mediator, XmlNode configurationNode, ICmObject sourceObject) { CheckDisposed(); Debug.Assert(mediator != null); Debug.Assert(configurationNode != null); Debug.Assert(sourceObject != null && (sourceObject is IWfiWordform || sourceObject is IWfiAnalysis || sourceObject is IWfiGloss)); m_cache = sourceObject.Cache; m_mediator = mediator; m_configurationNode = configurationNode; m_sourceObject = sourceObject; if (sourceObject is IWfiWordform) { m_wordform = sourceObject as IWfiWordform; } else { IWfiAnalysis anal = null; if (sourceObject is IWfiAnalysis) { anal = sourceObject as IWfiAnalysis; } else { anal = WfiAnalysis.CreateFromDBObject(m_cache, sourceObject.OwnerHVO); } m_wordform = WfiWordform.CreateFromDBObject(m_cache, anal.OwnerHVO); } m_mediator.PropertyTable.SetProperty("IgnoreStatusPanel", true); m_mediator.PropertyTable.SetPropertyPersistence("IgnoreStatusPanel", false); m_progAdvInd = new ProgressReporting(m_toolStripProgressBar); // Gather up the nodes. string xpathBase = "/window/controls/parameters[@id='guicontrols']/guicontrol[@id='{0}']/parameters[@id='{1}']"; string xpath = String.Format(xpathBase, "WordformConcordanceBrowseView", "WordformInTwficsOccurrenceList"); XmlNode configNode = m_configurationNode.SelectSingleNode(xpath); // And create the RecordClerks. RecordClerk clerk = RecordClerkFactory.CreateClerk(m_mediator, configNode); clerk.ProgressReporter = m_progAdvInd; m_recordClerks[WfiWordform.kclsidWfiWordform] = clerk; m_configurationNodes[WfiWordform.kclsidWfiWordform] = configNode; xpath = String.Format(xpathBase, "AnalysisConcordanceBrowseView", "AnalysisInTwficsOccurrenceList"); configNode = m_configurationNode.SelectSingleNode(xpath); clerk = RecordClerkFactory.CreateClerk(m_mediator, configNode); clerk.ProgressReporter = m_progAdvInd; m_recordClerks[WfiAnalysis.kclsidWfiAnalysis] = clerk; m_configurationNodes[WfiAnalysis.kclsidWfiAnalysis] = configNode; xpath = String.Format(xpathBase, "GlossConcordanceBrowseView", "GlossInTwficsOccurrenceList"); configNode = m_configurationNode.SelectSingleNode(xpath); clerk = RecordClerkFactory.CreateClerk(m_mediator, configNode); clerk.ProgressReporter = m_progAdvInd; m_recordClerks[WfiGloss.kclsidWfiGloss] = clerk; m_configurationNodes[WfiGloss.kclsidWfiGloss] = configNode; int concordOnHvo = sourceObject.Hvo; Debug.Assert(m_wordform != null); Debug.Assert(concordOnHvo > 0); tvSource.Font = new Font("Arial", 9); tvTarget.Font = new Font("Arial", 9); TreeNode srcTnWf = new TreeNode(); TreeNode tarTnWf = new TreeNode(); StringUtils.InitIcuDataDir(); // used for normalizing strings to NFC tarTnWf.Text = srcTnWf.Text = StringUtils.NormalizeToNFC(MEStrings.ksNoAnalysis); tarTnWf.Tag = srcTnWf.Tag = m_wordform.Hvo; tvSource.Nodes.Add(srcTnWf); tvTarget.Nodes.Add(tarTnWf); if ((int)srcTnWf.Tag == concordOnHvo) { tvSource.SelectedNode = srcTnWf; } int cnt = 0; // Note: the left side source tree only has human approved analyses, // since only those can have instances from text-land pointing at them. foreach (int humanApprovedAnalId in m_wordform.HumanApprovedAnalyses) { IWfiAnalysis anal = WfiAnalysis.CreateFromDBObject(m_wordform.Cache, humanApprovedAnalId); TreeNode srcTnAnal = new TreeNode(); TreeNode tarTnAnal = new TreeNode(); tarTnAnal.Text = srcTnAnal.Text = StringUtils.NormalizeToNFC( String.Format(MEStrings.ksAnalysisX, (++cnt).ToString())); tarTnAnal.Tag = srcTnAnal.Tag = anal.Hvo; srcTnWf.Nodes.Add(srcTnAnal); tarTnWf.Nodes.Add(tarTnAnal); if ((int)srcTnAnal.Tag == concordOnHvo) { tvSource.SelectedNode = srcTnAnal; } foreach (WfiGloss gloss in anal.MeaningsOC) { TreeNode srcTnGloss = new TreeNode(); TreeNode tarTnGloss = new TreeNode(); ITsString tss = gloss.Form.BestAnalysisAlternative; ITsTextProps props = tss.get_PropertiesAt(0); int nVar; int ws = props.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar); string fontname = m_wordform.Cache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(ws).DefaultMonospace; tarTnGloss.NodeFont = new Font(fontname, 9); srcTnGloss.NodeFont = new Font(fontname, 9); tarTnGloss.Text = srcTnGloss.Text = StringUtils.NormalizeToNFC(tss.Text); tarTnGloss.Tag = srcTnGloss.Tag = gloss.Hvo; srcTnAnal.Nodes.Add(srcTnGloss); tarTnAnal.Nodes.Add(tarTnGloss); if ((int)srcTnGloss.Tag == concordOnHvo) { tvSource.SelectedNode = srcTnGloss; } } } tvSource.ExpandAll(); tvSource.SelectedNode.EnsureVisible(); tvTarget.ExpandAll(); }
/// <summary> /// This will recache some information related to a wordform and its analyses, /// and call PropChanged to get the display to refresh. /// </summary> /// <param name="curDisplayedWfId"></param> /// <param name="updateUserCount"></param> /// <param name="updateUserStatusIcon"></param> /// <param name="updateParserCount"></param> /// <param name="updateParserStatusIcon"></param> /// <remarks> /// It makes no sense to call this method if the active area isn't the Words area, /// and the tool isn't Analyses. /// </remarks> public void UpdateWordsToolDisplay( int curDisplayedWfId, bool updateUserCount, bool updateUserStatusIcon, bool updateParserCount, bool updateParserStatusIcon) { CheckDisposed(); IWfiWordform wf = (IWfiWordform)Object; // First update the cache of the real property on which everything else depends. // This should take care of LT-3874. string sql = string.Format("select id from WfiAnalysis_ where owner$ = {0}", wf.Hvo); int[] newAnalyses = DbOps.ReadIntArrayFromCommand(wf.Cache, sql, null); int oldCount = m_cache.MainCacheAccessor.get_VecSize(wf.Hvo, (int)WfiWordform.WfiWordformTags.kflidAnalyses); m_cache.VwCacheDaAccessor.CacheVecProp(wf.Hvo, (int)WfiWordform.WfiWordformTags.kflidAnalyses, newAnalyses, newAnalyses.Length); m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, wf.Hvo, (int)WfiWordform.WfiWordformTags.kflidAnalyses, 0, newAnalyses.Length, oldCount); bool updateConflictCount = false; if (updateUserCount) { m_cache.PropChanged( null, PropChangeType.kpctNotifyAll, wf.Hvo, BaseVirtualHandler.GetInstalledHandlerTag(m_cache, "WfiWordform", "UserCount"), 0, 0, 0); updateConflictCount = true; } if (updateParserCount) { m_cache.PropChanged( null, PropChangeType.kpctNotifyAll, wf.Hvo, BaseVirtualHandler.GetInstalledHandlerTag(m_cache, "WfiWordform", "ParserCount"), 0, 0, 0); updateConflictCount = true; } if (updateConflictCount) { m_cache.PropChanged( null, PropChangeType.kpctNotifyAll, wf.Hvo, BaseVirtualHandler.GetInstalledHandlerTag(m_cache, "WfiWordform", "ConflictCount"), 0, 0, 0); } if (curDisplayedWfId == wf.Hvo) { // Update "WfiWordform"-"HumanApprovedAnalyses" m_cache.PropChanged( null, PropChangeType.kpctNotifyAll, wf.Hvo, BaseVirtualHandler.GetInstalledHandlerTag(m_cache, "WfiWordform", "HumanApprovedAnalyses"), 0, 0, 0); // Update "WfiWordform"-"HumanNoOpinionParses" m_cache.PropChanged( null, PropChangeType.kpctNotifyAll, wf.Hvo, BaseVirtualHandler.GetInstalledHandlerTag(m_cache, "WfiWordform", "HumanNoOpinionParses"), 0, 0, 0); // Update "WfiWordform"-"HumanDisapprovedParses" m_cache.PropChanged( null, PropChangeType.kpctNotifyAll, wf.Hvo, BaseVirtualHandler.GetInstalledHandlerTag(m_cache, "WfiWordform", "HumanDisapprovedParses"), 0, 0, 0); // Update "WfiAnalysis", "ParserStatusIcon" int psiFlid = BaseVirtualHandler.GetInstalledHandlerTag(m_cache, "WfiAnalysis", "ParserStatusIcon"); foreach (int analId in m_cache.GetVectorProperty(wf.Hvo, (int)WfiWordform.WfiWordformTags.kflidAnalyses, true)) { if (updateParserStatusIcon) { // This will force an update to the slice the shows the parser results. WfiAnalysis anal = (WfiAnalysis)CmObject.CreateFromDBObject(m_cache, analId, true); m_cache.PropChanged( null, PropChangeType.kpctNotifyAll, analId, psiFlid, 0, 0, 0); } } } }
/// <summary> /// Make (two) multimorphemic analyses on our favorite wordform, connected to four entries. /// </summary> private void MakeMultiAnalyses() { m_wfaCutIt = Make2BundleAnalysis("ax", "-x", "cut", "it"); m_wfaNotRude = Make2BundleAnalysis("a-", "xx", "not", "rude"); }
protected void CreateTestData() { // Create required virtual properties XmlDocument doc = new XmlDocument(); // Subset of Flex virtuals required for parsing paragraphs etc. doc.LoadXml( "<virtuals>" + "<virtual modelclass=\"StTxtPara\" virtualfield=\"Segments\">" + "<dynamicloaderinfo assemblyPath=\"ITextDll.dll\" class=\"SIL.FieldWorks.IText.ParagraphSegmentsVirtualHandler\"/>" + "</virtual>" + "<virtual modelclass=\"WfiWordform\" virtualfield=\"OccurrencesInTexts\" destinationClass=\"CmBaseAnnotation\">" + "<dynamicloaderinfo assemblyPath=\"ITextDll.dll\" class=\"SIL.FieldWorks.IText.OccurrencesInTextsVirtualHandler\"/>" + "</virtual>" + "<virtual modelclass=\"WfiWordform\" virtualfield=\"HumanApprovedAnalyses\" computeeverytime=\"true\">" + "<dynamicloaderinfo assemblyPath=\"FDO.dll\" class=\"SIL.FieldWorks.FDO.FDOSequencePropertyVirtualHandler\"/>" + "</virtual>" + "<virtual modelclass=\"WfiWordform\" virtualfield=\"HumanNoOpinionParses\" computeeverytime=\"true\" requiresRealParserGeneratedData=\"true\">" + "<dynamicloaderinfo assemblyPath=\"FDO.dll\" class=\"SIL.FieldWorks.FDO.FDOSequencePropertyVirtualHandler\"/>" + "</virtual>" + "<virtual modelclass=\"WfiWordform\" virtualfield=\"HumanDisapprovedParses\" computeeverytime=\"true\">" + "<dynamicloaderinfo assemblyPath=\"FDO.dll\" class=\"SIL.FieldWorks.FDO.FDOSequencePropertyVirtualHandler\"/>" + "</virtual>" + "<virtual modelclass=\"WfiWordform\" virtualfield=\"FullConcordanceCount\" depends=\"OccurrencesInTexts\" computeeverytime=\"true\">" + "<dynamicloaderinfo assemblyPath=\"FDO.dll\" class=\"SIL.FieldWorks.FDO.IntegerPropertyVirtualHandler\"/>" + "</virtual>" + "<virtual modelclass=\"WfiWordform\" virtualfield=\"UserCount\" bulkLoadMethod=\"LoadAllUserCounts\" computeeverytime=\"true\">" + "<dynamicloaderinfo assemblyPath=\"FDO.dll\" class=\"SIL.FieldWorks.FDO.IntegerPropertyVirtualHandler\"/>" + "</virtual>" + "<virtual modelclass=\"WfiWordform\" virtualfield=\"ParserCount\" bulkLoadMethod=\"LoadAllParserCounts\" computeeverytime=\"true\" requiresRealParserGeneratedData=\"true\">" + "<dynamicloaderinfo assemblyPath=\"FDO.dll\" class=\"SIL.FieldWorks.FDO.IntegerPropertyVirtualHandler\"/>" + "</virtual>" + "<virtual modelclass=\"WfiWordform\" virtualfield=\"ConflictCount\" computeeverytime=\"true\" requiresRealParserGeneratedData=\"true\">" + "<dynamicloaderinfo assemblyPath=\"FDO.dll\" class=\"SIL.FieldWorks.FDO.IntegerPropertyVirtualHandler\"/>" + "</virtual>" + "<virtual modelclass=\"WordformInventory\" virtualfield=\"ConcordanceWords\" destinationClass=\"WfiWordform\">" + "<dynamicloaderinfo assemblyPath=\"ITextDll.dll\" class=\"SIL.FieldWorks.IText.ConcordanceWordsVirtualHandler\"/>" + "</virtual>" + "</virtuals>"); BaseVirtualHandler.InstallVirtuals(doc.DocumentElement, Cache); m_text = new Text(); Cache.LangProject.TextsOC.Add(m_text); string para1 = "Axx simplexx testxx withxx axx lotxx ofxx wordsxx endingxx inxx xx"; string para2 = "axx sentencexx axx havingxx axx lotxx ofxx axx"; m_para1 = new StTxtPara(); m_stText = new StText(); m_text.ContentsOA = m_stText; m_para1 = MakePara(para1); m_para2 = MakePara(para2); m_wfAxx = WfiWordform.CreateFromDBObject(Cache, WfiWordform.FindOrCreateWordform(Cache, "axx", Cache.DefaultVernWs, true)); // Make one real annotation, which also serves to link the Axx to this. m_cbaAxx = CmBaseAnnotation.CreateUnownedCba(Cache); m_cbaAxx.InstanceOfRA = m_wfAxx; m_cbaAxx.BeginObjectRA = m_para1; m_cbaAxx.BeginOffset = 0; m_cbaAxx.EndOffset = 3; m_cbaAxx.Flid = (int)StTxtPara.StTxtParaTags.kflidContents; m_cbaAxx.AnnotationTypeRA = CmAnnotationDefn.Twfic(Cache); // Make another real annotation, which should get updated during Apply. IWfiWordform wf2 = WfiWordform.CreateFromDBObject(Cache, WfiWordform.FindOrCreateWordform(Cache, "lotxx", Cache.DefaultVernWs, true)); m_cba2 = CmBaseAnnotation.CreateUnownedCba(Cache); m_cba2.InstanceOfRA = wf2; m_cba2.BeginObjectRA = m_para2; m_cba2.BeginOffset = "axx sentencexx axx havingxx axx ".Length; m_cba2.EndOffset = m_cba2.BeginOffset + "lotxx".Length; m_cba2.AnnotationTypeRA = CmAnnotationDefn.Twfic(Cache); m_cba2.Flid = (int)StTxtPara.StTxtParaTags.kflidContents; ParagraphParser.ConcordTexts(Cache, new int[] { m_stText.Hvo }, new NullProgressState()); m_axxOccurrences = m_wfAxx.ConcordanceIds; m_para1Occurrences = OccurrencesInPara(m_para1.Hvo, m_axxOccurrences); m_para2Occurrences = OccurrencesInPara(m_para2.Hvo, m_axxOccurrences); // to improve test isolation, be sure to null things not always initialized. m_wfaAxe = m_wfaCut = m_wfaCutIt = m_wfaNotRude = null; m_cAnalyses = 0; }
protected override void ValidateSegForms(object expectedSegForm, object actualSegForm, string segFormContext) { string msg = "Mismatched {0} in {1}."; // Get the paragraph string corresponding to the annotation. ICmBaseAnnotation cbaExpected = CmBaseAnnotation.CreateFromDBObject(m_cache, (int)expectedSegForm); // first make sure we have a txt item. if (IsLineEnabled(InterlinLineChoices.kflidWord)) { ITsString tssExpectedForm = m_para.Contents.UnderlyingTsString.GetSubstring(cbaExpected.BeginOffset, cbaExpected.EndOffset); string lang = "xkal"; // Review: get WsLabel from tssExpectedForm. string actualForm = ""; if (cbaExpected.AnnotationTypeRAHvo == TwficAnnotationType) { actualForm = m_reader.GetItemInnerText(actualSegForm as XmlNode, "txt", lang); } else if (cbaExpected.AnnotationTypeRAHvo == PunctuationAnnotationType) { actualForm = m_reader.GetItemInnerText(actualSegForm as XmlNode, "punct", lang); } Assert.AreEqual(tssExpectedForm.Text, actualForm, String.Format(msg, "word", segFormContext)); } // if WordGloss is enabled, verify it. if (IsLineEnabled(InterlinLineChoices.kflidWordGloss)) { string lang = "en"; string actualWordGloss = m_reader.GetItemInnerText(actualSegForm as XmlNode, "gls", lang); if (cbaExpected.AnnotationTypeRAHvo == PunctuationAnnotationType) { // must be a punctuation (non-wfic) Assert.AreEqual("", actualWordGloss); } else { WfiGloss expectedGloss = null; int clsId = m_cache.GetClassOfObject(cbaExpected.InstanceOfRAHvo); if (clsId == WfiGloss.kclsidWfiGloss) { expectedGloss = new WfiGloss(m_cache, cbaExpected.InstanceOfRAHvo); } else if (clsId == WfiWordform.kclsidWfiWordform) { // should be a twfic so get its guess. StTxtPara.TwficInfo cbaInfo = new StTxtPara.TwficInfo(m_cache, cbaExpected.Hvo); int hvoExpectedGloss = cbaInfo.GetGuess(); if (hvoExpectedGloss != 0) { expectedGloss = new WfiGloss(m_cache, hvoExpectedGloss); } } // TODO: There are cases for other classes (e.g. WfiAnalysis) but // the tests do not generate those right now, so we won't worry about them right now. if (expectedGloss != null) { Assert.AreEqual(expectedGloss.Form.AnalysisDefaultWritingSystem, actualWordGloss); } else { Assert.AreEqual("", actualWordGloss); } } } // validate morph bundle lines. if (IsLineEnabled(InterlinLineChoices.kflidMorphemes) || IsLineEnabled(InterlinLineChoices.kflidLexEntries) || IsLineEnabled(InterlinLineChoices.kflidLexGloss) || IsLineEnabled(InterlinLineChoices.kflidLexPos)) { // compare exported document to the LexEntries information in the WfiAnalysis int hvoWfiAnalysis = 0; if (cbaExpected.AnnotationTypeRAHvo != PunctuationAnnotationType) { hvoWfiAnalysis = WfiAnalysis.GetWfiAnalysisFromInstanceOf(m_cache, cbaExpected.Hvo); } List <XmlNode> morphNodes = m_reader.GetMorphNodes(actualSegForm as XmlNode); if (hvoWfiAnalysis == 0) { // make sure we don't have any morphs. Assert.IsEmpty(morphNodes); } else { IWfiAnalysis wfiAnalysis = WfiAnalysis.CreateFromDBObject(m_cache, hvoWfiAnalysis); foreach (WfiMorphBundle morphBundle in wfiAnalysis.MorphBundlesOS) { int iMorph = morphBundle.OwnOrd - 1; string morphContext = segFormContext + "/Morph(" + iMorph + ")"; XmlNode actualMorphNode = iMorph < morphNodes.Count ? morphNodes[iMorph] : null; if (actualMorphNode == null) { Assert.Fail(String.Format(msg, "missing morph", morphContext)); } ITsString tssLexEntry = null; int hvoMorph = morphBundle.MorphRAHvo; if (hvoMorph != 0) { // first test the morph form if (IsLineEnabled(InterlinLineChoices.kflidMorphemes)) { string actualMorphForm = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "txt", "xkal"); Assert.AreEqual(morphBundle.MorphRA.Form.VernacularDefaultWritingSystem, actualMorphForm, String.Format(msg, "morph/txt", morphContext)); } // next test the lex entry if (IsLineEnabled(InterlinLineChoices.kflidLexEntries)) { string actualLexEntry = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "cf", "xkal"); string actualHomograph = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "hn", "en"); string actualVariantTypes = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "variantTypes", "en"); tssLexEntry = InterlinDocChild.GetLexEntryTss(m_cache, morphBundle, m_cache.DefaultVernWs); Assert.AreEqual(tssLexEntry.Text, actualLexEntry + actualHomograph + actualVariantTypes, String.Format(msg, "morph/cf[hn|variantTypes]", morphContext)); } if (IsLineEnabled(InterlinLineChoices.kflidLexGloss)) { string actualLexGloss = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "gls", "en"); string expectedGloss = ""; if (morphBundle.SenseRA != null && morphBundle.SenseRA.Gloss != null) { expectedGloss = morphBundle.SenseRA.Gloss.AnalysisDefaultWritingSystem; } Assert.AreEqual(expectedGloss, actualLexGloss, String.Format(msg, "morph/gls", morphContext)); } if (IsLineEnabled(InterlinLineChoices.kflidLexPos)) { string actualLexMsa = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "msa", "en"); string expectedMsa = ""; if (morphBundle.SenseRA != null && morphBundle.SenseRA.MorphoSyntaxAnalysisRA != null) { expectedMsa = morphBundle.SenseRA.MorphoSyntaxAnalysisRA.InterlinearAbbr; } Assert.AreEqual(expectedMsa, actualLexMsa, String.Format(msg, "morph/msa", morphContext)); } } } Assert.AreEqual(wfiAnalysis.MorphBundlesOS.Count, morphNodes.Count); } } }