/// <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; }
/// <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; }
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)); }
public void CheckAgentCounts() { CheckDisposed(); int hvoWf = m_fdoCache.LangProject.WordformInventoryOA.WordformsOC.HvoArray[0]; IWfiWordform wf = WfiWordform.CreateFromDBObject(m_fdoCache, hvoWf); int cOldUser = wf.UserCount; int cOldParse = wf.ParserCount; WfiAnalysis wa1 = new WfiAnalysis(); WfiAnalysis wa2 = new WfiAnalysis(); wf.AnalysesOC.Add(wa1); wf.AnalysesOC.Add(wa2); ICmAgent ca = m_fdoCache.LangProject.DefaultParserAgent; ca.SetEvaluation(wa1.Hvo, 1, ""); ca = m_fdoCache.LangProject.DefaultUserAgent; ca.SetEvaluation(wa2.Hvo, 1, ""); int cNewUser = wf.UserCount; int cNewParse = wf.ParserCount; Assert.IsTrue(cOldUser + 1 == cNewUser, "UserCount wrong: Expected " + cNewUser + " but got " + (cOldUser + 1)); Assert.IsTrue(cOldParse + 1 == cNewParse, "ParserCount wrong: Expected " + cNewParse + " but got " + (cOldParse + 1)); }
private void FinishSettingAnalysis(int hvoNewAnalysis, int hvoOldAnalysisBackup) { if (hvoNewAnalysis == hvoOldAnalysisBackup) return; List<int> msaHvoList = new List<int>(); int wfAnalHvo = FocusBox.InterlinWordControl.GetWfiAnalysisHvoOfAnalysis(hvoOldAnalysisBackup); IWfiAnalysis anal = null; if (wfAnalHvo != 0) { anal = new WfiAnalysis(m_fdoCache, wfAnalHvo); anal.CollectReferencedMsaHvos(msaHvoList); } // Collecting for the new analysis is probably overkill, since the MissingEntries combo will only have MSAs // that are already referenced outside of the focus box (namely by the Senses). It's unlikely, therefore, // that we could configure the Focus Box in such a state as to remove the last link to an MSA in the // new analysis. But just in case it IS possible... wfAnalHvo = FocusBox.InterlinWordControl.GetWfiAnalysisHvoOfAnalysis(hvoNewAnalysis); if (wfAnalHvo != 0) { anal = new WfiAnalysis(m_fdoCache, wfAnalHvo); anal.CollectReferencedMsaHvos(msaHvoList); // Make sure this analysis is marked as user-approved (green check mark) m_fdoCache.LangProject.DefaultUserAgent.SetEvaluation(wfAnalHvo, 1, ""); } MoMorphSynAnalysis.DeleteUnusedMsas(m_fdoCache, msaHvoList); // if we can't find any instances to the old wordform, try to delete // a redundant capitalized form. if (Cache.GetClassOfObject(hvoOldAnalysisBackup) == WfiWordform.kclsidWfiWordform) { bool fInstanceOfFound = false; foreach (int hvoInstanceOf in GetNextInstanceOf()) { if (hvoInstanceOf == hvoOldAnalysisBackup) { fInstanceOfFound = true; break; } } if (!fInstanceOfFound) WfiWordform.DeleteRedundantCapitalizedWordform(m_fdoCache, hvoOldAnalysisBackup); } else if (!m_fdoCache.IsDummyObject(hvoOldAnalysisBackup)) { // not a wordform analysis DeleteIfUnattested(hvoOldAnalysisBackup); } // if we're switching to a different annotation, save that information, // so that we can move the sandbox back to the annotation being undone. }
private IWfiAnalysis CreateWfiAnalysisForTwfic(int hvoCbaActual) { int hvoActualInstanceOf; IWfiWordform actualWordform; GetRealWordformInfo(hvoCbaActual, out hvoActualInstanceOf, out actualWordform); // Create a new WfiAnalysis for the wordform. IWfiAnalysis actualWfiAnalysis = new WfiAnalysis(); actualWordform.AnalysesOC.Add(actualWfiAnalysis); return actualWfiAnalysis; }
/// <summary> /// This goes through the collected list of WfiWordforms that do not have any analyses, and generates /// a guess for any whose forms exactly match a LexemeForm (or AlternateForm) of a stem/root entry. /// </summary> /// <param name="progress"></param> private void AddEntryGuesses(ProgressState progress) { if (m_rgEmptyWfis.Count == 0) return; MapEmptyWfToInfo(); progress.Breath(); if (m_mapEmptyWfInfo.Count == 0) return; foreach (EmptyWwfAnno ewa in m_rgEmptyWfis) { IWfiWordform ww = WfiWordform.CreateFromDBObject(m_cache, ewa.m_hvoWwf); EmptyWwfKey key = new EmptyWwfKey(ww.Hvo, ewa.m_ws); EmptyWwfInfo info; if (!m_mapEmptyWfInfo.TryGetValue(key, out info)) continue; IWfiAnalysis wa; if (ww.AnalysesOC.Count == 0) { ITsString tssName = null; int wsVern = 0; ILexEntryRef ler = SandboxBase.GetVariantRef(m_cache, info.m_hvoEntry, true); int hvoEntryToDisplay = info.m_hvoEntry; if (ler != null) { ICmObject coRef = ler.ComponentLexemesRS[0]; if (coRef is ILexSense) hvoEntryToDisplay = (coRef as ILexSense).EntryID; else hvoEntryToDisplay = coRef.Hvo; wsVern = StringUtils.GetWsAtOffset(m_tssPara, 0); tssName = InterlinDocChild.GetLexEntryTss(Cache, hvoEntryToDisplay, wsVern, ler); info.m_hvoSense = m_cache.MainCacheAccessor.get_VecItem(hvoEntryToDisplay, (int)LexEntry.LexEntryTags.kflidSenses, 0); info.m_hvoMsa = m_cache.MainCacheAccessor.get_ObjectProp(info.m_hvoSense, (int)LexSense.LexSenseTags.kflidMorphoSyntaxAnalysis); int clidMsa = m_cache.GetClassOfObject(info.m_hvoMsa); if (info.m_hvoPOS == 0) { info.m_hvoPOS = m_cache.MainCacheAccessor.get_ObjectProp(info.m_hvoMsa, (int)MoStemMsa.MoStemMsaTags.kflidPartOfSpeech); } } wa = new WfiAnalysis(); ww.AnalysesOC.Add(wa); wa.CategoryRAHvo = info.m_hvoPOS; WfiGloss wg = new WfiGloss(); wa.MeaningsOC.Add(wg); // Not all entries have senses. if (info.m_hvoSense != 0) { MultiUnicodeAccessor muaGloss = new MultiUnicodeAccessor(m_cache, info.m_hvoSense, /* ls.Id */ (int)LexSense.LexSenseTags.kflidGloss, "LexSense_Gloss"); wg.Form.MergeAlternatives(muaGloss); } WfiMorphBundle wmb = new WfiMorphBundle(); wa.MorphBundlesOS.Append(wmb); wmb.MorphRAHvo = info.m_hvoForm; if (tssName != null && wsVern != 0) wmb.Form.SetAlternative(tssName, wsVern); wmb.MsaRAHvo = info.m_hvoMsa; wmb.SenseRAHvo = info.m_hvoSense; // Now, set up an approved "Computer" evaluation of this generated analysis wa.SetAgentOpinion(m_cache.LangProject.DefaultComputerAgent, Opinions.approves); } else { // The same unanalyzed word may occur twice in a paragraph... wa = ww.AnalysesOC.ToArray()[0]; Debug.Assert(ww.AnalysesOC.Count == 1); Debug.Assert(wa.CategoryRAHvo == info.m_hvoPOS); Debug.Assert(wa.MorphBundlesOS.Count == 1); Debug.Assert(wa.MorphBundlesOS[0].MorphRAHvo == info.m_hvoForm); Debug.Assert(wa.MorphBundlesOS[0].MsaRAHvo == info.m_hvoMsa); Debug.Assert(wa.MorphBundlesOS[0].SenseRAHvo == info.m_hvoSense); } } progress.Breath(); }
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> /// 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; }
/// <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; }
// 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; }