Пример #1
0
        private static void TestSentences(JavaSDME javaMe, SharpSDME sharpME, string data) {
            var jSentences = javaMe.sentPosDetect(data);
            var sSentences = sharpME.SentPosDetect(data);

            var jProb = javaMe.getSentenceProbabilities();
            var sProb = sharpME.GetSentenceProbabilities();

            Assert.AreEqual(jSentences.Length, sSentences.Length);
            Assert.AreEqual(jProb.Length, sProb.Length);

            for (int i = 0; i < jSentences.Length; i++) {
                var a = jSentences[i].getCoveredText(data).toString(); // CharSequence -> string
                var b = sSentences[i].GetCoveredText(data);

                Assert.AreEqual(jSentences[i].getStart(), sSentences[i].Start);
                Assert.AreEqual(jSentences[i].getEnd(), sSentences[i].End);

                Assert.AreEqual(a, b);
                Assert.AreEqual(jProb[i], sProb[i]);
            }
        }
        private static void TestSentences(JavaSDME javaMe, SharpSDME sharpME, string data)
        {
            var jSentences = javaMe.sentPosDetect(data);
            var sSentences = sharpME.SentPosDetect(data);

            var jProb = javaMe.getSentenceProbabilities();
            var sProb = sharpME.GetSentenceProbabilities();

            Assert.AreEqual(jSentences.Length, sSentences.Length);
            Assert.AreEqual(jProb.Length, sProb.Length);

            for (var i = 0; i < jSentences.Length; i++)
            {
                var a = jSentences[i].getCoveredText(data).toString(); // CharSequence -> string
                var b = sSentences[i].GetCoveredText(data);

                Assert.AreEqual(jSentences[i].getStart(), sSentences[i].Start);
                Assert.AreEqual(jSentences[i].getEnd(), sSentences[i].End);

                Assert.AreEqual(a, b);
                Assert.AreEqual(jProb[i], sProb[i]);
            }
        }
        internal static void EvalSentences(SentenceDetectorME sentDetect) {
            const string sampleSentences1 = "This is a test. There are many tests, this is the second.";
            var sents = sentDetect.SentDetect(sampleSentences1);
            Assert.AreEqual(sents.Length, 2);
            Assert.AreEqual(sents[0], "This is a test.");
            Assert.AreEqual(sents[1], "There are many tests, this is the second.");
            var probs = sentDetect.GetSentenceProbabilities();
            Assert.AreEqual(probs.Length, 2);

            const string sampleSentences2 = "This is a test. There are many tests, this is the second";
            sents = sentDetect.SentDetect(sampleSentences2);
            Assert.AreEqual(sents.Length, 2);
            probs = sentDetect.GetSentenceProbabilities();
            Assert.AreEqual(probs.Length, 2);
            Assert.AreEqual(sents[0], "This is a test.");
            Assert.AreEqual(sents[1], "There are many tests, this is the second");

            const string sampleSentences3 = "This is a \"test\". He said \"There are many tests, this is the second.\"";
            sents = sentDetect.SentDetect(sampleSentences3);
            Assert.AreEqual(sents.Length, 2);
            probs = sentDetect.GetSentenceProbabilities();
            Assert.AreEqual(probs.Length, 2);
            Assert.AreEqual(sents[0], "This is a \"test\".");
            Assert.AreEqual(sents[1], "He said \"There are many tests, this is the second.\"");

            const string sampleSentences4 = "This is a \"test\". I said \"This is a test.\"  Any questions?";
            sents = sentDetect.SentDetect(sampleSentences4);
            Assert.AreEqual(sents.Length, 3);
            probs = sentDetect.GetSentenceProbabilities();
            Assert.AreEqual(probs.Length, 3);
            Assert.AreEqual(sents[0], "This is a \"test\".");
            Assert.AreEqual(sents[1], "I said \"This is a test.\"");
            Assert.AreEqual(sents[2], "Any questions?");

            const string sampleSentences5 = "This is a one sentence test space at the end.    ";
            sents = sentDetect.SentDetect(sampleSentences5);
            Assert.AreEqual(1, sentDetect.GetSentenceProbabilities().Length);
            Assert.AreEqual(sents[0], "This is a one sentence test space at the end.");

            const string sampleSentences6 = "This is a one sentences test with tab at the end.            ";
            sents = sentDetect.SentDetect(sampleSentences6);
            Assert.AreEqual(sents[0], "This is a one sentences test with tab at the end.");

            const string sampleSentences7 = "This is a test.    With spaces between the two sentences.";
            sents = sentDetect.SentDetect(sampleSentences7);
            Assert.AreEqual(sents[0], "This is a test.");
            Assert.AreEqual(sents[1], "With spaces between the two sentences.");

            const string sampleSentences9 = "";
            sents = sentDetect.SentDetect(sampleSentences9);
            Assert.AreEqual(0, sents.Length);

            const string sampleSentences10 = "               "; // whitespaces and tabs
            sents = sentDetect.SentDetect(sampleSentences10);
            Assert.AreEqual(0, sents.Length);

            const string sampleSentences11 = "This is test sentence without a dot at the end and spaces          ";
            sents = sentDetect.SentDetect(sampleSentences11);
            Assert.AreEqual(sents[0], "This is test sentence without a dot at the end and spaces");
            probs = sentDetect.GetSentenceProbabilities();
            Assert.AreEqual(1, probs.Length);

            const string sampleSentence12 = "    This is a test.";
            sents = sentDetect.SentDetect(sampleSentence12);
            Assert.AreEqual(sents[0], "This is a test.");

            const string sampleSentence13 = " This is a test";
            sents = sentDetect.SentDetect(sampleSentence13);
            Assert.AreEqual(sents[0], "This is a test");

            // Test that sentPosDetect also works
            var pos = sentDetect.SentPosDetect(sampleSentences2);
            Assert.AreEqual(pos.Length, 2);
            probs = sentDetect.GetSentenceProbabilities();
            Assert.AreEqual(probs.Length, 2);
            Assert.AreEqual(new Span(0, 15), pos[0]);
            Assert.AreEqual(new Span(16, 56), pos[1]);
        }