Example #1
0
        public void Check_ValidPatternsAreNotReported()
        {
            PuncPatternsList puncPatterns = new PuncPatternsList();
            PuncPattern      pattern      = new PuncPattern();

            pattern.Pattern    = "._";
            pattern.ContextPos = ContextPosition.WordFinal;
            pattern.Status     = PuncPatternStatus.Valid;
            puncPatterns.Add(pattern);
            pattern            = new PuncPattern();
            pattern.Pattern    = ",";
            pattern.ContextPos = ContextPosition.WordBreaking;
            pattern.Status     = PuncPatternStatus.Invalid;
            puncPatterns.Add(pattern);
            m_dataSource.SetParameterValue("PunctuationPatterns", puncPatterns.XmlString);
            m_dataSource.SetParameterValue("PunctCheckLevel", "Intermediate");

            PunctuationCheck check = new PunctuationCheck(m_dataSource);

            m_dataSource.Text = "\\p This is nice. By nice,I mean really nice!";

            check.Check(m_dataSource.TextTokens(), RecordError);

            Assert.AreEqual(2, m_errors.Count);
            CheckError(0, "This is nice. By nice,I mean really nice!", 21, ",", "Invalid punctuation pattern");
            CheckError(1, "This is nice. By nice,I mean really nice!", 40, "!", "Unspecified use of punctuation pattern");
        }
Example #2
0
        public void Check_PatternsWithSpaceSeparatedQuoteMarks()
        {
            PuncPatternsList puncPatterns = new PuncPatternsList();
            PuncPattern      pattern      = new PuncPattern();

            pattern.Pattern    = ",_";
            pattern.ContextPos = ContextPosition.WordFinal;
            pattern.Status     = PuncPatternStatus.Valid;
            puncPatterns.Add(pattern);
            pattern            = new PuncPattern();
            pattern.Pattern    = "_\u201C";
            pattern.ContextPos = ContextPosition.WordInitial;
            pattern.Status     = PuncPatternStatus.Valid;
            puncPatterns.Add(pattern);
            pattern            = new PuncPattern();
            pattern.Pattern    = "_\u2018";
            pattern.ContextPos = ContextPosition.WordInitial;
            pattern.Status     = PuncPatternStatus.Valid;
            puncPatterns.Add(pattern);
            m_dataSource.SetParameterValue("PunctuationPatterns", puncPatterns.XmlString);
            m_dataSource.SetParameterValue("PunctCheckLevel", "Intermediate");

            PunctuationCheck check = new PunctuationCheck(m_dataSource);

            m_dataSource.Text = "\\p Tom replied, \u201CBill said, \u2018Yes!\u2019\u202F\u201D";

            check.Check(m_dataSource.TextTokens(), RecordError);

            Assert.AreEqual(1, m_errors.Count);
            CheckError(0, "Tom replied, \u201CBill said, \u2018Yes!\u2019\u202F\u201D", 29, "!\u2019\u202F\u201D", "Unspecified use of punctuation pattern");
        }
