Пример #1
0
        public static NGram Create(IEnumerable <Entity> dataItems)
        {
            NGram ngram = new NGram();

            ngram.CreateNGrams(dataItems);
            return(ngram);
        }
Пример #2
0
        public static Database Create()
        {
            Database database = new Database();

            database.Load();
            database.ngram = NGram.Create(database.entities);
            return(database);
        }
Пример #3
0
        public static Candidate Create(List <string> list, string input)
        {
            Candidate candidate = new Candidate();

            candidate.items = (from s in list
                               let ld = LevenshteinDistance.Compute(input, s)
                                        let unigram = NGram.CompareUnigram(input, s)
                                                      let bigram = NGram.CompareBigram(input, s)
                                                                   let ngram = NGram.Compare(input.Length, input, s)
                                                                               orderby bigram descending
                                                                               orderby ld ascending
                                                                               select new DataItem(ld, unigram, bigram, ngram, s)).Take(100);
            return(candidate);
        }
Пример #4
0
        /// <summary>
        /// もしかして…
        /// </summary>
        /// <param name="s"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string GetPossibility(string s, IEnumerable <string> source)
        {
            if (s == null)
            {
                throw new ArgumentNullException("s");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            List <string> possibilityList = new List <string>();
            int           mincost         = int.MaxValue;
            string        moshikashite    = null;

            foreach (string t in source)
            {
                int cost = LevenshteinDistance.Compute(s, t);
                if (cost == 0)
                {
                    return(t);
                }
                if (cost <= mincost)
                {
                    mincost = cost;
                    possibilityList.Add(t);
                }
            }

            decimal k = -1m;

            foreach (string t in possibilityList)
            {
                decimal result = NGram.CompareBigram(s, t);
                if (k == -1m || result > k)
                {
                    k            = result;
                    moshikashite = t;
                }
            }
            return(moshikashite);
        }