Exemple #1
0
        static int CheckGroups(Dictionary <int, string> strings, Dictionary <List <int>, string> groups, int searchIndex)
        {
            var copyGroups   = Extensions.DeepClone <List <KeyValuePair <List <int>, string> > >(groups.ToList());
            var primaryWords = Extensions.GetSplittedWords(copyGroups[0].Value);
            int inSearchItem = 0;

            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);
                    inSearchItem += copyGroups[index].Value.Count();
                    copyGroups.RemoveAt(index);
                    break;
                }

                case 1:
                {
                    copyGroups[0].Key.AddRange(copyGroups[index].Key);
                    inSearchItem += copyGroups[index].Value.Count();
                    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
                                });

                            inSearchItem += uniqueInCurrentGroup.Values.ToList()[0].Count();

                            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(inSearchItem);
        }