コード例 #1
0
        /// <summary>
        /// calculates the priority of the result
        /// </summary>
        /// <param name="result"></param>
        /// <param name="bestLine"></param>
        /// <param name="sep"></param>
        /// <returns></returns>
        public static int GetPriorityOf(System.Collections.ArrayList result, AsciiLineAnalyzer.Separation sep, ref AsciiLineStructure bestLine)
        {
            System.Collections.Hashtable sl = new System.Collections.Hashtable();
            bestLine = null;
            for (int i = 0; i < result.Count; i++)
            {
                AsciiLineAnalyzer ala = (AsciiLineAnalyzer)result[i];
                int p = ((AsciiLineAnalyzer)result[i]).structure[(int)sep].GetHashCode(); // and hash code
                if (null == sl[p])
                {
                    sl.Add(p, 1);
                }
                else
                {
                    sl[p] = 1 + (int)sl[p];
                }
            }
            // get the count with the topmost frequency
            int nNumberOfMaxSame = 0;
            int nHashOfMaxSame   = 0;

            foreach (System.Collections.DictionaryEntry ohash in sl)
            {
                int hash = (int)ohash.Key;
                int cnt  = (int)ohash.Value;
                if (nNumberOfMaxSame < cnt)
                {
                    nNumberOfMaxSame = cnt;
                    nHashOfMaxSame   = hash;
                }
            } // for each
            // search for the max priority of the hash
            int nMaxPriorityOfMaxSame = 0;

            for (int i = 0; i < result.Count; i++)
            {
                AsciiLineAnalyzer ala = (AsciiLineAnalyzer)result[i];
                if (nHashOfMaxSame == ((AsciiLineAnalyzer)result[i]).structure[(int)sep].GetHashCode())
                {
                    int prty = ((AsciiLineAnalyzer)result[i]).structure[(int)sep].Priority;
                    if (prty > nMaxPriorityOfMaxSame)
                    {
                        nMaxPriorityOfMaxSame = prty;
                        bestLine = ((AsciiLineAnalyzer)result[i]).structure[(int)sep];
                    }
                } // if
            }     // for
            return(nNumberOfMaxSame);
        }
コード例 #2
0
 /// <summary>
 /// calculates the priority of the result
 /// </summary>
 /// <param name="result"></param>
 /// <param name="bestLine"></param>
 /// <param name="sep"></param>
 /// <returns></returns>
 public static int GetPriorityOf(System.Collections.ArrayList result, AsciiLineAnalyzer.Separation sep, ref AsciiLineStructure bestLine)
 {
   System.Collections.Hashtable sl = new System.Collections.Hashtable();
   bestLine=null;
   for(int i=0;i<result.Count;i++)
   {
     AsciiLineAnalyzer ala = (AsciiLineAnalyzer)result[i];
     int p  = ((AsciiLineAnalyzer)result[i]).structure[(int)sep].GetHashCode(); // and hash code
     if(null==sl[p])
       sl.Add(p,1);
     else 
       sl[p] = 1+(int)sl[p];
   }
   // get the count with the topmost frequency
   int nNumberOfMaxSame = 0;
   int nHashOfMaxSame = 0;
   foreach(System.Collections.DictionaryEntry ohash in sl)
   {
     int hash = (int)ohash.Key;
     int cnt = (int)ohash.Value;
     if(nNumberOfMaxSame<cnt)
     {
       nNumberOfMaxSame  = cnt;
       nHashOfMaxSame = hash;
     }
   } // for each
   // search for the max priority of the hash
   int nMaxPriorityOfMaxSame=0;
   for(int i=0;i<result.Count;i++)
   {
     AsciiLineAnalyzer ala = (AsciiLineAnalyzer)result[i];
     if(nHashOfMaxSame == ((AsciiLineAnalyzer)result[i]).structure[(int)sep].GetHashCode())
     {
       int prty = ((AsciiLineAnalyzer)result[i]).structure[(int)sep].Priority;
       if(prty>nMaxPriorityOfMaxSame)
       {
         nMaxPriorityOfMaxSame = prty;
         bestLine = ((AsciiLineAnalyzer)result[i]).structure[(int)sep];
       }
     }// if
   } // for
   return nNumberOfMaxSame;
 }