コード例 #1
0
ファイル: SpellingFixerEC.cs プロジェクト: sillsdev/WorldPad
        protected void QueryAndAppend(string strBadWord)
        {
            QueryGoodSpelling aQuery = new QueryGoodSpelling(m_font);

            if (aQuery.ShowDialog(strBadWord, strBadWord, strBadWord, false) == DialogResult.OK)
            {
                // if it was legacy encoded, then we need to convert the data to narrow using
                //  the code page the user specified (or we got out of the repository)
                Encoding enc = GetEncoding;

                // get a stream writer for these encoding and append
                StreamWriter sw = new StreamWriter(m_strConverterSpec, true, enc);
                sw.WriteLine(FormatSubstitutionRule(aQuery.BadSpelling, aQuery.GoodSpelling, WordBoundaryDelimiter, strBadWord));
                sw.Flush();
                sw.Close();
            }
        }
コード例 #2
0
        protected void ProcessEditRow(DataGridViewRow theRow)
        {
            DataGridViewCell theBadCell   = theRow.Cells[cnBadSpelling];
            DataGridViewCell theGoodCell  = theRow.Cells[cnGoodSpelling];
            string           strBadValue  = (string)theBadCell.Value;
            string           strGoodValue = (string)theGoodCell.Value;

            QueryGoodSpelling aQuery = new QueryGoodSpelling(dataGridView.RowsDefaultCellStyle.Font);
            DialogResult      res    = aQuery.ShowDialog(strBadValue, strGoodValue, strBadValue, (strBadValue != null));

            if (res == DialogResult.Abort)
            {
                // this means delete
                dataGridView.Rows.Remove(theRow);

#if !TurnOffSF30
                if (!String.IsNullOrEmpty(strBadValue) && EditingCscBad2GoodList)
                {
                    m_mapBad2Good.Remove(strBadValue);
                }
#endif
                buttonOK.Enabled = true;
            }
            else if (res == DialogResult.OK)
            {
                // try to organize the permutations:
                //    o both columns were initially null (i.e. IsNewRow = true) and now have values
                //      ->  both must now be non-null
                //      ->  new 'bad' must not already exist
                //    o both columns were non-null and now the 'good' value is changed
                //      ->  if the old 'good' value is still present elsewhere, then query to change those also
                //      ->  change the good value in the row (and bad if necessary)
                //      ->  change the good value in the white list as well
                //    o both columns were non-null and now the 'bad' value (only) is changed
                //      ->  change the bad value in the row
                //      ->  change the bad value in the bad2good list
                if (String.IsNullOrEmpty(aQuery.BadSpelling) || String.IsNullOrEmpty(aQuery.GoodSpelling))
                {
                    // if either of them are null...
                    throw new ApplicationException("The 'Bad' and 'Good' forms are not allowed to be nothing!");
                }
#if !TurnOffSF30
                /* I don't recall what I was thinking about this one. Sometimes having the good and bad spelling
                 * be the same is the only way to force a replacement to not happen (e.g. if a shorter string
                 * replacement rule would otherwise override a longer string and you don't want that)
                 * Oh: maybe that applied with CSC since that always only worked with whole word forms... move
                 * it into the conditional compile area...
                 * else if (aQuery.BadSpelling == aQuery.GoodSpelling)
                 * {
                 *  // if they're the same...
                 *  throw new ApplicationException("The new 'Bad' and 'Good' forms must be different from each other!");
                 * }
                 */
                else if (!EditingCscBad2GoodList)
#endif
                {
                    // Legacy SpellFixer
                    theBadCell.Value  = aQuery.BadSpelling;
                    theGoodCell.Value = aQuery.GoodSpelling;
                }
#if !TurnOffSF30
                else if (String.IsNullOrEmpty(strBadValue) && m_mapBad2Good.ContainsKey(aQuery.BadSpelling))
                {
                    // if we're adding a new one (i.e. strBadValue == null) and it's already in the list...
                    // ... we don't want to have added the dummy record (so delete it)
                    dataGridView.Rows.Remove(theRow);

                    // scroll the existing match into view.
                    foreach (DataGridViewRow aRow in dataGridView.Rows)
                    {
                        if (aQuery.BadSpelling == (string)aRow.Cells[cnBadSpelling].Value)
                        {
                            aRow.Selected = true;
                            dataGridView.FirstDisplayedScrollingRowIndex = aRow.Index;
                            break;
                        }
                    }

                    // if the value was, in fact, different, then throw an exception
                    if (m_mapBad2Good[aQuery.BadSpelling] != aQuery.GoodSpelling)
                    {
                        // then throw an error unless it has the same result
                        throw new ApplicationException(String.Format("This new 'Bad Form' (i.e. '{0}') is already associated with another Good Form, '{1}'! If you really want to do this, you should edit the other record.",
                                                                     aQuery.BadSpelling, m_mapBad2Good[aQuery.BadSpelling]));
                    }
                }

                // now deal with the case where the good spelling was changed, which potentially involves updating
                //  the list of known good words. This could include changes to the bad form as well.
                else if (aQuery.GoodSpelling != strGoodValue)
                {
                    GoodValueEdited(theRow, strBadValue, aQuery.BadSpelling, strGoodValue, aQuery.GoodSpelling);
                }

                // check in case they changed the bad spelling only...
                else if (aQuery.BadSpelling != strBadValue)
                {
                    System.Diagnostics.Debug.Assert(aQuery.GoodSpelling == strGoodValue);
                    BadValueOnlyEdited(theBadCell, strBadValue, aQuery.BadSpelling, aQuery.GoodSpelling);
                }
#endif
                buttonOK.Enabled = true;
            }
        }
