/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ public InternalFwMultiParaTextBox(IStText stText, IVwStylesheet styleSheet) { WritingSystemFactory = stText.Cache.WritingSystemFactory; CurrentWs = stText.Cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle; StyleSheet = styleSheet; AutoScroll = true; // Sandbox cache. var cda = VwCacheDaClass.Create(); cda.TsStrFactory = TsStringUtils.TsStrFactory; m_sda = cda; m_sda.WritingSystemFactory = WritingSystemFactory; m_sda.SetActionHandler(new SimpleActionHandler()); List <int> memHvos = new List <int>(); foreach (IStTxtPara para in stText.ParagraphsOS) { memHvos.Add(para.Hvo); m_sda.SetString(para.Hvo, StTxtParaTags.kflidContents, para.Contents); } // If no paragraphs were passed in, then create one to get the user started off. if (memHvos.Count == 0) { ITsString paraStr = TsStringUtils.EmptyString(CurrentWs); m_sda.SetString(kDummyParaHvo, StTxtParaTags.kflidContents, paraStr); memHvos.Add(kDummyParaHvo); } ((IVwCacheDa)m_sda).CacheVecProp(kMemTextHvo, StTextTags.kflidParagraphs, memHvos.ToArray(), memHvos.Count); }
/// <summary> /// Load the information about the domains of hvoEntry. Returns false /// if the entry has no associated domains or none of them are linked to any other entries. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry">int ID of the lexical entry</param> /// <param name="hvoSemanticDomainsOut">A list of int IDs of the semantic domains of the lexical entry</param> /// <param name="cdaTemp"></param> /// <returns></returns> static private bool LoadDomainInfo(FdoCache cache, int hvoEntry, out int[] hvoSemanticDomainsOut, out IVwCacheDa cdaTemp) { // REVIEW (SteveMiller): The LINQ below runs slow the first time its run. We should try to // optimize it if possible. var entryRepo = cache.ServiceLocator.GetInstance <ILexEntryRepository>(); var lexEntry = entryRepo.GetObject(hvoEntry); var domains = (from sense in lexEntry.AllSenses from sd in sense.SemanticDomainsRC where (from incoming in sd.ReferringObjects where incoming is ILexSense && incoming.OwnerOfClass <ILexEntry>() != lexEntry select incoming).FirstOrDefault() != null select sd).Distinct().ToArray(); hvoSemanticDomainsOut = ( from sd in domains select sd.Hvo).ToArray(); cdaTemp = VwCacheDaClass.Create(); foreach (var sd in domains) { cdaTemp.CacheStringProp(sd.Hvo, RelatedWordsVc.ktagName, sd.Name.BestVernacularAnalysisAlternative); } cdaTemp.CacheVecProp(hvoEntry, RelatedWordsVc.ktagDomains, hvoSemanticDomainsOut, hvoSemanticDomainsOut.Length); return(hvoSemanticDomainsOut.Length > 0); }
/// <summary> /// Clear all text. If fReconstruct is true, also clears the display. /// </summary> public void Clear(bool fReconstruct) { CheckDisposed(); if (m_sda == null) { var cda = VwCacheDaClass.Create(); cda.TsStrFactory = TsStringUtils.TsStrFactory; m_sda = cda; if (WritingSystemFactory != null) { m_sda.WritingSystemFactory = WritingSystemFactory; } m_cd = cda; } else { m_hvoNextPara = khvoFirstPara; m_cd.CacheVecProp(m_hvoRoot, (int)SampleTags.ktagTextParas, new int[0], 0); if (fReconstruct) { RootBox.Reconstruct(); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ public InternalFwMultiParaTextBox(IStText stText, IVwStylesheet styleSheet) { WritingSystemFactory = stText.Cache.LanguageWritingSystemFactoryAccessor; CurrentWs = stText.Cache.DefaultAnalWs; StyleSheet = styleSheet; AutoScroll = true; m_sda = VwCacheDaClass.Create() as ISilDataAccess; m_sda.WritingSystemFactory = WritingSystemFactory; List <int> memHvos = new List <int>(); foreach (IStTxtPara para in stText.ParagraphsOS) { memHvos.Add(para.Hvo); m_sda.SetString(para.Hvo, (int)StTxtPara.StTxtParaTags.kflidContents, para.Contents.UnderlyingTsString); } // If no paragraphs were passed in, then create one to get the user started off. if (memHvos.Count == 0) { ITsStrFactory strFact = TsStrFactoryClass.Create(); ITsString paraStr = strFact.MakeString(String.Empty, CurrentWs); m_sda.SetString(kDummyParaHvo, (int)StTxtPara.StTxtParaTags.kflidContents, paraStr); memHvos.Add(kDummyParaHvo); } ((IVwCacheDa)m_sda).CacheVecProp(kMemTextHvo, (int)StText.StTextTags.kflidParagraphs, memHvos.ToArray(), memHvos.Count); }
/// <summary> /// Create a new secondary cache. /// </summary> public void CreateSecCache() { CheckDisposed(); var cda = VwCacheDaClass.Create(); cda.TsStrFactory = TsStringUtils.TsStrFactory; DataAccess = cda; DataAccess.WritingSystemFactory = m_cache.WritingSystemFactory; }
public void TestSetup() { RegistryHelper.CompanyName = "SIL"; m_ISilDataAccess = VwCacheDaClass.Create(); ILgWritingSystemFactory wsf = new PalasoWritingSystemManager(); m_ISilDataAccess.WritingSystemFactory = wsf; m_IVwCacheDa = (IVwCacheDa)m_ISilDataAccess; }
/// <summary> /// Load the information about the domains of hvoEntry. Returns false /// if the entry has no associated domains or none of them are linked to any other entries. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry"></param> /// <param name="domains"></param> /// <param name="cdaTemp"></param> /// <param name="fMoreRows"></param> /// <param name="owner"></param> /// <returns></returns> static private bool LoadDomainInfo(FdoCache cache, int hvoEntry, out int[] domainsOut, out IVwCacheDa cdaTemp, IWin32Window owner) { // This produces first the Semantic domains of the senses of the entry, // then restricts to those that occur on some other entry, // then looks up the vernacular (or, if none, analysis) name of the domains. The are sorted by // domain name. // We do left outer joins for the last two so we can distinguish the failure // modes "no SDs on senses of initial entry" versus "no other entries in those SDs" string sql1 = string.Format("select lssd2.dst, cn.txt, cn.ws from LexEntry le" + " join LexSense_ ls on ls.owner$ = le.id" + " join LexSense_SemanticDomains lssd on lssd.src = ls.id " + " left outer join LexSense_SemanticDomains lssd2 on lssd2.dst = lssd.dst" + " and exists (select * from CmObject lsother" + " join LexEntry leother on leother.id = lsother.owner$ and lsother.id = lssd2.src and leother.id != le.id)" + " left outer join CmPossibility_Name cn on lssd2.dst = cn.obj and cn.ws" + " in ({0}, {1}) where le.id = {2}" + " group by lssd2.dst, cn.txt, cn.ws" + " order by cn.txt", cache.DefaultVernWs, cache.DefaultAnalWs, hvoEntry); IOleDbCommand odc = DbOps.MakeRowSet(cache, sql1, null); bool fGotSrcDomain = false; // true if we found a semantic domain on some sense of the source entry try { bool fMoreRows; List <int> domains = new List <int>(); cdaTemp = VwCacheDaClass.Create(); for (odc.NextRow(out fMoreRows); fMoreRows; odc.NextRow(out fMoreRows)) { fGotSrcDomain = true; // any row indicates success here. int hvoDomain = DbOps.ReadInt(odc, 0); if (hvoDomain == 0) { continue; // null row, an SD that occurs on no other entry. } if (!((ISilDataAccess)cdaTemp).get_IsPropInCache(hvoDomain, RelatedWordsVc.ktagName, (int)CellarModuleDefns.kcptString, 0)) { ITsString tss = DbOps.ReadTss2(odc, 1); if (tss == null) { tss = FDO.Cellar.CmPossibility.BestAnalysisOrVernName(cache, hvoDomain); } cdaTemp.CacheStringProp(hvoDomain, RelatedWordsVc.ktagName, tss); domains.Add(hvoDomain); } } domainsOut = DbOps.ListToIntArray(domains); } finally { DbOps.ShutdownODC(ref odc); } return(fGotSrcDomain); }
public void TestSetup() { var cda = VwCacheDaClass.Create(); cda.TsStrFactory = TsStringUtils.TsStrFactory; m_ISilDataAccess = cda; ILgWritingSystemFactory wsf = new WritingSystemManager(); m_ISilDataAccess.WritingSystemFactory = wsf; m_IVwCacheDa = cda; }
public void SetUp() { CheckDisposed(); m_ISilDataAccess = VwCacheDaClass.Create(); // It must have a writing system factory: for testing, use the memory based one. ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create(); // For these tests we don't need to run InstallLanguage. wsf.BypassInstall = true; m_ISilDataAccess.WritingSystemFactory = wsf; }
/// ------------------------------------------------------------------------------------- /// <summary> /// Default constructor /// </summary> /// ------------------------------------------------------------------------------------- public BulletsPreview() { m_CacheDa = VwCacheDaClass.Create(); m_DataAccess = (ISilDataAccess)m_CacheDa; m_vc = new BulletsPreviewVc(); // So many things blow up so badly if we don't have one of these that I finally decided to just // make one, even though it won't always, perhaps not often, be the one we want. CreateTempWritingSystemFactory(); m_DataAccess.WritingSystemFactory = WritingSystemFactory; VScroll = false; // no vertical scroll bar visible. AutoScroll = false; // not even if the root box is bigger than the window. }
public void GetBestGloss() { var wf = Cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(); var wa = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>().Create(); wf.AnalysesOC.Add(wa); var sda = VwCacheDaClass.Create(); var wsIds = new List <int>(); wsIds.Add(Cache.DefaultAnalWs); int hvoAbc = 123456; // Basic check: no glosses, we don't find any. Assert.That(SandboxBase.GetRealAnalysisMethod.GetBestGloss(wa, wsIds, sda, hvoAbc), Is.Null); // Only possibility, everything blank, we want it. var wgAbc = Cache.ServiceLocator.GetInstance <IWfiGlossFactory>().Create(); wa.MeaningsOC.Add(wgAbc); Assert.That(SandboxBase.GetRealAnalysisMethod.GetBestGloss(wa, wsIds, sda, hvoAbc), Is.EqualTo(wgAbc)); // Looking for a particular string and not finding one that has it, we fail sda.CacheStringAlt(hvoAbc, SandboxBase.ktagSbWordGloss, Cache.DefaultAnalWs, MakeAnalysisString("abc")); Assert.That(SandboxBase.GetRealAnalysisMethod.GetBestGloss(wa, wsIds, sda, hvoAbc), Is.Null); // Likewise, we won't return a gloss that has relevant alternatives, even if all the desired strings are empty. // (An easy way to have all the SDA strings be empty is to use a different HVO.) sda.CacheStringAlt(hvoAbc, SandboxBase.ktagSbWordGloss, Cache.DefaultAnalWs, MakeAnalysisString("abc")); wgAbc.Form.AnalysisDefaultWritingSystem = MakeAnalysisString("abc"); Assert.That(SandboxBase.GetRealAnalysisMethod.GetBestGloss(wa, wsIds, sda, 27), Is.Null); // Simple success: the one and only WS matches. Assert.That(SandboxBase.GetRealAnalysisMethod.GetBestGloss(wa, wsIds, sda, hvoAbc), Is.EqualTo(wgAbc)); // It matches even if there is another, empty one. var wgDef = Cache.ServiceLocator.GetInstance <IWfiGlossFactory>().Create(); wa.MeaningsOC.Add(wgDef); Assert.That(SandboxBase.GetRealAnalysisMethod.GetBestGloss(wa, wsIds, sda, hvoAbc), Is.EqualTo(wgAbc)); // Also if there is another one with a different value for the form wgDef.Form.AnalysisDefaultWritingSystem = MakeAnalysisString("def"); Assert.That(SandboxBase.GetRealAnalysisMethod.GetBestGloss(wa, wsIds, sda, hvoAbc), Is.EqualTo(wgAbc)); // We can also find the def one. int hvoDef = 123457; sda.CacheStringAlt(hvoDef, SandboxBase.ktagSbWordGloss, Cache.DefaultAnalWs, MakeAnalysisString("def")); Assert.That(SandboxBase.GetRealAnalysisMethod.GetBestGloss(wa, wsIds, sda, hvoDef), Is.EqualTo(wgDef)); // Now trying to match two writing systems. One with both correct should beat one with only one correct. var wgAbc3 = Cache.ServiceLocator.GetInstance <IWfiGlossFactory>().Create(); wa.MeaningsOC.Add(wgAbc3); wgAbc3.Form.AnalysisDefaultWritingSystem = MakeAnalysisString("abc"); var wsSpn = Cache.WritingSystemFactory.get_Engine("es").Handle; var wsFrn = Cache.WritingSystemFactory.get_Engine("fr").Handle; wgAbc3.Form.set_String(wsSpn, Cache.TsStrFactory.MakeString("abcS", wsSpn)); wgAbc3.Form.set_String(wsFrn, Cache.TsStrFactory.MakeString("abcF", wsFrn)); wsIds.Add(wsSpn); sda.CacheStringAlt(hvoAbc, SandboxBase.ktagSbWordGloss, wsSpn, Cache.TsStrFactory.MakeString("abcS", wsSpn)); Assert.That(SandboxBase.GetRealAnalysisMethod.GetBestGloss(wa, wsIds, sda, hvoAbc), Is.EqualTo(wgAbc3)); // Of two partial matches, prefer the one where other alternatives are empty. // wgAbc2, wgAbc3 both match on English and Spanish. Neither matches on French, but wgAbc2 has no French // at all and is thus a better match. var wgAbc2 = Cache.ServiceLocator.GetInstance <IWfiGlossFactory>().Create(); wa.MeaningsOC.Add(wgAbc2); wgAbc2.Form.AnalysisDefaultWritingSystem = MakeAnalysisString("abc"); wgAbc2.Form.set_String(wsSpn, Cache.TsStrFactory.MakeString("abcS", wsSpn)); wsIds.Add(wsFrn); sda.CacheStringAlt(hvoAbc, SandboxBase.ktagSbWordGloss, wsFrn, Cache.TsStrFactory.MakeString("abcOther", wsFrn)); Assert.That(SandboxBase.GetRealAnalysisMethod.GetBestGloss(wa, wsIds, sda, hvoAbc), Is.EqualTo(wgAbc2)); // Of two perfect matches, we prefer the one that has no other information. wsIds.Remove(wsFrn); Assert.That(SandboxBase.GetRealAnalysisMethod.GetBestGloss(wa, wsIds, sda, hvoAbc), Is.EqualTo(wgAbc2)); // We will not return one where the WfiGloss has a relevant non-empty alternative, even if the corresponding target is empty. sda.CacheStringAlt(hvoAbc, SandboxBase.ktagSbWordGloss, wsSpn, Cache.TsStrFactory.MakeString("", wsSpn)); wa.MeaningsOC.Remove(wgAbc); Assert.That(SandboxBase.GetRealAnalysisMethod.GetBestGloss(wa, wsIds, sda, hvoAbc), Is.Null); }
public void Setup() { // Create the following: // - part and layout inventories // - metadata cache // - DataAccess cache // - collection of columns to display. // We want a MetaDataCache that knows about // - LexEntry.Senses, Msas, CitationForm, Bibliography, Etymology // - LexSense.SemanticDomains, SenseType, Status, gloss // - CmPossibility Name, abbr // - MoMorphSynAnalysis // - MoStemMsa // - MoDerivationalMsa string m_sTestPath = Path.Combine(DirectoryFinder.FwSourceDirectory, Path.Combine("Common", Path.Combine("Controls", Path.Combine("XMLViews", Path.Combine("XMLViewsTests", "SampleCm.xml"))))); m_mdc = MetaDataCache.CreateMetaDataCache(m_sTestPath); // We want ISilDataAccess with: // - LexEntry (1) with no senses and one MSA (2) // - LexEntry (4) with one sense (5) and no MSA // - LexEntry (6) with three senses (7, 8, 9) and two MSAs (10, 11) // - sense(5) with no semantic domains // - senses with one SD (7->30, 8->31) // - sense with three SDs, one the same as the first (9->30, 31, 32) // - MoStemMsa (2, 11) // - MoDerivationalMsa (10) m_cda = VwCacheDaClass.Create(); m_sda = m_cda as ISilDataAccess; m_wsManager = new PalasoWritingSystemManager(); m_sda.WritingSystemFactory = m_wsManager; var parser = new SimpleDataParser(m_mdc, m_cda); parser.Parse(Path.Combine(DirectoryFinder.FwSourceDirectory, Path.Combine("Common", Path.Combine("Controls", Path.Combine("XMLViews", Path.Combine("XMLViewsTests", "SampleData.xml")))))); int wsEn = m_wsManager.GetWsFromStr("en"); // These are mainly to check out the parser. Assert.AreEqual(3, m_sda.get_ObjectProp(2, 23011), "part of speech of an MoStemMsa"); Assert.AreEqual(2, m_sda.get_VecItem(1, 2009, 0), "owned msa"); Assert.AreEqual("noun", m_sda.get_MultiStringAlt(3, 7003, wsEn).Text, "got ms property"); Assert.AreEqual(9, m_sda.get_VecItem(6, 2010, 2), "3rd sense"); Assert.AreEqual(31, m_sda.get_VecItem(9, 21016, 1), "2nd semantic domain"); // Columns includes // - CitationForm (string inside span) // - Bibliography (string not in span) // - Sense glosses (string in para in seq, nested in column element) // - Semantic domains (pair of strings in para in seq in seq, using layout refs) // - MSAs (simplified, but polymorphic with one having <choice> and one <obj> to CmPossibility XmlDocument docColumns = new XmlDocument(); docColumns.Load(Path.Combine(DirectoryFinder.FwSourceDirectory, Path.Combine("Common", Path.Combine("Controls", Path.Combine("XMLViews", Path.Combine("XMLViewsTests", "TestColumns.xml")))))); m_columnList = docColumns.DocumentElement.ChildNodes; // Parts just has what those columns need. string partDirectory = Path.Combine(DirectoryFinder.FwSourceDirectory, Path.Combine("Common", Path.Combine("Controls", Path.Combine("XMLViews", "XMLViewsTests")))); Dictionary <string, string[]> keyAttrs = new Dictionary <string, string[]>(); keyAttrs["layout"] = new string[] { "class", "type", "name" }; keyAttrs["group"] = new string[] { "label" }; keyAttrs["part"] = new string[] { "ref" }; // Currently there are no specialized layout files that match. m_layoutInventory = new Inventory(new string[] { partDirectory }, "*.fwlayout", "/LayoutInventory/*", keyAttrs, "TestManyOneBrowse", "ProjectPath"); keyAttrs = new Dictionary <string, string[]>(); keyAttrs["part"] = new string[] { "id" }; m_partInventory = new Inventory(new string[] { partDirectory }, "TestParts.xml", "/PartInventory/bin/*", keyAttrs, "TestManyOneBrowse", "ProjectPath"); m_layouts = new LayoutCache(m_mdc, m_layoutInventory, m_partInventory); }