private MyWordInfo[] LookupCandidates(Wnlib.Index index, MyWordInfo pos )
		{						
			if (pos.Sense < 0) pos.Sense=1;						
			SynSet synset=new Wnlib.SynSet( index.offs[pos.Sense - 1 ], index.pos , index.wd, null , pos.Sense - 1);					
						
			ArrayList lexemes=new ArrayList() ;
			ArrayList synIndex=new ArrayList() ;

			foreach (Lexeme obj in synset.words)
			{
				lexemes.Add(obj) ;
				synIndex.Add(index.offs[pos.Sense - 1 ]);
			}
			
			if (index.offs.Length > 1)
			{
				if (lexemes.Count <= 1)
				{
					for(int i=0; i < index.offs.Length; i++ )
					{				
						synset=new Wnlib.SynSet( index.offs[i], index.pos, index.wd, null, i );

						foreach (Lexeme obj in synset.words)
						{
							synIndex.Add(index.offs[i]);
							lexemes.Add(obj) ;
						}
					}
				}
				else
				{
					synset=new Wnlib.SynSet( index.offs[0], index.pos, index.wd, null, 0 );
					int count=0; //get top most frequency word senses
					foreach (Lexeme obj in synset.words)
					{
						lexemes.Add(obj) ;
						synIndex.Add(index.offs[0]);
						++count;
						if (count > 4) break;
					}

				}
			}
			
			ArrayList sortedSet=new ArrayList() ;
			Hashtable trace=new Hashtable() ;
			int hasSem=0;
			for (int i = 0; i < lexemes.Count; i++)
			{				
				Lexeme word=(Lexeme)lexemes[i];				
				word.word=word.word.ToLower() ;

				int senIndex=(int)synIndex[i];
				if (senIndex != -1  && word.wnsns > 0)
				{
					word.semcor=new Wnlib.SemCor(word, senIndex);
					lexemes[i]=word;					
					++hasSem;
				}

				if (!trace.ContainsKey(word.word) )					
				{					
					if ((word.semcor != null &&  word.semcor.semcor  > 0 ) || (hasSem < 4))
					{
						trace[word.word]=1;
						sortedSet.Add(word) ;
					}
				}
				//catch
				{}
			}
			
			Lexeme[] words=(Lexeme[])sortedSet.ToArray( typeof(Lexeme) );						

			ArrayList candidates=new ArrayList();

			for( int i=0; i < words.Length; i++ )
			{
				string word=words[i].word.Replace("_", " " );				
				if( word[0] <= 'Z' ) continue;

				MyWordInfo newpos=new MyWordInfo(word, pos.Pos) ;
				newpos.Sense=words[i].wnsns;
				if (words[i].semcor != null)
					newpos.Frequency=words[i].semcor.semcor;
				else
					newpos.Frequency=0;

				candidates.Add( newpos);								
			}

			if (!trace.ContainsKey (index.wd))
				candidates.Add(pos) ;

			if (candidates.Count > 1)
			{
				CompareLexeme comparer=new CompareLexeme();
				candidates.Sort(comparer);
			}
			

			return (MyWordInfo[])candidates.ToArray( typeof(MyWordInfo) );
		}
        private static MyWordInfo[] LookupCandidates(Index index, MyWordInfo pos)
        {
            if (pos.Sense < 0)
            {
                pos.Sense = 1;
            }
            SynSet synset = new Wnlib.SynSet(index.SynsetOffsets[pos.Sense - 1], index.PartOfSpeech, index.Wd, null, pos.Sense - 1);

            ArrayList lexemes  = new ArrayList();
            ArrayList synIndex = new ArrayList();

            foreach (Lexeme obj in synset.words)
            {
                lexemes.Add(obj);
                synIndex.Add(index.SynsetOffsets[pos.Sense - 1]);
            }

            if (index.SynsetOffsets.Length > 1)
            {
                if (lexemes.Count <= 1)
                {
                    for (int i = 0; i < index.SynsetOffsets.Length; i++)
                    {
                        synset = new SynSet(index.SynsetOffsets[i], index.PartOfSpeech, index.Wd, null, i);

                        foreach (Lexeme obj in synset.words)
                        {
                            synIndex.Add(index.SynsetOffsets[i]);
                            lexemes.Add(obj);
                        }
                    }
                }
                else
                {
                    synset = new SynSet(index.SynsetOffsets[0], index.PartOfSpeech, index.Wd, null, 0);
                    int count = 0;                   //get top most frequency word senses
                    foreach (Lexeme obj in synset.words)
                    {
                        lexemes.Add(obj);
                        synIndex.Add(index.SynsetOffsets[0]);
                        ++count;
                        if (count > 4)
                        {
                            break;
                        }
                    }
                }
            }

            ArrayList sortedSet = new ArrayList();
            Hashtable trace     = new Hashtable();
            int       hasSem    = 0;

            for (int i = 0; i < lexemes.Count; i++)
            {
                Lexeme word = (Lexeme)lexemes[i];
                word.word = word.word.ToLower();

                int senIndex = (int)synIndex[i];
                if (senIndex != -1 && word.wnsns > 0)
                {
                    word.semcor = new Wnlib.SemCor(word, senIndex);
                    lexemes[i]  = word;
                    ++hasSem;
                }

                if (!trace.ContainsKey(word.word))
                {
                    if ((word.semcor != null && word.semcor.semcor > 0) || (hasSem < 4))
                    {
                        trace[word.word] = 1;
                        sortedSet.Add(word);
                    }
                }
                //catch
                {}
            }

            var words = (Lexeme[])sortedSet.ToArray(typeof(Lexeme));

            ArrayList candidates = new ArrayList();

            for (int i = 0; i < words.Length; i++)
            {
                string word = words[i].word.Replace("_", " ");
                if (word[0] <= 'Z')
                {
                    continue;
                }

                MyWordInfo newpos = new MyWordInfo(word, pos.Pos);
                newpos.Sense = words[i].wnsns;
                if (words[i].semcor != null)
                {
                    newpos.Frequency = words[i].semcor.semcor;
                }
                else
                {
                    newpos.Frequency = 0;
                }

                candidates.Add(newpos);
            }

            if (!trace.ContainsKey(index.Wd))
            {
                candidates.Add(pos);
            }

            if (candidates.Count > 1)
            {
                CompareLexeme comparer = new CompareLexeme();
                candidates.Sort(comparer);
            }


            return((MyWordInfo[])candidates.ToArray(typeof(MyWordInfo)));
        }