//Properties/Variables * **********************************************************
        //Constructors *******************************************************************
        //Methods ************************************************************************
        public static List<TransactionDto> Process(string FileType, string FileName)
        {
            List<TransactionDto> ret = new List<TransactionDto>();

            try
            {
                using (StreamReader sr = new StreamReader(FileName))
                {
                    string delimiter = "";
                    if (FileType.Equals("'|' Delimited File"))
                    {
                        delimiter = "|";
                    }
                    else if (FileType.Equals("Comma Delimited File"))
                    {
                        delimiter = ",";
                    }
                    else if (FileType.Equals("Tab Delimited File"))
                    {
                        delimiter = "\t";
                    }
                        //modified to accept new files
                    else if (FileType.Equals("| Delimited Points (x,y) File"))
                    {
                        delimiter = "|";
                    }
                    else return null;

                    string line;

                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] items = line.Split(delimiter.ToCharArray());

                        if (items.Length > 1)
                        {
                            TransactionDto temp = new TransactionDto();
                            temp.tid = items[0];

                            for (int i = 1; i < items.Length; i++)
                            {
                                temp.items.Add(items[i]);
                            }//for

                            ret.Add(temp);
                        }//if at least one product
                    }//while
                }//using
            }
            catch (Exception e)
            {
                MessageBox.Show("There was an issue with the file: " + FileName);
                return null;
            }//catch

            return ret;
        }
        public string decide(TransactionDto transaction, DecisionTreeNode node)
        {
            if (node.split_index == -1) return node.decision;

            foreach (DecisionTreeNode child in node.children)
            {
                if (transaction.items[node.split_index] == child.split_value) return decide(transaction, child);
            }

            return "NOT_FOUND";  //this case *SHOULD* never be reached
        }
        public TransactionDto Process(SalesItemsetsEntity Sale)
        {
            TransactionDto ret = new TransactionDto();

            ret.tid = Sale.salesorder;

            string[] productArray = Sale.Products.Split('|');

            ret.items = productArray.ToList();

            return ret;
        }
        public static List<TransactionDto> getAWSaleDto()
        {
            TransactionDto dto;
            List<TransactionDto> dtos = new List<TransactionDto>();

            using (AdventureWorksEntities awe = new AdventureWorksEntities())
            {
                IQueryable<BookExampleEntity> bee = awe.BookExampleEntities;

                foreach(BookExampleEntity be in bee)
                {
                    dto = new TransactionDto();
                    dto.tid = be.TID;
                    dto.items = be.items.Split('|').ToList();
                    dtos.Add(dto);
                }//foreach

            }//using

            return dtos;
        }
 public string decide(TransactionDto transaction)
 {
     return decide(transaction, _root);
 }
Пример #6
0
        private void createConditionalFPTree(List<FPPrefixPath> prefixPaths, ref List<ItemHeaderElement> itemHeaders)
        {
            foreach (FPPrefixPath p in prefixPaths)
            {
                for (int i = 0; i < p.support; i++)
                {
                    for (int j = 0; j < p.prefixpath.Count; j++)
                    {
                        Boolean found = false;
                        for (int k=0; k<itemHeaders.Count; k++){
                            if (itemHeaders[k].itemID == p.prefixpath[j].item) {
                                found = true;
                                itemHeaders[k].support = itemHeaders[k].support + 1;
                            }

                        }
                        if (!found) itemHeaders.Add(new ItemHeaderElement(p.prefixpath[j].item, 1));

                    }
                }
            }

            /* remove the itemHeaders that don't meet min_sup */
            for (int n = 0; n < itemHeaders.Count; n++)
            {
                if (itemHeaders[n].support < min_sup)
                {
                    itemHeaders.RemoveAt(n--);
                }
            }

            /*
            Console.WriteLine("ConditionalHeaderTable wo/node-links");
            foreach (ItemHeaderElement e in itemHeaders)
            {
                Console.WriteLine(e.ToString());
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
            */

            /* remove prefixpath nodes that don't meet min_sup */
            foreach (FPPrefixPath p in prefixPaths)
            {
                List<int> removeList = new List<int>();
                p.prefixpath.Reverse();
                for (int i = 0; i < p.prefixpath.Count; i++)
                {
                    bool found = false;
                    for (int j = 0; j < itemHeaders.Count; j++)
                    {
                        if (itemHeaders[j].itemID == p.prefixpath[i].item)
                        {
                            found = true;
                        }
                    }
                    if (!found) removeList.Add(i);
                }
                for (int i = 0; i < removeList.Count; i++)
                {
                    p.prefixpath.RemoveAt(removeList[i] - i); //CAN: Added because indexes change after the removing an element.  Did not encounter this issue in testing
                }
            }

            FPNode root = new FPNode(null, 0);
            foreach (FPPrefixPath p in prefixPaths)
            {
                TransactionDto dto = new TransactionDto();
                foreach (FPNode fpn in p.prefixpath)
                {
                    dto.items.Add(fpn.item);
                }
                /*
                Console.WriteLine("Adding to the tree " + p.support + " times: ");
                Console.WriteLine(dto);
                Console.ReadKey();
                */
                for (int i = 0; i < p.support; i++)
                {
                    TransactionDto tmpDto = new TransactionDto();
                    foreach (string item in dto.items)
                    {
                        tmpDto.items.Add(item);
                    }
                    addToTree(ref root, tmpDto, ref itemHeaders);
                }
            }

            /*
            Console.WriteLine("ConditionalHeaderTable w/node-links");
            foreach (ItemHeaderElement e in itemHeaders)
            {
                Console.WriteLine(e.ToString());
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();

            Console.WriteLine("Conditional FP-Tree children");
            foreach (FPNode aNode in root.children)
            {
                Console.WriteLine("----");
                FPNode myNode = aNode;
                while (myNode != null)
                {
                    Console.WriteLine(myNode.item + ":" + myNode.support + " --> ");
                    if (myNode.children.Count == 0) myNode = null;
                    else myNode = myNode.children[0];
                }
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
            */
        }
Пример #7
0
        /* add the items in dto to tree recursively && add node links to itemHeaderTable */
        private void addToTree(ref FPNode root, TransactionDto dto, ref List<ItemHeaderElement> itemHeaderTable)
        {
            if (dto.items.Count == 0) return;

            FPNode parent = root;
            foreach (FPNode node in root.children)
            {
                if (node.item == dto.items[0])
                {
                    parent = node;
                }
            }

            if (parent == root)
            {
                FPNode fpn = new FPNode(dto.items[0], 1, parent);
                parent.children.Add(fpn);
                parent = fpn;
                for (int i = 0; i < itemHeaderTable.Count; i++)
                {
                    if (itemHeaderTable[i].itemID == dto.items[0]) itemHeaderTable[i].addNodeLink(fpn);
                }
            }
            else
            {
                parent.support = parent.support + 1;
            }

            dto.items.RemoveAt(0);
            addToTree(ref parent, dto, ref itemHeaderTable);
        }