コード例 #1
0
        public static IEnumerable<TransitionEmissions> BuildTransitionEmissionsFromBrownText()
        {
            var assembly = Assembly.GetExecutingAssembly ();

            using (var fileStream = assembly.GetManifestResourceStream (Brown_Ca01File)) {
                if (fileStream == null) {
                    throw new InvalidOperationException ("brown-ca01.txt should exist. It doesn't, so you're seeing this error");
                }

                using (var stringReader = new StreamReader (fileStream)) {
                    string line = stringReader.ReadLine ();

                    while (line != null) {
                        var transitionEmissions = new TransitionEmissions ();

                        foreach (var tuple in ReadLine(line)) {
                            transitionEmissions.AddTransitionEmission (tuple.Item1, tuple.Item2);
                        }

                        yield return transitionEmissions;

                        line = stringReader.ReadLine ();
                    }
                }
            }
        }
コード例 #2
0
        public void ExceptionThrownWhenTransitionIsNull()
        {
            // arrange
            var transitionEmission = new TransitionEmissions ();

            // act
            transitionEmission.AddTransitionEmission (null, Emission);

            // assert - exception
        }
コード例 #3
0
        public void RecordsAddedWhenAccessedThroughMethod()
        {
            // arrange
            var transitionEmission = new TransitionEmissions ();

            // act
            transitionEmission.AddTransitionEmission (Transition, Emission);

            // assert
            Assert.AreEqual (1, transitionEmission.Records.Count);
            Assert.AreEqual (Transition, transitionEmission.Records [0].Transition);
            Assert.AreEqual (Emission, transitionEmission.Records [0].Emission);
        }
コード例 #4
0
        public void HiddenMarkovModelInstantiatedWithProperTransitionEmissions()
        {
            // arrange
            const string Transition = "noun";
            const string Emission = "Cardio";

            var transitionEmissions = new TransitionEmissions ();
            transitionEmissions.AddTransitionEmission (Transition, Emission);
            var transitionEmissionsList = new List<TransitionEmissions> ();
            transitionEmissionsList.Add (transitionEmissions);

            var hmm = new HiddenMarkovModelBuilder (transitionEmissionsList).Build();

            // act
            var result = hmm.GetEmissions (new[] { Transition });

            // assert
            Assert.AreEqual (1, result.Count ());
            Assert.AreEqual (Emission, result.First ().Emissions.First());
        }
コード例 #5
0
        private List<TransitionEmissions> BuildTestTransitionEmissions()
        {
            // http://nlp.stanford.edu:8080/parser/index.jsp - Thank You!
            // My dog also likes eating sausage.
            // My/PRP$ dog/NN also/RB likes/VBZ eating/VBG sausage/NN ./.
            var firstTransitionEmissions = new TransitionEmissions ();
            firstTransitionEmissions.AddTransitionEmission ("PRP$", "My");
            firstTransitionEmissions.AddTransitionEmission ("NN", "dog");
            firstTransitionEmissions.AddTransitionEmission ("RB", "also");
            firstTransitionEmissions.AddTransitionEmission ("VBZ", "likes");
            firstTransitionEmissions.AddTransitionEmission ("VBG", "eating");
            firstTransitionEmissions.AddTransitionEmission ("NN", "sausage");
            firstTransitionEmissions.AddTransitionEmission (".", ".");

            // My/PRP$ dog/NN likes/VBZ eating/VBG turkey/NN ./.
            var secondTransitionEmissions = new TransitionEmissions ();
            secondTransitionEmissions.AddTransitionEmission ("PRP$", "My");
            secondTransitionEmissions.AddTransitionEmission ("NN", "dog");
            secondTransitionEmissions.AddTransitionEmission ("VBZ", "likes");
            secondTransitionEmissions.AddTransitionEmission ("VBG", "eating");
            secondTransitionEmissions.AddTransitionEmission ("NN", "turkey");
            secondTransitionEmissions.AddTransitionEmission (".", ".");

            // My/PRP$ dog/NN likes/VBZ walking/VBG ./.
            var thirdTransitionEmissions = new TransitionEmissions ();
            thirdTransitionEmissions.AddTransitionEmission ("PRP$", "My");
            thirdTransitionEmissions.AddTransitionEmission ("NN", "dog");
            thirdTransitionEmissions.AddTransitionEmission ("VBZ", "likes");
            thirdTransitionEmissions.AddTransitionEmission ("VBG", "walking");
            thirdTransitionEmissions.AddTransitionEmission (".", ".");

            return new List<TransitionEmissions> { firstTransitionEmissions, secondTransitionEmissions, thirdTransitionEmissions };
        }