Check for capitalization: styles that should begin with a capital letter and words after sentence-final punctuation.
Inheritance: IScriptureCheck
Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a checking error if character style requires an initial uppercase letter,
        /// but the tssFirstLetter is lowercase.
        /// </summary>
        /// <param name="tok">The Scripture token.</param>
        /// <param name="ttsFirstLetter">The token substring of the first word-forming character
        /// in the given token.</param>
        /// <param name="result">The result.</param>
        /// <returns><c>true</c> if an error was added to the list of results; otherwise
        /// <c>false</c></returns>
        /// ------------------------------------------------------------------------------------
        private bool CheckForCharStyleCapilizationError(ITextToken tok,
                                                        TextTokenSubstring ttsFirstLetter, List <TextTokenSubstring> result)
        {
            if (m_foundCharacterText)
            {
                return(false);
            }

            m_foundCharacterText = true;

            // The first word-forming character of the character style is lowercase.
            // Look it up in the capitalized styles dictionary to determine if it should be uppercase.
            StyleCapInfo styleCapInfo;

            if (m_allCapitalizedStyles.TryGetValue(m_characterStyle, out styleCapInfo) &&
                styleCapInfo.m_type == StyleInfo.StyleTypes.character)
            {
                ttsFirstLetter.InventoryText = m_characterStyle;
                ttsFirstLetter.Message       = CapitalizationCheck.GetErrorMessage(m_checksDataSource,
                                                                                   styleCapInfo.m_capCheck, m_characterStyle);
                result.Add(ttsFirstLetter);
                return(true);
            }
            return(false);
        }
		public override void TestSetup()
		{
			base.TestSetup();
			m_dataSource = new TestChecksDataSource();
			m_dataSource.SetParameterValue("StylesInfo", stylesInfo);
			m_dataSource.SetParameterValue("SentenceFinalPunctuation", ".?!");
			m_check = new CapitalizationCheck(m_dataSource);
		}
		void Test(string[] result, string text)
		{
			source.Text = text;

			source.SetParameterValue("StylesInfo", stylesInfo);
			source.SetParameterValue("SentenceFinalPunctuation", ".!?");
			CapitalizationCheck check = new CapitalizationCheck(source);
			List<TextTokenSubstring> tts =
				check.GetReferences(source.TextTokens());

			Assert.AreEqual(result.Length, tts.Count,
				"A different number of results was returned from what was expected." );

			for (int i = 0; i < result.Length; i++)
				Assert.AreEqual(result[i], tts[i].InventoryText, "Result number: " + i);
		}
Example #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Processes the Scripture token.
        /// </summary>
        /// <param name="tok">The token.</param>
        /// <param name="result">The result.</param>
        /// ------------------------------------------------------------------------------------
        public void ProcessToken(ITextToken tok, List <TextTokenSubstring> result)
        {
            string tokenText = RemoveAbbreviations(tok);

            RecordParagraphStyle(tok);
            RecordCharacterStyle(tok);

            // must be at least one character in token to check the case of
            if (tok.Text == String.Empty)
            {
                return;
            }

            for (int iChar = 0; iChar < tokenText.Length; iChar++)
            {
                char ch = tokenText[iChar];

                if (IsSentenceFinalPunctuation(ch))
                {
                    m_fAtSentenceStart = iChar + 1 == tokenText.Length ||
                                         (iChar + 1 < tokenText.Length && !char.IsDigit(tokenText[iChar + 1]));
                    continue;
                }

                if (!m_categorizer.IsWordFormingCharacter(ch))
                {
                    continue;
                }

                if (m_categorizer.IsLower(ch))
                {
                    TextTokenSubstring tts = GetSubstring(tok, iChar);

                    if (!CheckForParaCapitalizationError(tok, tts, result) &&
                        !CheckForCharStyleCapilizationError(tok, tts, result) &&
                        m_fAtSentenceStart)
                    {
                        tts.Message = CapitalizationCheck.GetErrorMessage(m_checksDataSource,
                                                                          StyleCapInfo.CapCheckTypes.SentenceInitial, string.Empty);
                        result.Add(tts);
                    }
                }
                m_fAtSentenceStart   = false;
                m_foundCharacterText = true;
                m_foundParagraphText = true;
            }
        }
Example #5
0
        void Test(string[] result, string text)
        {
            source.Text = text;

            source.SetParameterValue("StylesInfo", stylesInfo);
            source.SetParameterValue("SentenceFinalPunctuation", ".!?");
            CapitalizationCheck       check = new CapitalizationCheck(source);
            List <TextTokenSubstring> tts   =
                check.GetReferences(source.TextTokens());

            Assert.AreEqual(result.Length, tts.Count,
                            "A different number of results was returned from what was expected.");

            for (int i = 0; i < result.Length; i++)
            {
                Assert.AreEqual(result[i], tts[i].InventoryText, "Result number: " + i);
            }
        }