Example #3
0
        public void GetParameterValue_SentenceFinalPunctuation()
        {
            // Set up the punctuation for a Roman-script vernacular writing system.
            int              hvoWs = Cache.DefaultVernWs;
            IWritingSystem   ws    = Cache.ServiceLocator.WritingSystemManager.Get(hvoWs);
            PuncPatternsList list  = new PuncPatternsList();

            list.Add(new PuncPattern(". ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
            list.Add(new PuncPattern("? ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
            list.Add(new PuncPattern("! ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
            list.Add(new PuncPattern("; ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
            list.Add(new PuncPattern("- ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
            list.Add(new PuncPattern(") ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
            list.Add(new PuncPattern("( ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
            list.Add(new PuncPattern(": ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
            ws.PunctuationPatterns = list.XmlString;

            // Get the sentence-final punctuation
            string sentenceFinalPunc = m_dataSource.GetParameterValue("SentenceFinalPunctuation");

            // We expect that only sentence-final punctuation would be returned.
            Assert.AreEqual(".?!", sentenceFinalPunc);
        }
Example #4
0
        public void Check_ParaWithSingleQuotationMark()
        {
            PuncPatternsList puncPatterns = new PuncPatternsList();
            PuncPattern      pattern      = new PuncPattern();

            pattern.Pattern    = "._";
            pattern.ContextPos = ContextPosition.WordFinal;
            pattern.Status     = PuncPatternStatus.Valid;
            puncPatterns.Add(pattern);
            m_dataSource.SetParameterValue("PunctuationPatterns", puncPatterns.XmlString);
            m_dataSource.SetParameterValue("PunctCheckLevel", "Intermediate");

            PunctuationCheck check = new PunctuationCheck(m_dataSource);

            m_dataSource.Text = "\\p wow\u201D\\p \u2019";

            check.Check(m_dataSource.TextTokens(), RecordError);

            Assert.AreEqual(2, m_errors.Count);
            CheckError(0, "wow\u201D", 3, "\u201D", "Unspecified use of punctuation pattern");
            CheckError(1, "\u2019", 0, "\u2019", "Unspecified use of punctuation pattern");
        }
		public void GetParameterValue_SentenceFinalPunctuation()
		{
			// Set up the punctuation for a Roman-script vernacular writing system.
			int hvoWs = Cache.DefaultVernWs;
			IWritingSystem ws = Cache.ServiceLocator.WritingSystemManager.Get(hvoWs);
			PuncPatternsList list = new PuncPatternsList();
			list.Add(new PuncPattern(". ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
			list.Add(new PuncPattern("? ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
			list.Add(new PuncPattern("! ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
			list.Add(new PuncPattern("; ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
			list.Add(new PuncPattern("- ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
			list.Add(new PuncPattern(") ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
			list.Add(new PuncPattern("( ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
			list.Add(new PuncPattern(": ", ContextPosition.WordFinal, PuncPatternStatus.Valid));
			ws.PunctuationPatterns = list.XmlString;

			// Get the sentence-final punctuation
			string sentenceFinalPunc = m_dataSource.GetParameterValue("SentenceFinalPunctuation");

			// We expect that only sentence-final punctuation would be returned.
			Assert.AreEqual(".?!", sentenceFinalPunc);
		}
		public void Check_ParaWithSingleQuotationMark()
		{
			PuncPatternsList puncPatterns = new PuncPatternsList();
			PuncPattern pattern = new PuncPattern();
			pattern.Pattern = "._";
			pattern.ContextPos = ContextPosition.WordFinal;
			pattern.Status = PuncPatternStatus.Valid;
			puncPatterns.Add(pattern);
			m_dataSource.SetParameterValue("PunctuationPatterns", puncPatterns.XmlString);
			m_dataSource.SetParameterValue("PunctCheckLevel", "Intermediate");

			PunctuationCheck check = new PunctuationCheck(m_dataSource);
			m_dataSource.Text = "\\p wow\u201D\\p \u2019";

			check.Check(m_dataSource.TextTokens(), RecordError);

			Assert.AreEqual(2, m_errors.Count);
			CheckError(0, "wow\u201D", 3, "\u201D", "Unspecified use of punctuation pattern");
			CheckError(1, "\u2019", 0, "\u2019", "Unspecified use of punctuation pattern");
		}
		public void Check_PatternsWithSpaceSeparatedQuoteMarks()
		{
			PuncPatternsList puncPatterns = new PuncPatternsList();
			PuncPattern pattern = new PuncPattern();
			pattern.Pattern = ",_";
			pattern.ContextPos = ContextPosition.WordFinal;
			pattern.Status = PuncPatternStatus.Valid;
			puncPatterns.Add(pattern);
			pattern = new PuncPattern();
			pattern.Pattern = "_\u201C";
			pattern.ContextPos = ContextPosition.WordInitial;
			pattern.Status = PuncPatternStatus.Valid;
			puncPatterns.Add(pattern);
			pattern = new PuncPattern();
			pattern.Pattern = "_\u2018";
			pattern.ContextPos = ContextPosition.WordInitial;
			pattern.Status = PuncPatternStatus.Valid;
			puncPatterns.Add(pattern);
			m_dataSource.SetParameterValue("PunctuationPatterns", puncPatterns.XmlString);
			m_dataSource.SetParameterValue("PunctCheckLevel", "Intermediate");

			PunctuationCheck check = new PunctuationCheck(m_dataSource);

			m_dataSource.Text = "\\p Tom replied, \u201CBill said, \u2018Yes!\u2019\u202F\u201D";

			check.Check(m_dataSource.TextTokens(), RecordError);

			Assert.AreEqual(1, m_errors.Count);
			CheckError(0, "Tom replied, \u201CBill said, \u2018Yes!\u2019\u202F\u201D", 29, "!\u2019\u202F\u201D", "Unspecified use of punctuation pattern");
		}
		public void Check_ValidPatternsAreNotReported()
		{
			PuncPatternsList puncPatterns = new PuncPatternsList();
			PuncPattern pattern = new PuncPattern();
			pattern.Pattern = "._";
			pattern.ContextPos = ContextPosition.WordFinal;
			pattern.Status = PuncPatternStatus.Valid;
			puncPatterns.Add(pattern);
			pattern = new PuncPattern();
			pattern.Pattern = ",";
			pattern.ContextPos = ContextPosition.WordBreaking;
			pattern.Status = PuncPatternStatus.Invalid;
			puncPatterns.Add(pattern);
			m_dataSource.SetParameterValue("PunctuationPatterns", puncPatterns.XmlString);
			m_dataSource.SetParameterValue("PunctCheckLevel", "Intermediate");

			PunctuationCheck check = new PunctuationCheck(m_dataSource);

			m_dataSource.Text = "\\p This is nice. By nice,I mean really nice!";

			check.Check(m_dataSource.TextTokens(), RecordError);

			Assert.AreEqual(2, m_errors.Count);
			CheckError(0, "This is nice. By nice,I mean really nice!", 21, ",", "Invalid punctuation pattern");
			CheckError(1, "This is nice. By nice,I mean really nice!", 40, "!", "Unspecified use of punctuation pattern");
		}