Esempio n. 1
0
        private Dictionary<string, HashSet<int>> GetDefaultTrigramIndex(QuestionList questionList)
        {
            var getDataFunction = new Func<Tuple<string, HashSet<int>>[]>(
                () => CalculateTrigramIndex().Select(pair => Tuple.Create(pair.Key, pair.Value)).ToArray());

            return DataActualityChecker.Check
                (
                    new Lazy<Tuple<string, HashSet<int>>[]>(getDataFunction),
                    t => t.Item1 + "\x2" + String.Join("\x2", t.Item2),
                    s =>
                        {
                            var q = s.Split('\x2');
                            return Tuple.Create(q[0], new HashSet<int>(q.Skip(1).Select(int.Parse)));
                        },
                    new FileDependencies(
                        String.Format("TrigramIndex_{0}.txt", questionList.GetHashCode()),
                        Program.QuestionsFileName,
                        Program.AnswersFileName)
                )
                .ToDictionary(item => item.Item1, item => item.Item2);
        }
Esempio n. 2
0
        public static string[] GetFrequentWords(QuestionList questionList)
        {
            var getDataFunction = new Func<string[]>(
                () =>
                    {
                        var statistics = new Statistics.Statistics(questionList);
                        return statistics.WordFrequencyDistribution(new EmptyStemmer())
                            .Where(item => item.Value > 10)
                            .Select(item => item.Key)
                            .ToArray();
                    });

            return DataActualityChecker.Check
                (
                    new Lazy<string[]>(getDataFunction),
                    t => t,
                    s => s,
                    new FileDependencies(String.Format("FrequentWords_{0}.txt", questionList.GetHashCode()),
                                         Program.QuestionsFileName,
                                         Program.AnswersFileName)
                ).ToArray();
        }