Пример #1
0
        private static void MergeIndices(Dictionary <string, List <string> > dict)
        {
            foreach (var key in dict.Keys)
            {
                if (!Exercises.ContainsKey(key))
                {
                    Exercises.Add(key, dict[key]);
                    continue;
                }

                var existingList = Exercises[key];
                var newList      = dict[key];

                foreach (var newItem in newList)
                {
                    if (!existingList.Contains(newItem))
                    {
                        existingList.Add(newItem);

                        var keywords = new List <string>();
                        foreach (var k in dict.Keys)
                        {
                            if (dict[k].Contains(newItem))
                            {
                                keywords.Add(k);
                            }
                        }

                        Index.AddFile(newItem, keywords);
                    }
                }
            }
        }
Пример #2
0
        public static IEnumerable <string> Filter(List <string> keywords)
        {
            if (keywords == null)
            {
                return(new List <string>());
            }

            IEnumerable <string> list = Exercises[string.Empty];

            foreach (var keyword in keywords)
            {
                if (!Exercises.ContainsKey(keyword))
                {
                    return(new List <string>());
                }

                var annotatedList = Exercises[keyword];
                list = list.Where(l => annotatedList.Contains(l));
            }

            return(list);
        }
Пример #3
0
        public static void AddExercise(string path, List <string> keywords)
        {
            var alreayExisting = Exercises[string.Empty];

            if (path == null || !File.Exists(path) || alreayExisting.Contains(path))
            {
                return;
            }

            alreayExisting.Add(path);
            m_translator.Add(File.ReadAllText(path), path);

            foreach (var keyword in keywords)
            {
                if (!Exercises.ContainsKey(keyword))
                {
                    Exercises.Add(keyword, new List <string>());
                }

                var list = Exercises[keyword];
                list.Add(path);
            }
        }