示例#1
0
        private static Sequences GetSequences(List <string> list)
        {
            Sequences sequences = new Sequences();

            while (list.Count() > 0)
            {
                var take     = list.TakeWhile(x => x == list.FirstOrDefault());
                var sequence = new Sequence {
                    Text = take.FirstOrDefault(), OccuranceCount = take.Count()
                };
                sequences.Groups.Add(sequence);
                list.RemoveRange(0, take.Count());
            }
            return(sequences);
        }
示例#2
0
        public static string FindSequences(this string data, int floor, int ceiling, int limit = 100)
        {
            var list = GetNGram(data, floor, ceiling);

            list.Sort();

            Sequences seq = GetSequences(list);

            seq.Groups.Sort((s, y) => y.OccuranceCount.CompareTo(s.OccuranceCount));


            seq.Groups = seq.Groups.Take(limit).ToList();


            var json = JsonConvert.SerializeObject(seq, Formatting.Indented);

            return(json);
        }