Exemple #1
0
        static void addTransactions()
        {
            //   int lineNum = 0;
            string line;
            using (StreamReader sr = new StreamReader("data/topic-1.txt"))
            {

                while ((line = sr.ReadLine()) != null)
                {
                    List<string> data = line.Split(' ').ToList();
                    ItemSet set = new ItemSet();
                    foreach (string d in data)
                    {
                        if (!d.Equals(""))
                        {
                            Item it = new Item(d);
                            set.add(it);
                        }

                    }
                    set.sort();
                    transactions.Add(set);

                    //  lineNum++;
                }
            }
        }
Exemple #2
0
        static List <ItemSet> join(List <ItemSet> itemsets)
        {
            List <ItemSet> newcandidateItemsets = new List <ItemSet>();

            for (int i = 0; i < itemsets.Count() - 1; i++)
            {
                ItemSet itemset1 = itemsets[i];
                for (int j = i + 1; j < itemsets.Count(); j++)
                {
                    ItemSet itemset2 = itemsets[j];
                    itemset2.sort();
                    ItemSet newcandidate = NewCandidateItemSet(itemset1, itemset2);
                    newcandidate.sort();
                    if (newcandidate.Count() != 0)
                    {
                        newcandidate.support = GetSupport(newcandidate);
                        newcandidateItemsets.Add(newcandidate);
                    }
                }
            }
            return(newcandidateItemsets);
            //foreach item[i] in itemsets  to itemsets.length-1
            //get item[i]
            //sort item[i].key
            //foreach item[j=1+1] in itemsets  to itemsets
            //get item[j]
            //generate new candidate/itemset with item[i] and item[j]
            //if the candidate is not empty
            //get and add min support
            //add to candidates itemsets
            //setmy itemsets to candidates itemset
            //clear candidates itemsets
        }
Exemple #3
0
        static ItemSet NewCandidateItemSet(ItemSet i1, ItemSet i2)
        {
            ItemSet newItemSet = new ItemSet();

            i1.clone(newItemSet);
            int length = i1.items.Count();

            if (length == 1)
            {
                newItemSet.items.AddRange(i2.items);
                return(newItemSet);
            }
            else
            {
                ItemSet firstSubString  = new ItemSet();
                ItemSet secondSubString = new ItemSet();

                firstSubString.items  = i1.items.GetRange(0, length - 1);
                secondSubString.items = i2.items.GetRange(0, length - 1);
                firstSubString.sort();
                secondSubString.sort();
                if (firstSubString.stringRepresentation().Equals(secondSubString.stringRepresentation()))
                {
                    newItemSet.items.Add(i2.items[length - 1]);
                    return(newItemSet);
                }

                ItemSet empt = new ItemSet();
                return(empt);
            }
        }
Exemple #4
0
        static void addTransactions()
        {
            //   int lineNum = 0;
            string line;

            using (StreamReader sr = new StreamReader("data/topic-1.txt"))
            {
                while ((line = sr.ReadLine()) != null)
                {
                    List <string> data = line.Split(' ').ToList();
                    ItemSet       set  = new ItemSet();
                    foreach (string d in data)
                    {
                        if (!d.Equals(""))
                        {
                            Item it = new Item(d);
                            set.add(it);
                        }
                    }
                    set.sort();
                    transactions.Add(set);

                    //  lineNum++;
                }
            }
        }
Exemple #5
0
        static ItemSet NewCandidateItemSet(ItemSet i1, ItemSet i2)
        {
            ItemSet newItemSet = new ItemSet();
            i1.clone(newItemSet);
            int length = i1.items.Count();

            if (length == 1)
            {
                newItemSet.items.AddRange(i2.items);
                return newItemSet;
            }
            else
            {

                ItemSet firstSubString = new ItemSet();
                ItemSet secondSubString = new ItemSet();

                firstSubString.items = i1.items.GetRange(0, length - 1);
                secondSubString.items = i2.items.GetRange(0, length - 1);
                firstSubString.sort();
                secondSubString.sort();
                if (firstSubString.stringRepresentation().Equals(secondSubString.stringRepresentation()))
                {
                    newItemSet.items.Add(i2.items[length - 1]);
                    return newItemSet;
                }

                ItemSet empt = new ItemSet();
                return empt;

            }
        }