예제 #1
0
        public int CompareTo(object obj)
        {
            SearchWordResult dest = (SearchWordResult)obj;

            if (this.SimilarRatio == dest.SimilarRatio)
            {
                return(0);
            }
            else if (this.SimilarRatio > dest.SimilarRatio)
            {
                return(-1);
            }
            else
            {
                return(1);
            }
        }
예제 #2
0
        public List <SearchWordResult> SearchByPos(POS Pos)
        {
            Debug.Assert(_WordDict != null);

            List <SearchWordResult> result = new List <SearchWordResult>();

            foreach (WordAttribute wa in _WordDict.Values)
            {
                if ((wa.Pos & Pos) != 0)
                {
                    SearchWordResult wordResult = new SearchWordResult();
                    wordResult.Word         = wa;
                    wordResult.SimilarRatio = 0;
                    result.Add(wordResult);
                }
            }

            return(result);
        }
예제 #3
0
        public List <SearchWordResult> SearchByLength(int len)
        {
            Debug.Assert(_WordDict != null);

            List <SearchWordResult> result = new List <SearchWordResult>();

            foreach (WordAttribute wa in _WordDict.Values)
            {
                if (wa.Word.Length == len)
                {
                    SearchWordResult wordResult = new SearchWordResult();
                    wordResult.Word         = wa;
                    wordResult.SimilarRatio = 0;
                    result.Add(wordResult);
                }
            }

            return(result);
        }
예제 #4
0
        /// <summary>
        /// 通过遍历方式搜索
        /// </summary>
        /// <returns></returns>
        public List <SearchWordResult> Search(String key)
        {
            Debug.Assert(_WordDict != null);

            List <SearchWordResult> result = new List <SearchWordResult>();

            foreach (WordAttribute wa in _FirstCharDict.Values)
            {
                if (wa.Word.Contains(key))
                {
                    SearchWordResult wordResult = new SearchWordResult();
                    wordResult.Word         = wa;
                    wordResult.SimilarRatio = (float)key.Length / (float)wa.Word.Length;
                    result.Add(wordResult);
                }
            }

            foreach (WordAttribute wa in _DoubleCharDict.Values)
            {
                if (wa.Word.Contains(key))
                {
                    SearchWordResult wordResult = new SearchWordResult();
                    wordResult.Word         = wa;
                    wordResult.SimilarRatio = (float)key.Length / (float)wa.Word.Length;
                    result.Add(wordResult);
                }
            }

            foreach (WordAttribute wa in _WordDict.Values)
            {
                if (wa.Word.Contains(key))
                {
                    SearchWordResult wordResult = new SearchWordResult();
                    wordResult.Word         = wa;
                    wordResult.SimilarRatio = (float)key.Length / (float)wa.Word.Length;
                    result.Add(wordResult);
                }
            }

            return(result);
        }