コード例 #3
0
		protected void ProcessEditRow(DataGridViewRow theRow)
		{
			DataGridViewCell theBadCell = theRow.Cells[cnBadSpelling];
			DataGridViewCell theGoodCell = theRow.Cells[cnGoodSpelling];
			string strBadValue = (string)theBadCell.Value;
			string strGoodValue = (string)theGoodCell.Value;

			QueryGoodSpelling aQuery = new QueryGoodSpelling(dataGridView.RowsDefaultCellStyle.Font);
			DialogResult res = aQuery.ShowDialog(strBadValue, strGoodValue, strBadValue, (strBadValue != null));
			if (res == DialogResult.Abort)
			{
				// this means delete
				dataGridView.Rows.Remove(theRow);

#if !TurnOffSF30
				if (!String.IsNullOrEmpty(strBadValue) && EditingCscBad2GoodList)
					m_mapBad2Good.Remove(strBadValue);
#endif
				buttonOK.Enabled = true;
			}
			else if (res == DialogResult.OK)
			{
				// try to organize the permutations:
				//    o both columns were initially null (i.e. IsNewRow = true) and now have values
				//      ->  both must now be non-null
				//      ->  new 'bad' must not already exist
				//    o both columns were non-null and now the 'good' value is changed
				//      ->  if the old 'good' value is still present elsewhere, then query to change those also
				//      ->  change the good value in the row (and bad if necessary)
				//      ->  change the good value in the white list as well
				//    o both columns were non-null and now the 'bad' value (only) is changed
				//      ->  change the bad value in the row
				//      ->  change the bad value in the bad2good list
				if (String.IsNullOrEmpty(aQuery.BadSpelling) || String.IsNullOrEmpty(aQuery.GoodSpelling))
				{
					// if either of them are null...
					throw new ApplicationException("The 'Bad' and 'Good' forms are not allowed to be nothing!");
				}
#if !TurnOffSF30
				/* I don't recall what I was thinking about this one. Sometimes having the good and bad spelling
				 * be the same is the only way to force a replacement to not happen (e.g. if a shorter string
				 * replacement rule would otherwise override a longer string and you don't want that)
				 * Oh: maybe that applied with CSC since that always only worked with whole word forms... move
				 * it into the conditional compile area...
				else if (aQuery.BadSpelling == aQuery.GoodSpelling)
				{
					// if they're the same...
					throw new ApplicationException("The new 'Bad' and 'Good' forms must be different from each other!");
				}
				*/
				else if (!EditingCscBad2GoodList)
#endif
				{
					// Legacy SpellFixer
					theBadCell.Value = aQuery.BadSpelling;
					theGoodCell.Value = aQuery.GoodSpelling;
				}
#if !TurnOffSF30
				else if (String.IsNullOrEmpty(strBadValue) && m_mapBad2Good.ContainsKey(aQuery.BadSpelling))
				{
					// if we're adding a new one (i.e. strBadValue == null) and it's already in the list...
					// ... we don't want to have added the dummy record (so delete it)
					dataGridView.Rows.Remove(theRow);

					// scroll the existing match into view.
					foreach (DataGridViewRow aRow in dataGridView.Rows)
						if (aQuery.BadSpelling == (string)aRow.Cells[cnBadSpelling].Value)
						{
							aRow.Selected = true;
							dataGridView.FirstDisplayedScrollingRowIndex = aRow.Index;
							break;
						}

					// if the value was, in fact, different, then throw an exception
					if (m_mapBad2Good[aQuery.BadSpelling] != aQuery.GoodSpelling)
					{
						// then throw an error unless it has the same result
						throw new ApplicationException(String.Format("This new 'Bad Form' (i.e. '{0}') is already associated with another Good Form, '{1}'! If you really want to do this, you should edit the other record.",
							aQuery.BadSpelling, m_mapBad2Good[aQuery.BadSpelling]));
					}
				}

				// now deal with the case where the good spelling was changed, which potentially involves updating
				//  the list of known good words. This could include changes to the bad form as well.
				else if (aQuery.GoodSpelling != strGoodValue)
				{
					GoodValueEdited(theRow, strBadValue, aQuery.BadSpelling, strGoodValue, aQuery.GoodSpelling);
				}

				// check in case they changed the bad spelling only...
				else if (aQuery.BadSpelling != strBadValue)
				{
					System.Diagnostics.Debug.Assert(aQuery.GoodSpelling == strGoodValue);
					BadValueOnlyEdited(theBadCell, strBadValue, aQuery.BadSpelling, aQuery.GoodSpelling);
				}
#endif
				buttonOK.Enabled = true;
			}
		}
