Exemple #1
0
        public void ComputeProbability(List <string> tokens)
        {
            var mleDictionary = new Dictionary <string, double>();
            var lsDictionary  = new Dictionary <string, double>();
            var adDictionary  = new Dictionary <string, double>();

            for (var i = 0; i < tokens.Count; i++)
            {
                var mleProbability = EstimationMethods.MaximumLikelihoodEstimate(tokens[i], tokens[i + 1], tokens);
                mleDictionary.Add(tokens[i] + tokens[i + 1], mleProbability);
                var lsProbability = EstimationMethods.LaplaceSmoothing(tokens[i], tokens[i + 1], tokens);
                lsDictionary.Add(tokens[i] + tokens[i + 1], lsProbability);
                var adProbability = EstimationMethods.AbsoluteDiscounting(tokens[i], tokens[i + 1], tokens);
                adDictionary.Add(tokens[i] + tokens[i + 1], adProbability);
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Reading File...");
            //var text = Preprocessing.ReadFile(@"C:\src\nlp-language-models\Homework1\train.txt");
            //var corpus = Preprocessing.DumbSentenceSegmentor(text);
            //var tokenizedCorpus = Preprocessing.DumbTokenizer(corpus);
            //tokenizedCorpus = new List<string>(tokenizedCorpus.RemoveAll(string.IsNullOrEmpty));

            var test   = "A fat dog is a fat dog only when other fat dogs say he is a fat dog";
            var tokens = Preprocessing.DumbTokenizer(test);

            for (var i = 0; i < tokens.Count - 1; i++)
            {
                var mle = EstimationMethods.MaximumLikelihoodEstimate(tokens[i], tokens[i + 1], tokens);
                var ls  = EstimationMethods.LaplaceSmoothing(tokens[i], tokens[i + 1], tokens);
                var ads = EstimationMethods.AbsoluteDiscounting(tokens[i], tokens[i + 1], tokens);
                Console.WriteLine("P(" + tokens[i] + " | " + tokens[i + 1] + ")" + " = " + mle.ToString());
            }
            Console.ReadKey();
        }