private IEnumerable <TVal> _row(int i, RangeWrapper jRange) { foreach (int j in jRange.Range(Cols)) { yield return(_matrix[i, j]); } }
public override void ApplyBatchModeAction(RangeWrapper rangeToChange, string suggestion) { int selectedIndex = SearchArray(m_lastSugs, suggestion); if (rangeToChange.Text != suggestion) { //string preText = rangeToChange.Text; if (rangeToChange.TryChangeText(suggestion)) { VerificationWindowBatchMode.CurrentStatus = m_punctuationCheckerEngine.GetMistakeDescription(); // preText + ": " + suggestion; m_punctuationCheckerEngine.CorrectMistake(selectedIndex); base.RefreshForChangeCalled(null, suggestion); m_stats++; } else { m_punctuationCheckerEngine.SkipMistake(); // Do nothing, or do it without making the window lose focus // i.e., do NOT show a message box //MessageBox.Show("تغییر مورد نظر قابل اعمال نیست!"); } } // end of common sections between change and change-all else { m_punctuationCheckerEngine.SkipMistake(); } }
private IEnumerable <TVal> _col(int j, RangeWrapper iRange) { foreach (int i in iRange.Range(Rows)) { yield return(_matrix[i, j]); } }
public override sealed bool InitParagraph(RangeWrapper par) { if (par == null || !par.IsRangeValid) { return(false); } m_mainPar = par.GetCopy(); RefreshContent(); if (String.IsNullOrEmpty(m_rawContent)) { return(false); } string refinedContent = StringUtil.RefineAndFilterPersianWord(m_rawContent); if (String.IsNullOrEmpty(refinedContent)) { return(false); } string strToVerify = this.NeedRefinedStrings ? refinedContent : m_rawContent; if (!base.IsInteractiveMode) { m_batchHistory.Clear(); m_isLoopDetected = false; } return(InitParagraphString(strToVerify)); }
private VerificationData ProcessSubParagraph(RangeWrapper subPar) { string rawContent = subPar.Text; if (rawContent == null) { return(null); } string contentToVerify = rawContent; if (NeedRefinedStrings) { contentToVerify = StringUtil.RefineAndFilterPersianWord(rawContent); } var strVerifData = FindPattern(contentToVerify); if (strVerifData == null || !strVerifData.IsValid) { return(null); } var verifData = new VerificationData(strVerifData, subPar, rawContent, NeedRefinedStrings); if (!verifData.IsValid) { return(null); } return(verifData); }
public static void FindEquations() { foreach (RangeWrapper par in RangeWrapper.ReadParagraphsStartingFromCursor(Globals.ThisAddIn.Application.ActiveDocument)) { string parContent = par.Text; par.Select(); var sb = new StringBuilder(); sb.AppendFormat("#Fields: {0}", par.Range.Fields.Count).AppendLine(); int numRangeChars = par.Range.Characters.Count; int numTextChars = par.Text.Length; sb.AppendFormat("#RangeChars: {0}", numRangeChars).AppendLine(); sb.AppendFormat("#TextChars: {0}", numTextChars).AppendLine(); if (numTextChars != numRangeChars) { sb.AppendFormat("#Diff: {0}", numTextChars - numRangeChars).AppendLine(); //sb.AppendFormat("#RRs: {0}", CountFoundSubstrings(parContent, "\r\r")).AppendLine(); } sb.AppendLine().AppendLine("Content Made Visible:").AppendLine(StringUtil.MakeStringVisible(parContent)); if (DialogResult.OK != MessageBox.Show(sb.ToString(), "Paragraph Content", MessageBoxButtons.OKCancel)) { return; } } }
public DepartementParser(RangeWrapper _rw) { this.listCells = _rw; CellWrapper cw = this.listCells.find("Département"); this.depColumn = cw.colNumber; this.depTitlesTableRowNum = cw.rowNumber; }
protected void RefreshForChangeCalled(RangeWrapper rangeToChange, string replaceText) { RefreshContents(); m_resetNeeded = true; m_resetIndex = m_roundq[0].Index; m_numIgnores = Math.Max(0, m_roundq.CurMainItemIndex - 1); }
private void BatchVerifierThreadCallBack() { bool isRevisionsEnabled = false; try { // Check if revisions are visible, if so make them invisible and turn them back on in the end isRevisionsEnabled = DocumentUtils.IsRevisionsEnabled(m_verifier.Document); if (isRevisionsEnabled) { DocumentUtils.ChangeShowingRevisions(m_verifier.Document, false); } int docPageCount = -1; foreach (RangeWrapper par in RangeWrapper.ReadParagraphs(m_verifier.Document)) { if (m_cancelationPending) { break; } if (docPageCount <= 0) { docPageCount = par.NumberOfPagesInDocument; } int curPage = par.PageNumber; if (curPage > 0 && docPageCount > 0) { ShowPageNumberProgress(curPage, docPageCount); } //System.Diagnostics.Debug.WriteLine("Page: " + curPage + " of " + docPageCount); SendParagraphForVerification(par); if (m_cancelationPending) { break; } } // end of foreach par } finally { // Check if revisions are visible, if so make them invisible and turn them back on in the end if (isRevisionsEnabled) { DocumentUtils.ChangeShowingRevisions(m_verifier.Document, true); } m_eventVerifierThreadStoped.Set(); } if (!m_isFormClosed) { StopThreadsAndClose(); } }
/// <summary> /// Fixes the location of the window based on the position of the highlighted range, /// so that the range will be perfectly visible. /// </summary> /// <param name="r">The range that is highlighted and wished to be visible</param> private void FixWindowLocation(RangeWrapper r) { try { int rangeLeft, rangeTop, rangeWidth, rangeHeight; Globals.ThisAddIn.Application.ActiveWindow.GetPoint(out rangeLeft, out rangeTop, out rangeWidth, out rangeHeight, r.Range); int x = rangeLeft; if (rangeWidth < 0) { x += rangeWidth; rangeWidth = Math.Abs(rangeWidth); } //int scrWidth = Screen.PrimaryScreen.WorkingArea.Width; int scrHeight = Screen.PrimaryScreen.WorkingArea.Height; // if it is masked if ((this.Left <= x && x <= this.Left + this.Width || this.Left <= x + rangeWidth && x + rangeWidth <= this.Left + this.Width) && (this.Top <= rangeTop && rangeTop <= this.Top + this.Height || this.Top <= rangeTop + rangeHeight && rangeTop + rangeHeight <= this.Top + this.Height)) { // if it is masked vertically if (this.Top <= rangeTop && rangeTop <= this.Top + this.Height || this.Top <= rangeTop + rangeHeight && rangeTop + rangeHeight <= this.Top + this.Height) { // if there's enough space below it if (scrHeight - rangeTop - rangeHeight > this.Height) { this.Top = rangeTop + rangeHeight; } // else if there's enough space above it else if (rangeTop > this.Height) { this.Top = rangeTop - this.Height; } //// if there's not enough space neither below nor above it try to move it horizontally //else //{ // // // if it can be shown on both sides // // if (x > this.Width && scrWidth - x > this.Width) // // { // // } // // else // if it can be shown on either side or none // // { // // } //} } } } catch { // simply do nothing in case of exception return; } }
static void Main(string[] args) { Application excel = new Application(); Workbook wkbk = null; List <Departement> listeDep = new List <Departement>(); DirectoryInfo rootSolutionDir = new DirectoryInfo(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName).Parent; // check resources folder exists or create it DirectoryInfo resDir = new DirectoryInfo(Path.Combine(rootSolutionDir.FullName, "resources")); DirectoryInfo[] yearsDir = resDir.GetDirectories(); foreach (DirectoryInfo yearDir in yearsDir) { FileInfo jsonFile = new FileInfo(Path.Combine(yearDir.FullName, yearDir.Name + ".json")); if (!jsonFile.Exists) { Console.WriteLine("Parsing year " + yearDir.Name); FileInfo[] depFiles = yearDir.GetFiles(); foreach (FileInfo file in depFiles) { Console.WriteLine("Departement : " + file.Name); wkbk = excel.Workbooks.Open(file.FullName); if (wkbk.Sheets.Count == 1) { Worksheet firstSheet = (Worksheet)wkbk.Sheets[1]; RangeWrapper rw = new RangeWrapper(firstSheet.UsedRange); wkbk.Close(false, file.FullName, null); DepartementParser dp = new DepartementParser(rw); listeDep.Add(dp.getDepartement()); } else { wkbk.Close(false, file.FullName, null); throw new Exception("Excel file has " + wkbk.Sheets.Count + " workbooks"); } } Console.WriteLine("Creating JSON file"); using (StreamWriter writer = new StreamWriter(jsonFile.FullName)) { writer.Write(JsonConvert.SerializeObject(listeDep.ToArray())); listeDep.Clear(); } } } Marshal.ReleaseComObject(wkbk); Marshal.ReleaseComObject(excel); Console.WriteLine("End of program"); Console.ReadLine(); }
public IEnumerable <IEnumerable <TVal> > this[RangeWrapper iRange] { get { return(this[iRange, Ranges.All]); } set { this[iRange, Ranges.All] = value; } }
public Column <TVal> this[RangeWrapper iRange, int j] { get { return(Col(j, iRange)); } set { this[iRange, (RangeWrapper)j] = value.Select(x => Enumerable.Repeat(x, 1)); } }
public Row <TVal> this[int i, RangeWrapper jRange] { get { return(Row(i, jRange)); } set { this[(RangeWrapper)i, jRange] = Enumerable.Repeat(value, 1); } }
public override void ApplyBatchModeAction(RangeWrapper rangeToChange, string suggestion) { //if (rangeToChange.TryChangeTextCharSensitive(suggestion)) if (rangeToChange.TryChangeText(suggestion)) { AddCurStatsToGlobalStats(); base.RefreshForChangeCalled(m_curVerData.RangeToHighlight, suggestion); } ResetCurStepStats(); }
public override void ApplyBatchModeAction(RangeWrapper rangeToChange, string suggestion) { if (rangeToChange.Text != suggestion) { if (rangeToChange.TryChangeText(suggestion)) { base.RefreshForChangeCalled(m_curVerData.RangeToHighlight, suggestion); m_bachModeStats++; } } }
public override bool InitParagraph(RangeWrapper par) { m_mainPar = par; if (par == null || !par.IsRangeValid) { return(false); } m_remainedParagraph = m_mainPar.GetCopy(); m_progInd = 0; return(true); //m_curProcType = ProceedTypes.Finished; }
public static void MakeEachParagraphVisible() { foreach (RangeWrapper par in RangeWrapper.ReadParagraphsStartingFromCursor(Globals.ThisAddIn.Application.ActiveDocument)) { string parContent = par.Text; par.Select(); if (DialogResult.OK != MessageBox.Show(StringUtil.MakeStringVisible(parContent), "Paragraph Content", MessageBoxButtons.OKCancel)) { return; } } }
private void SendParagraphForVerification(RangeWrapper par) { if (par == null || !par.IsRangeValid) { return; } if (!m_verifier.InitParagraph(par)) { return; } while (m_verifier.HasVerification()) { if (m_cancelationPending) { return; } // info about content and location of error, or even the related range VerificationData verData = m_verifier.GetNextVerificationData(); if (verData == null || !verData.IsValid) { continue; } //// SendToUi this verData and wait for user interaction //// VerificationResult contains selected suggestion user action and viwercontroller argument //VerificationResult verRes = SendVerificationToUi(verData); string defSuggestion = verData.Suggestions.DefaultSuggestion; if (defSuggestion == null) { continue; } if (ShowProgressAtDocument) { verData.RangeToHighlight.Select(); } m_verifier.ApplyBatchModeAction(verData.RangeToHighlight, defSuggestion); } }
public override bool InitParagraph(RangeWrapper par) { // TODO: make sure that creating a copy is needed m_curPar = par.GetCopy(); if (m_wordTokenizer == null) { m_wordTokenizer = new WordTokenizer(TokenizerOptions); } if (!RefreshContents()) { return(false); } m_etorNGramVerifs = null; m_roundq.Clear(); m_rangeRepairOffset = 0; return(true); }
public override bool HasVerification() { if (CancelationPending) { return(false); } //// if the text is shorter or equal than the length that is going to be cut from the paragraph; //// then we expect that no text should remain in the remainder paragraph; but in action it does, //// so hereby we prevent it. if (m_remainedParagraph == null || !m_remainedParagraph.IsRangeValid || m_progInd >= m_remainedParagraph.Text.Length) { return(false); } if (m_progInd > 0) { //m_remainedParagraph = m_remainedParagraph.GetRangeWithOffset(m_progInd - m_remainedParagraph.Start + 1); m_remainedParagraph = m_remainedParagraph.GetRangeWithCharIndex(m_progInd); if (m_remainedParagraph == null || !m_remainedParagraph.IsRangeValid) { return(false); } m_remainedParagraph = m_remainedParagraph.TrimRange(); if (m_remainedParagraph == null || !m_remainedParagraph.IsRangeValid) { return(false); } } m_curVerifData = ProcessSubParagraph(m_remainedParagraph); if (m_curVerifData == null || !m_curVerifData.IsValid) { return(false); } // m_progInd should be further changed by user actions m_progInd = m_curVerifData.ErrorEnd + 1; return(true); }
protected void RefreshForChangeAllCalled(int priorRangeLength, RangeWrapper rangeWrapper, string selectedSug) { RefreshContents(); m_resetNeeded = true; m_resetIndex = priorRangeLength; if (priorRangeLength == 0) { return; } // the length is given in raw text length if (this.NeedRefinedStrings) { string preStr = m_rawContent.Substring(0, priorRangeLength - 1); string strRefined = StringUtil.RefineAndFilterPersianWord(preStr); m_resetIndex = strRefined.Length; // -1 + 1 } }
public override void ApplyBatchModeAction(RangeWrapper rangeToChange, string suggestion) { string wordToChange = rangeToChange.Text; if (wordToChange != suggestion) { if (!m_curVerData.RangeToHighlight.TryChangeText(suggestion)) { //this.VerificationWindowInteractive.InvokeMethod(() => //{ // //MessageBox.Show(VerificationWindowInteractive.GetWin32Window(), // // "تغییر مورد نظر قابل اعمال نیست!"); //}); } else { m_sessionLogger.AddUsage(suggestion); base.RefreshForChangeCalled(m_curVerData.RangeToHighlight, suggestion); } } }
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); } } }
public override void ApplyBatchModeAction(RangeWrapper rangeToChange, string suggestion) { throw new NotImplementedException(); }
public abstract void ApplyBatchModeAction(RangeWrapper rangeToChange, string suggestion);
public abstract bool InitParagraph(RangeWrapper par);
public void SetContent(StringVerificationData copy, RangeWrapper rContext, string rawContent, bool needsRefinedString, ref int rangeRepairOffset) { base.SetContent(copy); ErrorContext = rawContent; RangeWrapper foundRange; string strToBeMatched; if (needsRefinedString) { int newInd = StringUtil.IndexInNotFilterAndRefinedString(rawContent, ErrorIndex); int newEnd = StringUtil.IndexInNotFilterAndRefinedString(rawContent, ErrorEnd); foundRange = rContext.GetRangeWithCharIndex(newInd + rangeRepairOffset, newEnd + rangeRepairOffset); strToBeMatched = rawContent.Substring(newInd, newEnd - newInd + 1); this.ErrorIndex = newInd; this.ErrorLength = newEnd - newInd + 1; } else { strToBeMatched = rawContent.Substring(ErrorIndex, ErrorLength); foundRange = rContext.GetRangeWithCharIndex(ErrorIndex + rangeRepairOffset, ErrorEnd + rangeRepairOffset); } this.RangeToHighlight = foundRange; // if it is an invalid range, no need to do anything, the IsValid property will return false automatically if (foundRange == null || !foundRange.IsRangeValid) { return; } if (foundRange.Text == strToBeMatched) // Well Done no need to do any range recovery stuff { return; } // Try to recover here, by fixing rangeRepairOffset var remStrParText = rawContent.Substring(ErrorIndex); // error index before repair done above var remParRange = rContext.GetRangeWithCharIndex(ErrorIndex + rangeRepairOffset); string remRngParText = remParRange.Text; // see if any of the rem pars contain the other bool isStrInRng = true; int remi = remRngParText.IndexOf(remStrParText, StringComparison.Ordinal); if (remi < 0) { remi = remStrParText.IndexOf(remRngParText, StringComparison.Ordinal); isStrInRng = false; } if (remi < 0) { RangeToHighlight = null; return; //Debug.Assert(false, "Non recoverable situation met!"); } if (!isStrInRng) { remi = -remi; } // make sure that you can find the appropriate range const int numTries = 3; int i; for (i = 0; i < numTries; i++) { var testRange = rContext.GetRangeWithCharIndex(ErrorIndex + rangeRepairOffset + remi, ErrorEnd + rangeRepairOffset + remi); if (testRange.Text == strToBeMatched) { rangeRepairOffset += remi; RangeToHighlight = testRange; break; } remi = remi < 0 ? remi - 1 : remi + 1; } if (i >= 3) // i.e., if the above loop did not break { RangeToHighlight = null; //Debug.Assert(false, "Substrings found but ranges not found!"); } }
public void SetContent(StringVerificationData copy, RangeWrapper rContext, string rawContent, bool needsRefinedString) { int dummy = 0; SetContent(copy, rContext, rawContent, needsRefinedString, ref dummy); }
public VerificationData(StringVerificationData copy, RangeWrapper rContext, string rawContent, bool needsRefinedString) { SetContent(copy, rContext, rawContent, needsRefinedString); }