public WordProbability GetWordProbability(string category, string word, int? catId = null)
        {
            try
            {
                WordProbability wp = null;
                long matchingCount = 0;
                long nonMatchingCount = 0;

                WordSource source = null;
                if (catId != null)
                {
                    source = this.Data.WordSources.All(new string[] { "Category" }).FirstOrDefault(w => w.Word == word && w.CategoryId == catId.Value);
                }
                else
                {
                    source = this.Data.WordSources.All(new string[] { "Category" }).FirstOrDefault(w => w.Word == word && w.Category.Name == category);
                }

                if (source != null)
                {
                    matchingCount = source.Matches;
                    nonMatchingCount = source.NonMatches;
                }

                wp = new WordProbability(word, matchingCount, nonMatchingCount);

                return wp;
            }
            catch (Exception ex)
            {
                throw new WordsDataSourceException("Problem updating WordProbability.", ex);
            }
        }
        public double CalculateOverallProbability(WordProbability[] wps)
        {
            if (wps == null || wps.Length == 0)
                return IClassifierConstants.NEUTRAL_PROBABILITY;

            // we need to calculate xy/(xy + z) where z = (1 - x)(1 - y)

            // first calculate z and xy
            double z = 0d;
            double xy = 0d;
            for (int i = 0; i < wps.Length; i++)
            {
                if (z == 0)
                    z = (1 - wps[i].Probability);
                else
                    z = z * (1 - wps[i].Probability);

                if (xy == 0)
                    xy = wps[i].Probability;
                else
                    xy = xy * wps[i].Probability;
            }

            double numerator = xy;
            double denominator = xy + z;

            return numerator / denominator;
        }