Exemple #1
0
        private void TestClassifier(string[,] input, long[,] expected)
        {
            Classifier cs = new Classifier();

            for (int i = 0; i < input.GetLength(0); i++)
            {
                cs.Add(i, input[i, 0], Int32.Parse(input[i, 1]));
            }

            long[,] actual = cs.GetClassificationResult();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #2
0
        private static List <MainData> Classify(List <MainData> aggregatedDataList)
        {
            Classifier cs = new Classifier();

            for (int i = 0; i < aggregatedDataList.Count; i++)
            {
                cs.Add(i, aggregatedDataList[i].Process + aggregatedDataList[i].Title, aggregatedDataList[i].Frequency);
            }

            var csResult = cs.GetClassificationResult();

            List <MainData> finalDataList = new List <MainData>();

            for (int i = 0; i < csResult.GetLength(0); i++)
            {
                aggregatedDataList[(int)csResult[i, 0]].Frequency = csResult[i, 1];

                finalDataList.Add(aggregatedDataList[(int)csResult[i, 0]]);
            }
            return(finalDataList);
        }
Exemple #3
0
        public void GetClassificationResult_5Items3Distinct_InsertOrderDifferent_ExpectedCount()
        {
            string[,] input =
            {
                { "hello", "3"   },
                { "world", "2"   },
                { "hello", "5"   },
                { "how",   "8"   },
                { "hello", "100" }
            };

            long[,] expected = { { 0, 108 }, { 1, 2 }, { 3, 8 } };

            Classifier cs = new Classifier();

            for (int i = input.GetLength(0) - 1; i >= 0; i--)
            {
                cs.Add(i, input[i, 0], Int32.Parse(input[i, 1]));
            }

            long[,] actual = cs.GetClassificationResult();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #4
0
        public void AggregatorClassifier()
        {
            List <MainData> dataList = new List <MainData>();

            using (StreamReader sr = File.OpenText("Copy of DCManualLog.txt"))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] read = line.Split(',');
                    dataList.Add(new MainData()
                    {
                        Time      = DateTime.Parse(read[0]),
                        Process   = read[1],
                        Title     = read[2],
                        Frequency = 1
                    });                     // This can hit OOM if file is HUGE
                }
            }

            Aggregator agg = new Aggregator();

            for (int i = 0; i < dataList.Count; i++)
            {
                agg.Add(dataList[i].Process, dataList[i].Title);
            }

            var aggRes = agg.GetAggregationResult();

            List <MainData> aggregatedDataList = new List <MainData>();

            for (int i = 0; i < aggRes.GetLength(0); i++)
            {
                dataList[aggRes[i, 0]].Frequency = aggRes[i, 1];

                aggregatedDataList.Add(dataList[aggRes[i, 0]]);
            }

            Classifier cs = new Classifier();

            for (int i = 0; i < aggregatedDataList.Count; i++)
            {
                cs.Add(i, aggregatedDataList[i].Process + aggregatedDataList[i].Title, aggregatedDataList[i].Frequency);
            }

            var csResult = cs.GetClassificationResult();

            List <MainData> finalDataList = new List <MainData>();

            for (int i = 0; i < csResult.GetLength(0); i++)
            {
                aggregatedDataList[(int)csResult[i, 0]].Frequency = csResult[i, 1];

                finalDataList.Add(aggregatedDataList[(int)csResult[i, 0]]);
            }

            using (StreamWriter sw = File.AppendText("ClassifiedAnalysis.txt"))
            {
                foreach (var item in finalDataList)
                {
                    sw.WriteLine(string.Format("{0},{1},{2},{3}", item.Time, item.Process, item.Title, item.Frequency));
                }
            }
        }