SILUBS.ScriptureChecks.QuotationCheck.GetReferences C# (CSharp) Method

GetReferences() public method

Gets a list if TextTokenSubstrings containing the references and character offsets where quotation problems occur.
public GetReferences ( IEnumerable tokens, string desiredKey ) : List
tokens IEnumerable The tokens (from the data source) to check for quotation problems.
desiredKey string empty string.
return List
		public List<TextTokenSubstring> GetReferences(IEnumerable<ITextToken> tokens, string desiredKey)
		{
			m_charCategorizer = m_chkDataSource.CharacterCategorizer;
			ValidItems = m_chkDataSource.GetParameterValue(m_validItemsParameter);
			InvalidItems = m_chkDataSource.GetParameterValue(m_invalidItemsParameter);

			QuotationMarkCategorizer qmCategorizer = new QuotationMarkCategorizer(m_chkDataSource);
			m_qmProblems = new List<TextTokenSubstring>();

			QTokenProcessor bodyProcessor =	new QTokenProcessor(m_chkDataSource,
				m_charCategorizer, qmCategorizer, desiredKey, m_qmProblems);

			QTokenProcessor noteProcessor =	new QTokenProcessor(m_chkDataSource,
				m_charCategorizer, qmCategorizer, desiredKey, m_qmProblems);

			VerseTextToken scrToken = new VerseTextToken();
			foreach (ITextToken tok in tokens)
			{
				if (tok.TextType == TextType.Note)
				{
					// If a new note is starting finalize any sequences from the previous note.
					if (tok.IsNoteStart)
						noteProcessor.FinalizeResult();
					noteProcessor.ProcessToken(tok, null);
				}
				else if (tok.TextType == TextType.Verse || tok.TextType == TextType.Other ||
					tok.IsParagraphStart)
				{
					scrToken.Token = tok;
					// body text: finalize any note that was in progress and continue with body text
					noteProcessor.FinalizeResult();
					bodyProcessor.ProcessToken(tok, scrToken);
				}
			}

			noteProcessor.FinalizeResult();
			bodyProcessor.FinalizeResult();
			return m_qmProblems;
		}
	}

Usage Example

Ejemplo n.º 1
0
		void Test(string[,] result, string text)
		{
			m_source.Text = text;

			QuotationCheck check = new QuotationCheck(m_source);
			List<TextTokenSubstring> tts =
				check.GetReferences(m_source.TextTokens(), "");

			for (int i = 0; i < tts.Count; i++)
			{
				Console.WriteLine(tts[i].Text);
				Console.WriteLine(tts[i].Message);
				Debug.WriteLine(tts[i].Text);
				Debug.WriteLine(tts[i].Message);
			}

			Assert.AreEqual(result.GetUpperBound(0) + 1, tts.Count,
				"A different number of results was returned than what was expected." );

			for (int i = 0; i <= result.GetUpperBound(0); ++i)
			{
				// Verify the Reference, Message, and Details columns of the results pane.
				// Verifies empty string, but not null, for the reference (for original tests).
				if (result.GetUpperBound(1) == 2)
					Assert.AreEqual(result[i, 2], tts[i].FirstToken.ScrRefString, "Reference number: " + i);

				Assert.AreEqual(result[i, 0], tts[i].Text, "Text number: " + i.ToString());
				Assert.AreEqual(result[i, 1], tts[i].Message, "Message number: " + i.ToString());
			}
		}