コード例 #4
0
ファイル: SpellingFixerEC.cs プロジェクト: sillsdev/WorldPad
        public void FindReplacementRule(string strWord)
        {
            // first make sure the CC table exists
            if ((m_strConverterSpec != null) && File.Exists(m_strConverterSpec))
            {
                CleanWord(ref strWord);

                // Open the CC table that has the mappings and put them in a DataTable.
                DataTable myTable;
                Encoding  enc = GetEncoding;
                if (InitializeDataTableFromCCTable(m_strConverterSpec, enc, WordBoundaryDelimiter, out myTable))
                {
                    // temporary filename for temporary CC tables (to check portions of the file at a time)
                    string strTempName = Path.GetTempFileName();

                    // get a CC table EncConverter
                    IEncConverter aEC = new EncConverters().NewEncConverterByImplementationType(EncConverters.strTypeSILcc);

                    // check to make sure that the whole table has a rule which changes it (it might not)
                    int nFoundIndex = -1;
                    if (ChaChaChaChaChanges(aEC, m_strConverterSpec, strWord))
                    {
                        // do a binary search to find the one replacement rule that causes a change
                        int nLength = myTable.Rows.Count, nIndex = 0;
                        nFoundIndex = nIndex;
                        DataTable tblTestingRules = GetDataTable;

                        while (nLength > 1)
                        {
                            // check the lower half
                            int nLowHalfLength = nLength / 2;
                            // GetPortionOfTable(myTable, nIndex, nLowHalfLength, ref tblTestingRules);
                            if (ChaChaChaChaChanges(aEC, strTempName, enc, strWord, myTable, nIndex, nLowHalfLength))
                            {
                                // found in the lower half
                                nFoundIndex = nIndex;
                                nLength     = nLowHalfLength;
                            }
                            else
                            {
                                // otherwise check in the upper half
                                // GetPortionOfTable(myTable, nIndex + nLowHalfLength, nLength - nLowHalfLength, ref tblTestingRules);
                                if (ChaChaChaChaChanges(aEC, strTempName, enc, strWord, myTable, nIndex + nLowHalfLength, nLength - nLowHalfLength))
                                {
                                    // found in the upper half
                                    nIndex     += nLowHalfLength;
                                    nFoundIndex = nIndex;
                                    nLength    -= nLowHalfLength;
                                }
                            }
                        }
                    }

                    // clean up the temporary file.
                    File.Delete(strTempName);

                    // if we didn't see any rules that manipulate the input string, then see if any generate
                    //  the input string (i.e. compare the word against the right-hand side)
                    if (nFoundIndex == -1)
                    {
                        // let's trim it of external spaces first
                        strWord = strWord.Trim();
                        for (nFoundIndex = 0; nFoundIndex < myTable.Rows.Count; nFoundIndex++)
                        {
                            DataRow row = myTable.Rows[nFoundIndex];
                            if (strWord == (string)row[strColumnRhs])
                            {
                                break;
                            }
                        }
                    }

                    if (nFoundIndex == myTable.Rows.Count)
                    {
                        // none found
                        MessageBox.Show(String.Format("There are no substitution rules that apply to this word ({0})!", strWord), cstrCaption);
                    }

                    else if ((nFoundIndex >= 0) && (nFoundIndex < myTable.Rows.Count))
                    {
                        DataRow           row    = myTable.Rows[nFoundIndex];
                        QueryGoodSpelling aQuery = new QueryGoodSpelling(m_font);
                        DialogResult      res    = aQuery.ShowDialog((string)row[strColumnLhs], (string)row[strColumnRhs], GetComment(row), true);
                        bool bRewrite            = false;
                        if (res == DialogResult.Abort)
                        {
                            // this means to delete the bad substitution rule
                            myTable.Rows.RemoveAt(nFoundIndex);
                            bRewrite = true;
                        }

                        // if the user clicks OK and has made a change...
                        if ((res == DialogResult.OK) &&
                            (((string)row[strColumnLhs] != aQuery.BadSpelling) ||
                             ((string)row[strColumnRhs] != aQuery.GoodSpelling)
                            )
                            )
                        {
                            // update the table and rewrite
                            row[strColumnLhs] = aQuery.BadSpelling;
                            row[strColumnRhs] = aQuery.GoodSpelling;
                            row[strColumnCmt] = strWord;
                            bRewrite          = true;
                        }

                        if (bRewrite)
                        {
                            // write the newly updated DataTable
                            LoginSF.ReWriteCCTableHeader(m_strConverterSpec, PunctuationAndWhiteSpace, enc);
                            AppendCCTableFromDataTable(m_strConverterSpec, enc, WordBoundaryDelimiter, PunctuationAndWhiteSpace, myTable);
                        }
                    }
                }
            }
        }
