public static LogDebuggerControl getInstance()
        {
            if (_logDebugger == null)
                _logDebugger = new LogDebuggerControl();

            return _logDebugger;
        }
Esempio n. 2
0
        public static LogDebuggerControl getInstance()
        {
            if (_logDebugger == null)
            {
                _logDebugger = new LogDebuggerControl();
            }

            return(_logDebugger);
        }
Esempio n. 3
0
        /**
         * This method returns the match level of the given wordlist according to a
         * certain formula.
         */
        public int getMatchLevel(String wordList, CategorizerOptions parameters)
        {
            char[] separators     = { ' ', '\t', '\n' };
            int    numOfWords     = Math.Max(1, wordList.Split(separators).Length);
            int    numOfKeywords  = Math.Max(1, keywordList.Count);
            int    nonZero        = 0;
            double sumOfhistogram = 0;
            double threshold      = Math.Max(2.0, ((numOfWords * parameters.BETA) / numOfKeywords));

            // keywordList and wordList are copied to a new arrays so that we won't change them(the originals)
            List <String> keywordListCopied = new List <string>(keywordList);
            String        wordListCopied    = (String)wordList.Clone();

            // Transforming the keywordListCopied and wordListCopied to canonical form
            //keywordListCopied.ForEach(canonicForm);
            canonicForm(ref wordListCopied);
            //wordListCopied = wordListCopied.ToLower();
            int[] histogram = new int[numOfKeywords];
            //Initialising the histogram array to zeros
            for (int i = 0; i < numOfKeywords; i++)
            {
                histogram[i] = 0;
            }

            foreach (String keyword in keywordListCopied)
            {
                Regex objPattern = new Regex(keyword.ToLower());
                int   count      = objPattern.Matches(wordListCopied, 0).Count;

                int index = keywordListCopied.IndexOf(keyword);
                if (count != 0 && histogram[index] == 0)
                {
                    nonZero++;
                }

                if (histogram[index] < threshold)
                {
                    int add = Math.Min(histogram[index] + count, (int)threshold) - histogram[index];
                    histogram[index] = histogram[index] + add;
                    sumOfhistogram   = sumOfhistogram + add;
                }
            }

            double nonZeroBonus = (nonZero * parameters.GAMMA) / numOfKeywords;

            nonZeroBonus = Math.Min(parameters.NONZERO_MAX_EFFECT, nonZeroBonus);
            double matchPercent = (sumOfhistogram * parameters.ALPHA) / numOfWords;

            matchPercent = Math.Min(parameters.MATCH_MAX_EFFECT, matchPercent);
            double total = parameters.MAX_MATCH_LEVEL * (nonZeroBonus + matchPercent) / (parameters.MATCH_MAX_EFFECT + parameters.NONZERO_MAX_EFFECT);

            if (numOfWords < parameters.MIN_WORDS_LIMIT)
            {
                total = parameters.MIN_WORDS_PENLTY * total;
            }

            StreamWriter sw = null;

            if (LogDebuggerControl.getInstance().debugCategorization)
            {
                if (!parameters.isRank)
                {
                    sw = new
                         StreamWriter("_DEBUG_INFO_CATEGORIZER@" + System.Threading.Thread.CurrentThread.ManagedThreadId + ".txt", true);
                    sw.WriteLine(" ***** DATA FOR REQUEST ************************************************* ");
                    //sw.WriteLine(" .CONTENT WORDS: ");
                    //sw.WriteLine(wordListCopied.ToString());
                    sw.WriteLine(" .NUM OF WORDS: ");
                    sw.WriteLine(numOfWords.ToString());
                    sw.WriteLine(" .KEY WORDS: ");
                    sw.WriteLine(keywordListCopied.ToString());
                    sw.WriteLine(" .NUM OF KEY WORDS: ");
                    sw.WriteLine(numOfKeywords.ToString());
                    sw.WriteLine(" .THRESOLD PARAM: ");
                    sw.WriteLine(threshold.ToString());
                    sw.WriteLine(" .SUM OF HISTOGRAM: ");
                    sw.WriteLine(sumOfhistogram.ToString());
                    sw.WriteLine(" .NONZERO PARAM: ");
                    sw.WriteLine(nonZero.ToString());
                    sw.WriteLine(" .HISTOGRAM DATA:");
                    for (int j = 0; j < numOfKeywords; j++)
                    {
                        sw.WriteLine(" .[" + keywordList[j] + "] -> " + histogram[j].ToString());
                    }
                    sw.WriteLine(" .NON-ZERO BONUS: ");
                    sw.WriteLine(nonZeroBonus.ToString());
                    sw.WriteLine(" .MATCH PERCENT: ");
                    sw.WriteLine(matchPercent.ToString());
                    sw.WriteLine(" .TOTAL TRUST: ");
                    sw.WriteLine(total.ToString());
                    sw.WriteLine(" * END ****************************************************************** ");
                    sw.Close();
                }
            }

            if (LogDebuggerControl.getInstance().debugCategorizationInRanker&& LogDebuggerControl.getInstance().debugRanker)
            {
                if (parameters.isRank)
                {
                    sw = new StreamWriter("DataForRank" + System.Threading.Thread.CurrentThread.ManagedThreadId + ".txt", true);
                    sw.WriteLine(" ***** DATA FOR Categorizer ************************************************* ");
                    //sw.WriteLine(" .CONTENT WORDS: ");
                    //sw.WriteLine(wordListCopied.ToString());
                    sw.WriteLine(" .NUM OF WORDS: ");
                    sw.WriteLine(numOfWords.ToString());
                    //String[] wordListSplited = wordListCopied.Split(separators);
                    //for (int k = 0; k < numOfWords;k++ )
                    //{
                    //    sw.WriteLine(" .[" + k + "] -> " + wordListSplited[k]);
                    //}
                    sw.WriteLine(" .KEY WORDS: ");
                    sw.WriteLine(keywordListCopied.ToString());
                    sw.WriteLine(" .NUM OF KEY WORDS: ");
                    sw.WriteLine(numOfKeywords.ToString());
                    sw.WriteLine(" .THRESOLD PARAM: ");
                    sw.WriteLine(threshold.ToString());
                    sw.WriteLine(" .SUM OF HISTOGRAM: ");
                    sw.WriteLine(sumOfhistogram.ToString());
                    sw.WriteLine(" .NONZERO PARAM: ");
                    sw.WriteLine(nonZero.ToString());
                    sw.WriteLine(" .HISTOGRAM DATA:");
                    for (int j = 0; j < numOfKeywords; j++)
                    {
                        sw.WriteLine(" .[" + keywordList[j] + "] -> " + histogram[j].ToString());
                    }
                    sw.WriteLine(" .NON-ZERO BONUS: ");
                    sw.WriteLine(nonZeroBonus.ToString());
                    sw.WriteLine(" .MATCH PERCENT: ");
                    sw.WriteLine(matchPercent.ToString());
                    sw.WriteLine(" .TOTAL TRUST: ");
                    sw.WriteLine(total.ToString());
                    sw.WriteLine(" * END ****************************************************************** ");
                    sw.Close();
                }
            }
            return(Convert.ToInt32(total));
        }