public override void TestSetup() { base.TestSetup(); m_vc = new StVc(); m_vc.Cache = Cache; m_pattern = VwPatternClass.Create(); m_pattern.Pattern = TsStringUtils.MakeString("a", Cache.DefaultVernWs); m_pattern.MatchOldWritingSystem = false; m_pattern.MatchDiacritics = false; m_pattern.MatchWholeWord = false; m_pattern.MatchCase = false; m_pattern.UseRegularExpressions = false; IScrBook genesis = AddBookWithTwoSections(1, "Genesis"); m_section = genesis.SectionsOS[0]; // Add paragraphs (because we use an StVc in the test we add them all to the same section) m_para1 = AddParaToMockedSectionContent(m_section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(m_para1, "This is some text so that we can test the find functionality.", null); m_para2 = AddParaToMockedSectionContent(m_section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(m_para2, "Some more text so that we can test the find and replace functionality.", null); m_para3 = AddParaToMockedSectionContent( m_section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(m_para3, "This purugruph doesn't contuin the first letter of the ulphubet.", null); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:SimpleMatchDlg"/> class. /// </summary> /// <param name="wsf">The WSF.</param> /// <param name="ws">The ws.</param> /// <param name="ss">The ss.</param> /// ------------------------------------------------------------------------------------ public SimpleMatchDlg(ILgWritingSystemFactory wsf, int ws, IVwStylesheet ss) { // // Required for Windows Form Designer support // InitializeComponent(); // We do this outside the designer-controlled code because it does funny things // to FwTextBoxes, owing to the need for a writing system factory, and some // properties it should not persist but I can't persuade it not to. this.m_textBox = new FwTextBox(); this.m_textBox.WritingSystemFactory = wsf; // set ASAP. this.m_textBox.WritingSystemCode = ws; this.m_textBox.StyleSheet = ss; // before setting text, otherwise it gets confused about height needed. this.m_textBox.Location = new System.Drawing.Point(8, 24); this.m_textBox.Name = "m_textBox"; this.m_textBox.Size = new System.Drawing.Size(450, 32); this.m_textBox.TabIndex = 0; this.m_textBox.Text = ""; this.Controls.Add(this.m_textBox); regexContextMenu = new RegexHelperMenu(m_textBox, FwApp.App); m_ivwpattern = VwPatternClass.Create(); helpProvider = new System.Windows.Forms.HelpProvider(); helpProvider.HelpNamespace = FwApp.App.HelpFile; helpProvider.SetHelpKeyword(this, FwApp.App.GetHelpString(s_helpTopic, 0)); helpProvider.SetHelpNavigator(this, System.Windows.Forms.HelpNavigator.Topic); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes for replace all: creates a view constructor to be used with replace all /// as well as initial settings for the pattern. /// </summary> /// ------------------------------------------------------------------------------------ private void InitializeForReplaceAll() { m_vc = new TeStVc(TeStVc.LayoutViewTarget.targetDraft, 0); m_vc.Cache = Cache; m_pattern = VwPatternClass.Create(); m_strFactory = TsStrFactoryClass.Create(); m_pattern.MatchOldWritingSystem = false; m_pattern.MatchDiacritics = false; m_pattern.MatchWholeWord = false; m_pattern.MatchCase = false; m_pattern.UseRegularExpressions = false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes for replace all: creates a view constructor to be used with replace all /// as well as initial settings for the pattern. /// </summary> /// ------------------------------------------------------------------------------------ private void InitializeForReplaceAll() { // REVIEW: do we need to create m_vc? We don't seem to use it anywhere. m_vc = new TeStVc(TeStVc.LayoutViewTarget.targetDraft, 0); m_vc.Cache = Cache; m_pattern = VwPatternClass.Create(); m_strFactory = TsStrFactoryClass.Create(); m_pattern.MatchOldWritingSystem = false; m_pattern.MatchDiacritics = false; m_pattern.MatchWholeWord = false; m_pattern.MatchCase = false; m_pattern.UseRegularExpressions = false; }
public void UpdateConcordanceForCustomField_FindsMatches() { // build pre-existing data var sl = Cache.ServiceLocator; var wsf = Cache.WritingSystemFactory; var mdc = Cache.ServiceLocator.GetInstance <IFwMetaDataCacheManaged>(); IWfiWordform word = null; ITsString para1_1Contents = null; Guid segGuid = new Guid(); NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () => { mdc.AddCustomField("Segment", "test1", CellarPropertyType.String, 0, "just testing", Cache.DefaultAnalWs, Guid.Empty); var text1 = MakeText("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA", "Sentence one. Sentence 2."); var sttext1 = text1.ContentsOA; var para1_1 = sttext1.ParagraphsOS[0] as IStTxtPara; var segment1_1_1 = para1_1.SegmentsOS[0]; var testFlid = mdc.GetFieldId("Segment", "test1", false); Cache.MainCacheAccessor.SetString(segment1_1_1.Hvo, testFlid, TsStringUtils.MakeString("the big bad wolf", Cache.DefaultAnalWs)); var text2 = MakeText("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAB", "Another Sentence one. Another Sentence 2."); var sttext2 = text2.ContentsOA; var para2_1 = sttext2.ParagraphsOS[0] as IStTxtPara; var segment2_1_2 = para2_1.SegmentsOS[1]; Cache.MainCacheAccessor.SetString(segment2_1_2.Hvo, testFlid, TsStringUtils.MakeString("the nice big dog", Cache.DefaultAnalWs)); var segment2_1_1 = para2_1.SegmentsOS[0]; Cache.MainCacheAccessor.SetString(segment2_1_1.Hvo, testFlid, TsStringUtils.MakeString("the small furry cat", Cache.DefaultAnalWs)); var paragraphs = new HashSet <IStTxtPara>(); paragraphs.Add(para1_1); paragraphs.Add(para2_1); var vwPattern = VwPatternClass.Create(); vwPattern.Pattern = TsStringUtils.MakeString("big", Cache.DefaultAnalWs); var matcher = new RegExpMatcher(vwPattern); var result = ConcordanceControl.GetOccurrencesInCustomField(testFlid, paragraphs, Cache.MainCacheAccessor, matcher); Assert.That(result, Has.Count.EqualTo(2)); Assert.That(result.Any(pf => pf.Segment == segment1_1_1)); Assert.That(result.Any(pf => pf.Segment == segment2_1_2)); }); }
public override void Initialize() { CheckDisposed(); base.Initialize(); m_vc = new StVc(); m_vc.Cache = Cache; m_pattern = VwPatternClass.Create(); m_strFactory = TsStrFactoryClass.Create(); m_pattern.Pattern = m_strFactory.MakeString("a", Cache.DefaultVernWs); m_pattern.MatchOldWritingSystem = false; m_pattern.MatchDiacritics = false; m_pattern.MatchWholeWord = false; m_pattern.MatchCase = false; m_pattern.UseRegularExpressions = false; }
public void PersistMatchersEtc() { // BaseMatcher is abstract // IntMatcher is abstract RangeIntMatcher rangeIntMatch = new RangeIntMatcher(5, 23); rangeIntMatch.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor; ITsString tssLabel = m_cache.MakeAnalysisTss("label1"); rangeIntMatch.Label = tssLabel; OwnIntPropFinder ownIntFinder = new OwnIntPropFinder(m_sda, 551); FilterBarCellFilter rangeIntFilter = new FilterBarCellFilter(ownIntFinder, rangeIntMatch); AndFilter andFilter = new AndFilter(); andFilter.Add(rangeIntFilter); ITsStrFactory tsf = TsStrFactoryClass.Create(); int ws = m_cache.DefaultAnalWs; IVwPattern m_pattern = VwPatternClass.Create(); m_pattern.MatchOldWritingSystem = false; m_pattern.MatchDiacritics = false; m_pattern.MatchWholeWord = false; m_pattern.MatchCase = false; m_pattern.UseRegularExpressions = false; andFilter.Add(new FilterBarCellFilter(ownIntFinder, new NotEqualIntMatcher(77))); OwnMlPropFinder mlPropFinder = new OwnMlPropFinder(m_cache.MainCacheAccessor, 788, 23); m_pattern.Pattern = tsf.MakeString("hello", ws); andFilter.Add(new FilterBarCellFilter(mlPropFinder, new ExactMatcher(m_pattern))); OwnMonoPropFinder monoPropFinder = new OwnMonoPropFinder(m_cache.MainCacheAccessor, 954); m_pattern = VwPatternClass.Create(); m_pattern.MatchOldWritingSystem = false; m_pattern.MatchDiacritics = false; m_pattern.MatchWholeWord = false; m_pattern.MatchCase = false; m_pattern.UseRegularExpressions = false; m_pattern.Pattern = tsf.MakeString("goodbye", ws); andFilter.Add(new FilterBarCellFilter(monoPropFinder, new BeginMatcher(m_pattern))); OneIndirectMlPropFinder oneIndMlPropFinder = new OneIndirectMlPropFinder(m_cache.MainCacheAccessor, 221, 222, 27); m_pattern = VwPatternClass.Create(); m_pattern.MatchOldWritingSystem = false; m_pattern.MatchDiacritics = false; m_pattern.MatchWholeWord = false; m_pattern.MatchCase = false; m_pattern.UseRegularExpressions = false; m_pattern.Pattern = tsf.MakeString("exit", ws); andFilter.Add(new FilterBarCellFilter(oneIndMlPropFinder, new EndMatcher(m_pattern))); MultiIndirectMlPropFinder mimlPropFinder = new MultiIndirectMlPropFinder( m_cache.MainCacheAccessor, new int[] { 444, 555 }, 666, 87); m_pattern = VwPatternClass.Create(); m_pattern.MatchOldWritingSystem = false; m_pattern.MatchDiacritics = false; m_pattern.MatchWholeWord = false; m_pattern.MatchCase = false; m_pattern.UseRegularExpressions = false; m_pattern.Pattern = tsf.MakeString("whatever", ws); andFilter.Add(new FilterBarCellFilter(mimlPropFinder, new AnywhereMatcher(m_pattern))); OneIndirectAtomMlPropFinder oneIndAtomFinder = new OneIndirectAtomMlPropFinder(m_cache.MainCacheAccessor, 543, 345, 43); andFilter.Add(new FilterBarCellFilter(oneIndAtomFinder, new BlankMatcher())); andFilter.Add(new FilterBarCellFilter(oneIndAtomFinder, new NonBlankMatcher())); m_pattern = VwPatternClass.Create(); m_pattern.MatchOldWritingSystem = false; m_pattern.MatchDiacritics = false; m_pattern.MatchWholeWord = false; m_pattern.MatchCase = false; m_pattern.UseRegularExpressions = false; m_pattern.Pattern = tsf.MakeString("pattern", ws); andFilter.Add(new FilterBarCellFilter(oneIndAtomFinder, new InvertMatcher(new RegExpMatcher(m_pattern)))); andFilter.Add(new NullFilter()); XmlDocument docPaf = new XmlDocument(); docPaf.LoadXml("<root targetClasses=\"LexEntry, LexSense\"></root>"); ProblemAnnotationFilter paf = new ProblemAnnotationFilter(); paf.Init(m_cache, docPaf.DocumentElement); andFilter.Add(paf); // Save and restore! string xml = DynamicLoader.PersistObject(andFilter, "filter"); XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); // And check all the pieces... AndFilter andFilterOut = DynamicLoader.RestoreObject(doc.DocumentElement) as AndFilter; andFilterOut.Cache = m_cache; Assert.IsNotNull(andFilterOut); FilterBarCellFilter rangeIntFilterOut = andFilterOut.Filters[0] as FilterBarCellFilter; // todo Assert.IsNotNull(rangeIntFilterOut); OwnIntPropFinder ownIntFinderOut = rangeIntFilterOut.Finder as OwnIntPropFinder; Assert.IsNotNull(ownIntFinderOut); Assert.AreEqual(551, ownIntFinderOut.Flid); RangeIntMatcher rangeIntMatchOut = rangeIntFilterOut.Matcher as RangeIntMatcher; Assert.IsNotNull(rangeIntMatchOut); Assert.AreEqual(5, rangeIntMatchOut.Min); Assert.AreEqual(23, rangeIntMatchOut.Max); Assert.IsTrue(tssLabel.Equals(rangeIntMatchOut.Label)); NotEqualIntMatcher notEqualMatchOut = GetMatcher(andFilter, 1) as NotEqualIntMatcher; Assert.IsNotNull(notEqualMatchOut); Assert.AreEqual(77, notEqualMatchOut.NotEqualValue); ExactMatcher exactMatchOut = GetMatcher(andFilter, 2) as ExactMatcher; Assert.IsNotNull(exactMatchOut); Assert.AreEqual("hello", exactMatchOut.Pattern.Pattern.Text); BeginMatcher beginMatchOut = GetMatcher(andFilter, 3) as BeginMatcher; Assert.IsNotNull(beginMatchOut); Assert.AreEqual("goodbye", beginMatchOut.Pattern.Pattern.Text); EndMatcher endMatchOut = GetMatcher(andFilter, 4) as EndMatcher; Assert.IsNotNull(endMatchOut); Assert.AreEqual("exit", endMatchOut.Pattern.Pattern.Text); AnywhereMatcher anywhereMatchOut = GetMatcher(andFilter, 5) as AnywhereMatcher; Assert.IsNotNull(anywhereMatchOut); Assert.AreEqual("whatever", anywhereMatchOut.Pattern.Pattern.Text); BlankMatcher blankMatchOut = GetMatcher(andFilter, 6) as BlankMatcher; Assert.IsNotNull(blankMatchOut); NonBlankMatcher nonBlankMatchOut = GetMatcher(andFilter, 7) as NonBlankMatcher; Assert.IsNotNull(nonBlankMatchOut); InvertMatcher invertMatchOut = GetMatcher(andFilter, 8) as InvertMatcher; Assert.IsNotNull(invertMatchOut); OwnMlPropFinder mlPropFinderOut = GetFinder(andFilter, 2) as OwnMlPropFinder; Assert.AreEqual(m_cache.MainCacheAccessor, mlPropFinderOut.DataAccess); Assert.AreEqual(788, mlPropFinderOut.Flid); Assert.AreEqual(23, mlPropFinderOut.Ws); OwnMonoPropFinder monoPropFinderOut = GetFinder(andFilter, 3) as OwnMonoPropFinder; Assert.AreEqual(m_cache.MainCacheAccessor, monoPropFinderOut.DataAccess); Assert.AreEqual(954, monoPropFinderOut.Flid); OneIndirectMlPropFinder oneIndMlPropFinderOut = GetFinder(andFilter, 4) as OneIndirectMlPropFinder; Assert.AreEqual(m_cache.MainCacheAccessor, oneIndMlPropFinderOut.DataAccess); Assert.AreEqual(221, oneIndMlPropFinderOut.FlidVec); Assert.AreEqual(222, oneIndMlPropFinderOut.FlidString); Assert.AreEqual(27, oneIndMlPropFinderOut.Ws); MultiIndirectMlPropFinder mimlPropFinderOut = GetFinder(andFilter, 5) as MultiIndirectMlPropFinder; Assert.AreEqual(m_cache.MainCacheAccessor, mimlPropFinderOut.DataAccess); Assert.AreEqual(444, mimlPropFinderOut.VecFlids[0]); Assert.AreEqual(555, mimlPropFinderOut.VecFlids[1]); Assert.AreEqual(666, mimlPropFinderOut.FlidString); Assert.AreEqual(87, mimlPropFinderOut.Ws); OneIndirectAtomMlPropFinder oneIndAtomFinderOut = GetFinder(andFilter, 6) as OneIndirectAtomMlPropFinder; Assert.AreEqual(m_cache.MainCacheAccessor, oneIndAtomFinderOut.DataAccess); Assert.AreEqual(543, oneIndAtomFinderOut.FlidAtom); Assert.AreEqual(345, oneIndAtomFinderOut.FlidString); Assert.AreEqual(43, oneIndAtomFinderOut.Ws); // 7, 8 are duplicates NullFilter nullFilterOut = andFilter.Filters[9] as NullFilter; Assert.IsNotNull(nullFilterOut); ProblemAnnotationFilter pafOut = andFilter.Filters[10] as ProblemAnnotationFilter; Assert.IsNotNull(pafOut); Assert.AreEqual(5002, pafOut.ClassIds[0]); Assert.AreEqual(5016, pafOut.ClassIds[1]); }