/// <summary> /// Select the word indicated by the text-wordform-in-context (twfic) annotation. /// This ignores the Sandbox! This is 'public' because it overrides a public method. /// </summary> /// <param name="hvoAnn"></param> public override void SelectAnnotation(int hvoAnn) { ISilDataAccess sda = Cache.MainCacheAccessor; // We should assert that ann is Twfic int twficType = CmAnnotationDefn.Twfic(Cache).Hvo; int annoType = sda.get_ObjectProp(hvoAnn, (int)CmAnnotation.CmAnnotationTags.kflidAnnotationType); Debug.Assert(annoType == twficType, "Given annotation type should be twfic(" + twficType + ") but was " + annoType + "."); // The following will select the Twfic, ... I hope! // Scroll to selection into view IVwSelection sel = SelectWficInIText(hvoAnn); if (sel == null) { return; } if (!this.Focused) { this.Focus(); } this.ScrollSelectionIntoView(sel, VwScrollSelOpts.kssoTop); Update(); }
// 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); }
/// <summary> /// Return the next wfics that have not yet been added to the chart (up to maxContext of them). /// </summary> /// <param name="maxContext"></param> /// <returns></returns> public static int[] NextUnusedInput(FdoCache cache, int hvoStText, int maxContext, int hvoChart) { int hvoWficDefn = CmAnnotationDefn.Twfic(cache).Hvo; int hvoCcaDefn = CmAnnotationDefn.ConstituentChartAnnotation(cache).Hvo; // First two lines yield annotations on the right text of the right type (wfics). // balance further limits it to uncharted ones string sql = "select top(" + maxContext + ") cba.id, stp.owner$ from CmBaseAnnotation_ cba" + " join StTxtPara_ stp on cba.BeginObject = stp.id and cba.AnnotationType = " + hvoWficDefn + " and stp.OwnFlid$ = 14001 and stp.Owner$ = " + hvoStText + " where not exists(Select * from DsConstChart_Rows row" + " join CmIndirectAnnotation_AppliesTo row_cca on row_cca.src = row.Dst and row.Src = " + hvoChart + " join CmIndirectAnnotation_AppliesTo cca_cba on cca_cba.src = row_cca.dst and cca_cba.Dst = cba.id)" + " order by stp.OwnOrd$, cba.BeginOffset"; return(DbOps.ReadIntArrayFromCommand(cache, sql, null)); }
/// <summary> /// Return the hvo for theCmBaseAnnotation that /// matches the given boundaries in an StTxtPara object. /// If no exact match is found, return the nearest segment (preferably the following word). /// </summary> /// <param name="hvoStTxtPara"></param> /// <param name="ichMin"></param> /// <param name="ichLim"></param> /// <param name="fOnlyTWFIC">true, if restricted to TWFIC</param> /// <param name="fExactMatch"> true if we return an exact match, false otherwise.</param> /// <returns>hvo is 0 if not found.</returns> static internal int FindAnnotationHvoForStTxtPara(FdoCache cache, int hvoStTxtPara, int ichMin, int ichLim, bool fOnlyTWFIC, out bool fExactMatch) { int twficType = CmAnnotationDefn.Twfic(cache).Hvo; int textSegType = CmAnnotationDefn.TextSegment(cache).Hvo; fExactMatch = false; int clsid = cache.GetClassOfObject(hvoStTxtPara); if (clsid != StTxtPara.kClassId) { Debug.Assert(clsid != StTxtPara.kClassId, "hvoStTxtPara should be of class StTxtPara."); return(0); } int kflidParaSegment = InterlinVc.ParaSegmentTag(cache); ISilDataAccess sda = cache.MainCacheAccessor; // first find the closest segment. int[] segments = cache.GetVectorProperty(hvoStTxtPara, kflidParaSegment, true); ICmBaseAnnotation cbaClosestSeg = FindClosestAnnotation(cache, segments, textSegType, ichMin, ichLim, out fExactMatch); if (cbaClosestSeg == null) { return(0); } // if it was an exact match for a segment, return it. if (cbaClosestSeg != null && fExactMatch && !fOnlyTWFIC) { return(cbaClosestSeg.Hvo); } // otherwise, see if we can find a closer wordform int[] segmentForms = cache.GetVectorProperty(cbaClosestSeg.Hvo, InterlinVc.SegmentFormsTag(cache), true); ICmBaseAnnotation cbaClosestWf = FindClosestAnnotation(cache, segmentForms, twficType, ichMin, ichLim, out fExactMatch); if (cbaClosestWf == null) { return(fOnlyTWFIC ? 0 : cbaClosestSeg.Hvo); } return(cbaClosestWf.Hvo); }
public TestTaggingChild(FdoCache cache) { Cache = cache; m_textTagAnnDefn = CmAnnotationDefn.TextMarkupTag(Cache).Hvo; m_twficAnnDefn = CmAnnotationDefn.Twfic(Cache).Hvo; }
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; }