Esempio n. 1
0
        private void PutData()
        {
            ClearData();
            ChangeVisibility(true);

            Dictionary <int, string> strings = IO.ParseStrings(filePath);
            var list = new List <List <string> >();

            foreach (var item in strings)
            {
                list.Add(item.Value.Split(new char[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).ToList());
            }
            AddListOfListsToDataGrid(InitialDataGrid, list);

            var comparationMatrix = Operands.CompareLines(strings.Values.ToList());

            AddListOfListsToDataGrid(ComparationDataGrid, comparationMatrix);

            var groupped = Groupping.Group(comparationMatrix);
            var unique   = Operands.GetUniqueInGroups(strings, groupped);

            AddDictionaryToTextBlock(GroupsUTextBlock, unique);


            var sorted = Groupping.SortGroups(strings, unique);

            AddDictionaryToTextBlock(GroupsTextBlock, sorted);
        }
Esempio n. 2
0
        static Dictionary <List <int>, string> CollapseGroups(Dictionary <int, string> strings, Dictionary <List <int>, string> groups)
        {
            var copyGroups   = Extensions.DeepClone <List <KeyValuePair <List <int>, string> > >(groups.ToList());
            var primaryWords = Extensions.GetSplittedWords(copyGroups[0].Value);

            for (int index = 1; index < copyGroups.Count; index++)
            {
                var secondaryWords = Extensions.GetSplittedWords(copyGroups[index].Value);

                switch (primaryWords.ContainsAllItems(secondaryWords))
                {
                case 0:
                {
                    copyGroups[0].Key.AddRange(copyGroups[index].Key);
                    copyGroups.RemoveAt(index);
                    break;
                }

                case 1:
                {
                    copyGroups[0].Key.AddRange(copyGroups[index].Key);
                    copyGroups.RemoveAt(index);
                    break;
                }

                case 2:
                {
                    break;
                }

                default:
                {
                    var keys = new List <int>(copyGroups.ToDictionary(x => x.Key, x => x.Value).Keys.ToList()[index]);

                    foreach (var item in keys)
                    {
                        var itemWords = Extensions.GetSplittedWords(strings.Values.ToArray()[item]);

                        if (primaryWords.ContainsAllItems(itemWords) == 0 || primaryWords.ContainsAllItems(itemWords) == 1)
                        {
                            copyGroups[0].Key.Add(item);
                            copyGroups[index].Key.Remove(item);

                            var uniqueInCurrentGroup = Operands.GetUniqueInGroups(strings, new List <List <int> >()
                                {
                                    copyGroups[index].Key
                                });

                            KeyValuePair <List <int>, string> updatedItem = new KeyValuePair <List <int>, string>(copyGroups[index].Key, copyGroups[index].Value.Replace(copyGroups[index].Value, uniqueInCurrentGroup.Values.ToList()[0]));
                            copyGroups[index] = updatedItem;
                        }
                    }
                    break;
                }
                }
            }

            return(copyGroups.ToDictionary(x => x.Key, x => x.Value));
        }