Esempio n. 1
0
    private static Tuple <List <Sequence>, int> getPrefixSpanResults(string filepath, double minSupport, bool print)
    {
        // current batch to process
        List <Sequence> sequenceList = new List <Sequence>();

        // open the CSV file
        var reader = new StreamReader(File.OpenRead(filepath));

        while (!reader.EndOfStream)
        {
            // read the current line
            string line = reader.ReadLine();

            // split the line by comma (assuming CSV file)
            string []          transactions = line.Split(new string[] { " -1 " }, StringSplitOptions.None);
            List <Transaction> tr           = new List <Transaction>(transactions.Length);

            for (int i = 0; i < transactions.Length - 1; i++)
            {
                string []   items = transactions[i].Split(' ');
                Transaction trans = new Transaction(items);
                tr.Add(trans);
            }

            Sequence sequence = new Sequence(tr);
            sequenceList.Add(sequence);
        }

        PrefixSpan algorithm = new PrefixSpan(sequenceList);

        // extract the frequent patterns
        List <Sequence> frequentSequences = algorithm.MinSupportFrequentSequences(minSupport);

        return(new Tuple <List <Sequence>, int>(frequentSequences, sequenceList.Count));
    }
Esempio n. 2
0
        private static long processFile(string filepath, double minSupport, int maxLength)
        {
            // measure the time it takes for the algorithm to complete
            Stopwatch stopwatch = Stopwatch.StartNew();

            // current batch to process
            List <Sequence> sequences = new List <Sequence>(5000000);

            // read the csv file
            var reader = new StreamReader(File.OpenRead(filepath));

            while (!reader.EndOfStream)
            {
                // read the current line
                string line = reader.ReadLine();

                // split the line by comma (assuming CSV file)
                string [] transactions = line.Split(new string[] { " -1 " }, StringSplitOptions.None);

                List <Transaction> tr = new List <Transaction>(transactions.Length);
                for (int i = 0; i < transactions.Length - 1; i++)
                {
                    string []   items = transactions[i].Split(' ');
                    Transaction trans = new Transaction(items);
                    tr.Add(trans);
                }

                Sequence sequence = new Sequence(tr);
                sequences.Add(sequence);
            }

            long csvReadingTime = stopwatch.ElapsedMilliseconds;

            PrefixSpan algo = new PrefixSpan(sequences);

            var frequentSequences = algo.MinSupportFrequentSequences(minSupport);

            frequentSequences.Sort(Sequence.SequenceSorter);
            frequentSequences.ForEach(Console.WriteLine);

            Console.WriteLine("*****************************************************************************");
            Console.WriteLine("Done with PrefixSpan results.");
            Console.WriteLine("Number of frequent sequences:        " + frequentSequences.Count + " sequences.");
            Console.WriteLine("Minimum support:                     " + minSupport);
            Console.WriteLine("CSV reading time:                    " + csvReadingTime + "ms.");
            Console.WriteLine("Total run time:                      " + stopwatch.ElapsedMilliseconds + "ms.");
            Console.WriteLine("*****************************************************************************");

            return(stopwatch.ElapsedMilliseconds);
        }
Esempio n. 3
0
    private static long processCSVFile(string filepath, double minSupport)
    {
        Stopwatch stopwatch = Stopwatch.StartNew(); //creates and start the instance of Stopwatch

        // current batch to process
        List <Sequence> sequenceList = new List <Sequence>();

        // open the CSV file
        var reader = new StreamReader(File.OpenRead(filepath));

        while (!reader.EndOfStream)
        {
            // read the current line
            string line = reader.ReadLine();

            // split the line by comma (assuming CSV file)
            string [] transactions = line.Split(new string[] { " -1 " }, StringSplitOptions.None);

            List <Transaction> tr = new List <Transaction>(transactions.Length);
            for (int i = 0; i < transactions.Length - 1; i++)
            {
                string []   items = transactions[i].Split(' ');
                Transaction trans = new Transaction(items);
                tr.Add(trans);
            }

            Sequence sequence = new Sequence(tr);
            sequenceList.Add(sequence);
        }

        PrefixSpan algorithm = new PrefixSpan(sequenceList);

        List <Sequence> frequentSequences = algorithm.MinSupportFrequentSequences(minSupport);

        // stop the stopwatch after frequent patterns are
        // returned
        stopwatch.Stop();

        return(stopwatch.ElapsedMilliseconds);
    }
Esempio n. 4
0
        private async Task runPrefixSpan(BenchmarkRequest request, IServerStreamWriter <BenchmarkReply> responseStream, ServerCallContext context)
        {
            Console.WriteLine("run prefix span");

            await Task.Run(async() => {
                Stopwatch stopwatch = Stopwatch.StartNew(); //creates and start the instance of Stopwatch

                List <Sequence> sequenceList = new List <Sequence>();

                // open the CSV file
                using (var reader = new StreamReader(File.OpenRead(request.File)))
                {
                    while (!reader.EndOfStream)
                    {
                        // read the current line
                        string line = reader.ReadLine();

                        // split the line by comma (assuming CSV file)
                        string [] transactions = line.Split(new string[] { " -1 " }, StringSplitOptions.None);

                        List <Transaction> tr = new List <Transaction>(transactions.Length);
                        for (int i = 0; i < transactions.Length - 1; i++)
                        {
                            string [] items   = transactions[i].Split(' ');
                            Transaction trans = new Transaction(items);
                            tr.Add(trans);
                        }

                        Sequence sequence = new Sequence(tr);
                        sequenceList.Add(sequence);
                    }
                }

                PrefixSpan algorithm = new PrefixSpan(sequenceList);

                List <Sequence> frequentSequences = algorithm.MinSupportFrequentSequences(request.Support);

                // stop the stopwatch after frequent patterns are
                // returned
                stopwatch.Stop();

                var reply = new BenchmarkReply
                {
                    NrProcessedRecords = request.DBSize,
                    ReplyType          = ReplyType.Batch,
                    Iteration          = 0,
                    Error = 0,
                    BatchRuntimeInMillis = stopwatch.ElapsedMilliseconds,
                    TotalRuntimeInMillis = stopwatch.ElapsedMilliseconds
                };
                var ser = JsonConvert.SerializeObject(frequentSequences, _jsonSettings);
                reply.SequencesInJson = ser;
                await responseStream.WriteAsync(reply);

                reply = new BenchmarkReply
                {
                    ReplyType            = ReplyType.Complete,
                    TotalRuntimeInMillis = stopwatch.ElapsedMilliseconds
                };

                await responseStream.WriteAsync(reply);
            });
        }