コード例 #5
0
ファイル: SpellingFixerEC.cs プロジェクト: sillsdev/WorldPad
		public void FindReplacementRule(string strWord)
		{
			// first make sure the CC table exists
			if ((m_strConverterSpec != null) && File.Exists(m_strConverterSpec))
			{
				CleanWord(ref strWord);

				// Open the CC table that has the mappings and put them in a DataTable.
				DataTable myTable;
				Encoding enc = GetEncoding;
				if (InitializeDataTableFromCCTable(m_strConverterSpec, enc, WordBoundaryDelimiter, out myTable))
				{
					// temporary filename for temporary CC tables (to check portions of the file at a time)
					string strTempName = Path.GetTempFileName();

					// get a CC table EncConverter
					IEncConverter aEC = new EncConverters().NewEncConverterByImplementationType(EncConverters.strTypeSILcc);

					// check to make sure that the whole table has a rule which changes it (it might not)
					int nFoundIndex = -1;
					if (ChaChaChaChaChanges(aEC, m_strConverterSpec, strWord))
					{
						// do a binary search to find the one replacement rule that causes a change
						int nLength = myTable.Rows.Count, nIndex = 0;
						nFoundIndex = nIndex;
						DataTable tblTestingRules = GetDataTable;

						while (nLength > 1)
						{
							// check the lower half
							int nLowHalfLength = nLength / 2;
							// GetPortionOfTable(myTable, nIndex, nLowHalfLength, ref tblTestingRules);
							if (ChaChaChaChaChanges(aEC, strTempName, enc, strWord, myTable, nIndex, nLowHalfLength))
							{
								// found in the lower half
								nFoundIndex = nIndex;
								nLength = nLowHalfLength;
							}
							else
							{
								// otherwise check in the upper half
								// GetPortionOfTable(myTable, nIndex + nLowHalfLength, nLength - nLowHalfLength, ref tblTestingRules);
								if (ChaChaChaChaChanges(aEC, strTempName, enc, strWord, myTable, nIndex + nLowHalfLength, nLength - nLowHalfLength))
								{
									// found in the upper half
									nIndex += nLowHalfLength;
									nFoundIndex = nIndex;
									nLength -= nLowHalfLength;
								}
							}
						}
					}

					// clean up the temporary file.
					File.Delete(strTempName);

					// if we didn't see any rules that manipulate the input string, then see if any generate
					//  the input string (i.e. compare the word against the right-hand side)
					if (nFoundIndex == -1)
					{
						// let's trim it of external spaces first
						strWord = strWord.Trim();
						for (nFoundIndex = 0; nFoundIndex < myTable.Rows.Count; nFoundIndex++)
						{
							DataRow row = myTable.Rows[nFoundIndex];
							if (strWord == (string)row[strColumnRhs])
								break;
						}
					}

					if (nFoundIndex == myTable.Rows.Count)
					{
						// none found
						MessageBox.Show(String.Format("There are no substitution rules that apply to this word ({0})!", strWord), cstrCaption);
					}

					else if ((nFoundIndex >= 0) && (nFoundIndex < myTable.Rows.Count))
					{
						DataRow row = myTable.Rows[nFoundIndex];
						QueryGoodSpelling aQuery = new QueryGoodSpelling(m_font);
						DialogResult res = aQuery.ShowDialog((string)row[strColumnLhs], (string)row[strColumnRhs], GetComment(row), true);
						bool bRewrite = false;
						if (res == DialogResult.Abort)
						{
							// this means to delete the bad substitution rule
							myTable.Rows.RemoveAt(nFoundIndex);
							bRewrite = true;
						}

						// if the user clicks OK and has made a change...
						if ((res == DialogResult.OK)
							&& (((string)row[strColumnLhs] != aQuery.BadSpelling)
								|| ((string)row[strColumnRhs] != aQuery.GoodSpelling)
								)
						)
						{
							// update the table and rewrite
							row[strColumnLhs] = aQuery.BadSpelling;
							row[strColumnRhs] = aQuery.GoodSpelling;
							row[strColumnCmt] = strWord;
							bRewrite = true;
						}

						if (bRewrite)
						{
							// write the newly updated DataTable
							LoginSF.ReWriteCCTableHeader(m_strConverterSpec, PunctuationAndWhiteSpace, enc);
							AppendCCTableFromDataTable(m_strConverterSpec, enc, WordBoundaryDelimiter, PunctuationAndWhiteSpace, myTable);
						}
					}
				}
			}
		}
コード例 #6
0
ファイル: SpellingFixerEC.cs プロジェクト: sillsdev/WorldPad
		protected void QueryAndAppend(string strBadWord)
		{
			QueryGoodSpelling aQuery = new QueryGoodSpelling(m_font);
			if (aQuery.ShowDialog(strBadWord, strBadWord, strBadWord, false) == DialogResult.OK)
			{
				// if it was legacy encoded, then we need to convert the data to narrow using
				//  the code page the user specified (or we got out of the repository)
				Encoding enc = GetEncoding;

				// get a stream writer for these encoding and append
				StreamWriter sw = new StreamWriter(m_strConverterSpec, true, enc);
				sw.WriteLine(FormatSubstitutionRule(aQuery.BadSpelling, aQuery.GoodSpelling, WordBoundaryDelimiter, strBadWord));
				sw.Flush();
				sw.Close();
			}
		}