/// <summary> /// Finds the first and the most prominent pattern in the string. /// </summary> /// <param name="content">The content to search the pattern in.</param> protected override StringVerificationData FindPattern(string content) { m_lstPatterns = FindNumberPatterns(content); if (m_lstPatterns == null || m_lstPatterns.Count <= 0) { return(null); } IPatternInfo minPi = m_lstPatterns[0]; var listSugs = new List <string>(); foreach (IPatternInfo pi in m_lstPatterns) { listSugs.AddRange(CreateSuggestions(pi)); } return(new StringVerificationData { ErrorIndex = minPi.Index, ErrorLength = minPi.Length, ErrorType = VerificationTypes.Information, Suggestions = new TitledListBoxSuggestion { Message = "پیشنهادها", SuggestionItems = listSugs } }); }
internal ExtensionState( IPatternInfo extendingProduct, IExtensionPointInfo extensionPoint, IBindingFactory bindingFactory) { this.ExtendingProduct = extendingProduct; this.ExtensionPoint = extensionPoint; this.bindingFactory = bindingFactory; this.BindingContext = bindingFactory.CreateContext(); this.BindingContext.AddExportsFromInterfaces(extendingProduct); this.BindingContext.AddExportsFromInterfaces(extensionPoint); }
public static string CreateSuggestionFor(IPatternInfo pi, KeyValuePair <NumberChangeRule.OutputFormats, NumberChangeRule.OutputDigitLanguages> ruleValue) { switch (pi.PatternInfoType) { case PatternInfoTypes.PersianNumber: return(CreateGeneralNumberSuggestionFor(pi as GeneralNumberInfo, ruleValue)); case PatternInfoTypes.DigitizedNumber: return(CreateDigitizedNumberSuggestionFor(pi as DigitizedNumberPatternInfo, ruleValue)); default: return(null); } }
/// <summary> /// Creates suggestions for the given pattern info /// </summary> /// <param name="rule">the change rules that give order to the suggestions</param> /// <param name="pi">the pattern info object to create suggestions for</param> /// <returns></returns> public static string[] CreateSuggestions(NumberChangeRule rule, IPatternInfo pi) { switch (pi.PatternInfoType) { case PatternInfoTypes.PersianNumber: return(CreateGeneralNumberSuggestions(rule, pi as GeneralNumberInfo)); case PatternInfoTypes.DigitizedNumber: return(CreateDigitizedNumberSuggestions(rule, pi as DigitizedNumberPatternInfo)); default: return(new string[0]); } }
private List <IPatternInfo> FindNumberPatterns(string content) { var lstPatternInfos = new List <IPatternInfo>(); lstPatternInfos.Clear(); IPatternInfo firstPi = null; foreach (IPatternInfo pi in m_perianRealNumberParser.FindAndParse(content)) { if (firstPi == null) { firstPi = pi; lstPatternInfos.Add(pi); } else { if (pi.Index == firstPi.Index && pi.Length == firstPi.Length) { lstPatternInfos.Add(pi); } else { break; } } } foreach (IPatternInfo pi in m_digitizedNumberParser.FindAndParse(content)) { if (firstPi != null) { if ((pi.Index < firstPi.Index) || (pi.Index == firstPi.Index && pi.Length > firstPi.Length)) { lstPatternInfos.Clear(); lstPatternInfos.Add(pi); } } else { //firstPi = pi; lstPatternInfos.Add(pi); } break; } return(lstPatternInfos); }
private IPatternInfo PeakFirstVerification() { IPatternInfo minPi = null; int minIndex = Int32.MaxValue; foreach (var pi in m_lstPatternInfo) { if (pi.Index < minIndex) { minIndex = pi.Index; minPi = pi; } } return(minPi); }
private ListViewItem[] CreateSuggestions(IPatternInfo minPi) { switch (minPi.PatternInfoType) { case PatternInfoTypes.EnglishDate: return(CreateEnglishDateSuggestions(minPi as EnglishDatePatternInfo)); case PatternInfoTypes.NumericDate: return(CreateNumericDateSuggestions(minPi as NumericDatePatternInfo)); case PatternInfoTypes.PersianDate: return(CreatePersianDateSuggestions(minPi as PersianDatePatternInfo)); default: return(new ListViewItem[0]); } }
protected override StringVerificationData FindPattern(string content) { m_lstPatternInfo.Clear(); foreach (var pi in m_perianDataParser.FindAndParse(content)) { if (pi.YearNumber >= 0) { m_lstPatternInfo.Add(pi); } } foreach (var pi in m_englishDateParser.FindAndParse(content)) { if (pi.YearNumber >= 0) { m_lstPatternInfo.Add(pi); } } foreach (var pi in m_numericDateParser.FindAndParse(content)) { m_lstPatternInfo.Add(pi); } if (m_lstPatternInfo.Count <= 0) { return(null); } m_minPi = PeakFirstVerification(); return(new StringVerificationData { ErrorIndex = m_minPi.Index, ErrorLength = m_minPi.Length, ErrorType = VerificationTypes.Information, Suggestions = new DateSuggestion { Message = "موارد یافت شده:", MainPattern = m_minPi } }); }
public void Initialize() { this.storeFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); var toolkit = Mocks.Of <IInstalledToolkitInfo>().First( x => x.Id == "test_toolkit" && x.Schema.Pattern.Id == Guid.NewGuid()); this.productInfo = toolkit.Schema.Pattern; var productMock = Mock.Get(this.productInfo); productMock.Setup(x => x.Views) .Returns(Mocks.Of <IViewInfo>(x => x.Id == Guid.NewGuid() && x.Pattern == this.productInfo).Take(2).ToList()); productMock.Setup(x => x.Properties) .Returns(Mocks.Of <IPropertyInfo>(x => x.Id == Guid.NewGuid() && x.Name == "Foo" + Guid.NewGuid() && x.Type == "System.String" && x.Parent == this.productInfo).Take(2).ToList()); var serviceProvider = new Mock <IServiceProvider>(); serviceProvider.Setup(x => x.GetService(typeof(IPatternManager))) .Returns(Mocks.Of <IPatternManager>().First(x => x.InstalledToolkits == new[] { toolkit })); using (var store = new Microsoft.VisualStudio.Modeling.Store(serviceProvider.Object, typeof(Microsoft.VisualStudio.Modeling.CoreDomainModel), typeof(ProductStateStoreDomainModel))) using (var tx = store.TransactionManager.BeginTransaction()) { var productStore = store.ElementFactory.CreateElement <ProductState>(); var product = productStore .CreateProduct(x => { x.ExtensionId = "test_toolkit"; x.DefinitionId = toolkit.Schema.Pattern.Id; }); this.productId = product.Id; ProductStateStoreSerializationHelper.Instance.SaveModel(new Microsoft.VisualStudio.Modeling.SerializationResult(), productStore, this.storeFilePath); tx.Commit(); } this.store = new Microsoft.VisualStudio.Modeling.Store(serviceProvider.Object, typeof(Microsoft.VisualStudio.Modeling.CoreDomainModel), typeof(ProductStateStoreDomainModel)); }
public void print(IPatternInfo item) { Console.WriteLine("" + item.name + "->" + item.description); }
private void PerformReplaceAll(KeyValuePair <NumberChangeRule.InputFormats, NumberChangeRule.InputDigitLanguages> ruleKey, KeyValuePair <NumberChangeRule.OutputFormats, NumberChangeRule.OutputDigitLanguages> ruleValue) { foreach (var par in RangeWrapper.ReadParagraphs(Document)) { if (CancelationPending) { break; } if (!par.IsRangeValid) { continue; } string rawParText = par.Text; string parText = rawParText; if (NeedRefinedStrings) { parText = StringUtil.RefineAndFilterPersianWord(parText); } int startFrom = 0; int len = parText.Length; var sbRawText = new StringBuilder(rawParText); var sbParText = new StringBuilder(parText); string parToVerify = parText; // parToVerify is going to shrink while parText is fixed while (startFrom < len) { var lstPats = FindNumberPatterns(parToVerify); if (lstPats == null || lstPats.Count <= 0) { break; } if (CancelationPending) { break; } IPatternInfo minPi = lstPats[0]; int startIndex = minPi.Index + startFrom; int endIndex = minPi.Index + minPi.Length - 1 + startFrom; int rawStartIndex = StringUtil.IndexInNotFilterAndRefinedString(sbRawText.ToString(), startIndex); int rawEndIndex = StringUtil.IndexInNotFilterAndRefinedString(sbRawText.ToString(), endIndex); NumberChangeRule.InputFormats inpFormat; NumberChangeRule.InputDigitLanguages inpLang; NumberChangeRule.DectectInputFormat(minPi.Content, out inpFormat, out inpLang); int forwardingOffset = 0; if (ruleKey.Key == inpFormat && ruleKey.Value == inpLang) { string suggestion = NumberParsersSuggestions.CreateSuggestionFor(minPi, ruleValue); if (!String.IsNullOrEmpty(suggestion)) { RangeWrapper foundRange; if (NeedRefinedStrings) { foundRange = par.GetRangeWithCharIndex(rawStartIndex, rawEndIndex); } else { foundRange = par.GetRangeWithCharIndex(startIndex, endIndex); } if (foundRange.IsRangeValid && foundRange.Text != suggestion) { if (foundRange.TryChangeText(suggestion)) { if (NeedRefinedStrings) { sbRawText.Remove(rawStartIndex, rawEndIndex - rawStartIndex + 1); sbRawText.Insert(rawStartIndex, suggestion); } sbParText.Remove(startIndex, endIndex - startIndex + 1); sbParText.Insert(startIndex, suggestion); //System.Diagnostics.Debug.WriteLine(sbParText); //System.Diagnostics.Debug.WriteLine("---------------------------"); len = sbParText.Length; forwardingOffset = suggestion.Length - minPi.Length; } } } // end if (suggestions count > 0) } // end if (minPi content matches change rule) startFrom = endIndex + 1 + forwardingOffset; if (startFrom >= len) { break; } parToVerify = sbParText.ToString().Substring(startFrom); } } }
private string[] CreateSuggestions(IPatternInfo minPi) { return(NumberParsersSuggestions.CreateSuggestions(m_changeRules, minPi)); }
/// <summary> /// Creates suggestions for the given pattern info /// </summary> /// <param name="pi">the pattern info object to create suggestions for</param> /// <returns></returns> public static string[] CreateSuggestions(IPatternInfo pi) { return(CreateSuggestions(null, pi)); }
public void Initialize() { this.storeFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); var toolkit = Mocks.Of<IInstalledToolkitInfo>().First( x => x.Id == "test_toolkit" && x.Schema.Pattern.Id == Guid.NewGuid()); this.productInfo = toolkit.Schema.Pattern; var productMock = Mock.Get(this.productInfo); productMock.Setup(x => x.Views) .Returns(Mocks.Of<IViewInfo>(x => x.Id == Guid.NewGuid() && x.Pattern == this.productInfo).Take(2).ToList()); productMock.Setup(x => x.Properties) .Returns(Mocks.Of<IPropertyInfo>(x => x.Id == Guid.NewGuid() && x.Name == "Foo" + Guid.NewGuid() && x.Type == "System.String" && x.Parent == this.productInfo).Take(2).ToList()); var serviceProvider = new Mock<IServiceProvider>(); serviceProvider.Setup(x => x.GetService(typeof(IPatternManager))) .Returns(Mocks.Of<IPatternManager>().First(x => x.InstalledToolkits == new[] { toolkit })); using (var store = new Microsoft.VisualStudio.Modeling.Store(serviceProvider.Object, typeof(Microsoft.VisualStudio.Modeling.CoreDomainModel), typeof(ProductStateStoreDomainModel))) using (var tx = store.TransactionManager.BeginTransaction()) { var productStore = store.ElementFactory.CreateElement<ProductState>(); var product = productStore .CreateProduct(x => { x.ExtensionId = "test_toolkit"; x.DefinitionId = toolkit.Schema.Pattern.Id; }); this.productId = product.Id; ProductStateStoreSerializationHelper.Instance.SaveModel(new Microsoft.VisualStudio.Modeling.SerializationResult(), productStore, this.storeFilePath); tx.Commit(); } this.store = new Microsoft.VisualStudio.Modeling.Store(serviceProvider.Object, typeof(Microsoft.VisualStudio.Modeling.CoreDomainModel), typeof(ProductStateStoreDomainModel)); }