Beispiel #1
0
        public void TestEverything()
        {
            var sentences = new[] {
                "What you get by achieving your goals is not as important as what you become by achieving your goals .",
                "The price of anything is the amount of life you exchange for it .",
                "The light which puts out our eyes is darkness to us .",
                "Only that day dawns to which we are awake .",
                "There is more day to dawn. The sun is but a morning star ."
            };

            var sTagger = new SharpTagger(OpenSharpModel());
            var jTagger = new JavaTagger(OpenJavaModel());

            foreach (var sentence in sentences)
            {
                var tokens = WhitespaceTokenizer.Instance.Tokenize(sentence);

                var sTags = sTagger.Tag(tokens);
                var jTags = jTagger.tag(tokens);

                Assert.AreEqual(jTags.Length, sTags.Length);
                for (var i = 0; i < sTags.Length; i++)
                {
                    Assert.AreEqual(jTags[i], sTags[i]);
                }

                var sTop = sTagger.TopKSequences(tokens);
                var jTop = jTagger.topKSequences(tokens);

                Assert.AreEqual(jTop.Length, sTop.Length);

                for (var i = 0; i < sTop.Length; i++)
                {
                    var jOut   = jTop[i].getOutcomes();
                    var jProbs = jTop[i].getProbs();

                    Assert.AreEqual(jOut.size(), sTop[i].Outcomes.Count);

                    for (var j = 0; j < jOut.size(); j++)
                    {
                        Assert.AreEqual(jOut.get(j), sTop[i].Outcomes[j]);
                        Assert.AreEqual(jProbs[j], sTop[i].Probabilities[j], 0.0000000001d);
                    }

                    Assert.AreEqual(jTop[i].getScore(), sTop[i].Score, 0.0000000001d);
                }
            }
        }
Beispiel #2
0
        public void TestEverything() {
            var sentences = new[] {
                "What you get by achieving your goals is not as important as what you become by achieving your goals .",
                "The price of anything is the amount of life you exchange for it .",
                "The light which puts out our eyes is darkness to us .",
                "Only that day dawns to which we are awake .",
                "There is more day to dawn. The sun is but a morning star ."
            };

            var sTagger = new SharpTagger(OpenSharpModel());
            var jTagger = new JavaTagger(OpenJavaModel());

            foreach (var sentence in sentences) {
                var tokens = WhitespaceTokenizer.Instance.Tokenize(sentence);

                var sTags = sTagger.Tag(tokens);
                var jTags = jTagger.tag(tokens);

                Assert.AreEqual(jTags.Length, sTags.Length);
                for (var i = 0; i < sTags.Length; i++) {                   
                    Assert.AreEqual(jTags[i], sTags[i]);
                }

                var sTop = sTagger.TopKSequences(tokens);
                var jTop = jTagger.topKSequences(tokens);

                Assert.AreEqual(jTop.Length, sTop.Length);

                for (var i = 0; i < sTop.Length; i++) {

                    var jOut = jTop[i].getOutcomes();
                    var jProbs = jTop[i].getProbs();

                    Assert.AreEqual(jOut.size(), sTop[i].Outcomes.Count);

                    for (var j = 0; j < jOut.size(); j++) {
                        Assert.AreEqual(jOut.get(j), sTop[i].Outcomes[j]);
                        Assert.AreEqual(jProbs[j], sTop[i].Probabilities[j], 0.0000000001d);
                    }

                    Assert.AreEqual(jTop[i].getScore(), sTop[i].Score, 0.0000000001d);
                }
            }
        }
Beispiel #3
0
        public void PartOfSpeechTagger()
        {
            using var modelIn = new java.io.FileInputStream(GetModel("en-pos-maxent.bin"));

            var model  = new opennlp.tools.postag.POSModel(modelIn);
            var tagger = new opennlp.tools.postag.POSTaggerME(model);

            var sentence = new[]
            {
                "Most", "large", "cities", "in", "the", "US", "had",
                "morning", "and", "afternoon", "newspapers", "."
            };
            var tags = tagger.tag(sentence);

            System.Console.WriteLine(string.Join(";", tags));
            Assert.AreEqual(12, tags.Length);

            var probs = tagger.probs();

            System.Console.WriteLine(string.Join(";", probs));
            Assert.AreEqual(12, probs.Length);
        }